This topic describes how to use Register Transfer Level (RTL) Compiler on an f1 instance.

Prerequisites

Before you perform the operations, make sure that the following requirements are met:
  • An Alibaba Cloud account is created. To create an Alibaba Cloud account, go to the Alibaba Cloud official website.
  • An f1 instance is created and can access the Internet.
    Note Only FaaS F1 basic images from Alibaba Cloud Marketplace can be used in f1 instances. For more information, see Create an f1 instance.
  • The rule for allowing traffic on SSH port 22 is configured for the security groups where the f1 instance resides.
  • The ID of the f1 instance is obtained from the Instances page in the ECS console.
  • An OSS bucket for FaaS is created.

    The OSS bucket and the f1 instance must be in the same account and the same region. For more information, see Create buckets.

  • To encrypt files, activate Key Management Service (KMS) first.

    For more information, see Activate Key Management Service (KMS).

  • You must complete the following operations before you can manage FPGA-based instance as a RAM user:
    • Create a RAM user and grant permissions to the RAM user. For more information, see Create a RAM user and Grant permissions to a RAM user.

      The permissions you must grant to the RAM users include AliyunECSReadOnlyAccess, AliyunOSSFullAccess, and AliyunRAMFullAccess.

    • Click here to grant permissions to FaaS.
    • Obtain the AccessKey ID and AccessKey secret of the RAM user.

Background information

Before you perform the operations, take note of the following items:
  • All operations described in this topic must be performed by a single account within the same region.
  • We strongly recommend that you manage FaaS instances as a RAM user. To avoid unwanted operations, you must authorize the RAM user to perform required actions only. You must create a role for the RAM user and grant temporary permissions to the role to access the specified OSS bucket. Then, you can download the original DCP project from the OSS bucket and manage the FPGA image. If you want to encrypt the IP address, you must authorize the RAM user to use Key Management Service (KMS). If you want the RAM user to check permissions of Alibaba Cloud accounts, you must authorize the RAM user to view the resources of Alibaba Cloud accounts.

Procedure

  1. Connect to an f1 instance.
  2. Run the following command to configure the basic environment:
    source /opt/dcp1_1/script/f1_env_set.sh
  3. Run the following commands in sequence to compile the project:
    cd /opt/dcp1_1/hw/samples/dma_afu
    afu_synth_setup --source hw/rtl/filelist.txt build_synth
    cd build_synth/
    run.sh
    Note The compilation process may take some time.
  4. Create an image.
    1. Run the following commands in sequence to configure the PATH environment variable and grant execute permissions to the faascmd file:
      export PATH=$PATH:/opt/dcp1_1/script/
      chmod +x /opt/dcp1_1/script/faascmd
    2. Run the following commands in sequence to initialize the faascmd configuration:
      # Replace hereIsYourSecretId with your AccessKey ID. Replace hereIsYourSecretKey with your AccessKey secret.
      faascmd config --id=hereIsYourSecretId --key=hereIsYourSecretKey
      # Replace hereIsYourBucket with the OSS bucket name in the China (Hangzhou) region.
      faascmd auth --bucket=hereIsYourBucket
    3. Run the following command in the /opt/dcp1_1/hw/samples/dma_afu directory to upload the GBS file:
      faascmd upload_object --object=dma_afu.gbs --file=dma_afu.gbs
    4. Run the following command to create an image:
      # Replace hereIsYourImageName with your image name.
      faascmd create_image --object=dma_afu.gbs --fpgatype=intel --name=hereIsYourImageName --tags=hereIsYourImageTag --encrypted=false --shell=V1.1
  5. Download the image.
    1. Run the following command to check whether the image is created:
      faascmd list_images
      If "State":"success" is displayed in the command output, the image is created. Record the value of FpgaImageUUID in the command output for later use.download_image
    2. Run the following command to obtain the FPGA ID:
      # Replace hereIsYourInstanceId with the ID of your f1 instance.
      faascmd list_instances --instanceId=hereIsYourInstanceId
      The following figure shows the command output. Record the value of FpgaUUID.get_fpga-id
    3. Run the following command to download the FPGA image to the f1 instance:
      # Replace hereIsYourInstanceID with the instance ID that you recorded. Replace hereIsFpgaUUID with the value of FpgaUUID that you recorded. Replace hereIsImageUUID with the value of FpgaImageUUID that you recorded.
      faascmd download_image --instanceId=hereIsYourInstanceID --fpgauuid=hereIsFpgaUUID --fpgatype=intel --imageuuid=hereIsImageUUID --imagetype=afu --shell=V1.1
    4. Run the following command to check whether the image is downloaded:
      # Replace hereIsYourInstanceID with the instance ID that you recorded. Replace hereIsFpgaUUID with the value of FpgaUUID that you recorded.
      faascmd fpga_status --instanceId=hereIsYourInstanceID --fpgauuid=hereIsFpgaUUID
      If "TaskStatus":"operating" is displayed in the command output, and the value of FpgaImageUUID is the same as that of FpgaImageUUID, the image is downloaded.download_success
  6. Optional:Run the following command to enable HugePages if HugePages is disabled:
    sudo bash -c "echo 20 > /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages"
  7. Run the following commands in sequence to perform a test:
    cd /opt/dcp1_1/hw/samples/dma_afu/sw
    make
    sudo LD_LIBRARY_PATH=/opt/dcp1_1/hw/samples/dma_afu/sw:$LD_LIBRARY_PATH ./fpga_dma_test 0
    If the following command output is displayed, the test is completed.test_complete