This article introduces how to use Open Computing Language (OpenCL) to create an image file, and then download the image to an FPGA chip.
- All the operations described in this article must be performed by one account in the same region.
- We strongly recommend that you use an f1 instance 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 OSS buckets. If you want to encrypt the IP address, grant the RAM user to use Key Management Service (KMS). If you want the RAM user to check permissions, authorize the RAM user to view the resources of an account.
Before you begin, complete the following:
- Create an f1 instance and add a security group rule to allow Internet access to SSH Port 22 of the instance.
Note: Only the image we share with you can be used on an f1 instance. For more information, see Create an f1 instance.
- To operate an f1 instance as a RAM user, you must do the following operations:
- Activate OSS and create an OSS bucket to upload your custom bitstream files. The OSS bucket and the f1 instance must be owned by one account and in the same region.
- Log on to the
ECS consoleto obtain the instance ID.
- To encrypt your bitstream, activate Key Management Service (KMS).
To configure the environment of FPGA Server Example, follow these steps.
Run the script to install the basic environment.
To download the OpenCL Example, follow these steps:
Create the /opt/tmp directory, and change the current directory to it.
mkdir -p /opt/tmp
Now, you are at the /opt/tmp directory.
Run the commands one by one to download and decompress the OpenCL Example file.
tar -zxvf exm_opencl_matrix_mult_x64_linux.tgz
The following figure displays the directory after decompression.
Change the current directory to the matrix_mult directory and run the command for compilation.
aoc -v -g --report ./device/matrix_mult.cl
The process of compilation takes several hours. You can open a new console, and run the
topcommand to monitor processes and system resource usage on the instance and view the status of the compilation process.
Run the commands to initialize the faascmd.
# If needed, add the environment variable and grant the permission to run the commands
chmod +x /opt/dcp1_0/script/faascmd
# Replace hereIsMySecretId with your AccessKey ID. Replace hereIsMySecretKey with your AccessKey Secret
faascmd config --id=hereIsMySecretId --key=hereIsMySecretKey
# Replace hereIsMyBucket with the bucket name of your OSS in the Region China East 1.
faascmd auth --bucket=hereIsMyBucket
Change the current directory to the matrix_mult/output_files directory, and upload the configuration file.
cd matrix_mult/output_files # Now you are accessing /opt/tmp/matrix_mult/matrix_mult/output_files
faascmd upload_object --object=afu_fit.gbs --file=afu_fit.gbs
Use gbs to create an FPGA image.
# Replace hereIsFPGAImageName with your image name. Replace hereIsFPGAImageTag with the tag of your image.
faascmd create_image --object=afu_fit.gbs --fpgatype=intel --name=hereIsFPGAImageName --tags=hereIsFPGAImageTag --encrypted=false --shell=V0.11
faascmd list_imagescommand to check whether the image is created.
In the returned result, if
"State":"success"is displayed, it means the image is created. Record the FpgaImageUUID.
To download the image to your f1 instance, follow these steps:
Run the command to obtain FPGA ID.
# Replace hereIsYourInstanceId with your f1 instance ID.
faascmd list_instances --instanceId=hereIsYourInstanceId
Record FpgaUUID in the returned result.
Run the command to download the image to your f1 instance.
# Replace hereIsYourInstanceID with your f1 instance ID. Replace hereIsFpgaUUID with your FpgaUUID. Replace hereIsImageUUID with your FpgaImageUUID.
faascmd download_image --instanceId=hereIsYourInstanceID --fpgauuid=hereIsFpgaUUID --fpgatype=intel --imageuuid=hereIsImageUUID --imagetype=afu --shell=V0.11
Run the command to check whether the image is downloaded.
# Replace hereIsYourInstanceID with your f1 instance ID. Replace hereIsFpgaUUID with your FpgaUUID.
faascmd fpga_status --fpgauuid=hereIsFpgaUUID --instanceId=hereIsYourInstanceID
"TaskStatus": "operating"exists in the returned result, it means the image is downloaded.
To download the FPGA image to an FPGA chip, follow these steps:
Open the console in Step 1. If it is closed, repeat Step 1.
Run the following command to configure the runtime environment for OpenCL.
Run the command to go back to the parent directory.
cd ../.. # Now, you are at the /opt/tmp/matrix_mult directory
Run the command to compile.
# Output the environment configuration
cp matrix_mult.aocx ./bin/matrix_mult.aocx
If the following result is returned, it means the configuration is successful. Note that the last line must be
[root@iZbpXXXXXZ bin]# ./host matrix_mult.aocx
A: 2048 x 1024
B: 1024 x 1024
C: 2048 x 1024
Platform: Intel(R) FPGA SDK for OpenCL(TM)
Using 1 device(s)
skx_fpga_dcp_ddr : SKX DCP FPGA OpenCL BSP (acl0)
Using AOCX: matrix_mult.aocx
Generating input matrices
Launching for device 0 (global size: 1024, 2048)
Time: 40.415 ms
Kernel time (device 0): 40.355 ms
Throughput: 106.27 GFLOPS
Computing reference output