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.
- Log on to the ECS console to obtain the instance ID.
- 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.
- To encrypt your bitstream, activate Key Management Service (KMS).
- To operate an f1 instance as a RAM user, you must do the following operations:
To configure the environment of FPGA Server Example, follow these steps.
Step 1. Connect to your f1 instance
Step 2. Install the basic environment
Run the following script to install the base environment.
Step 3. Download the OpenCL Example
Follow these steps to download the official opencl example.
- Create the /opt/tmp directory, and change the current directory to it.
mkdir -p /opt/tmp cd /opt/tmpNow, you are at the /opt/tmp directory.
- Run the commands one by one to download and decompress the OpenCL Example file.
wget https://www.altera.com/content/dam/altera-www/global/en_US/others/support/examples/download/exm_opencl_matrix_mult_x64_linux.tgz tar -zxvf exm_opencl_matrix_mult_x64_linux.tgzThe following figure displays the directory after decompression.
- Change the current directory to the matrix_mult directory and run the command for compilation.
cd matrix_mult 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.
Step 4. Upload the configuration file to the OSS bucket
Follow these steps to upload the configuration file.
- Run the commands to initialize the faascmd.
# If needed, add the environment variable and grant the permission to run the commands export PATH=$PATH:/opt/dcp1_1/script/ chmod +x /opt/dcp1_1/script/faascmd # Replace hereIsYourSecretId with your AccessKey ID. Replace hereIsYourSecretKey with your AccessKey Secret faascmd config --id=hereIsYourSecretId --key=hereIsYourSecretKey # Replace hereIsYourBucket with the bucket name of your OSS in the Region China East 1. faascmd auth --bucket=hereIsYourBucket
- 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 hereIsYourImageName with your image name. Replace hereIsYourImageTag with your image tag. faascmd create_image --object=dma_afu.gbs --fpgatype=intel --name=hereIsYourImageName --tags=hereIsYourImageTag --encrypted=false --shell=V1.1
- Run the
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.
Step 5. Download the image to your f1 instance
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=hereIsYourInstanceIdReturned results sample: 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 FPGA UUID. Replace hereIsImageUUID with your image UUID. 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 FPGA UUID. faascmd fpga_status --fpgauuid=hereIsFpgaUUID --instanceId=hereIsYourInstanceIDIf "TaskStatus": "operating" exists in the returned result, it means the image is downloaded.
Step 6. Download the FPGA image to an FPGA chip
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.
make # Output the environment configuration export CL_CONTEXT_COMPILER_MODE_ALTERA=3 cp matrix_mult.aocx ./bin/matrix_mult.aocx cd bin host 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 Matrix sizes: A: 2048 x 1024 B: 1024 x 1024 C: 2048 x 1024 Initializing OpenCL 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 Verifying Verification: PASS