Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCL error executing on Xilinx FPGA

I am trying to use SDAccel to build an OpenCL application; then to run it on an PCIe FPGA-based card (alpha data).

I have tried to use the examples given but no success so far. Also there was no similar thread (and no respond to my queries) in any Xilinx forum.

So I have decided to create a small OpenCL application to test exhaustively.

Here is the source code:

#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <unistd.h>
#include <assert.h>
#include <stdbool.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <CL/opencl.h>

int main(int argc, char** argv)
{
   int err;      // error code returned from api calls
   uint i = 0;
   uint j = 0;

   char *info;
   size_t infoSize;
   cl_uint num_platforms;
   cl_platform_id *platform_id_array;

   const char* platfAttrNames[5] = {"Name","Vendor","Version","Profile","Extensions"};
   const cl_platform_info platfAttrTypes[5] = {CL_PLATFORM_NAME, 
                                               CL_PLATFORM_VENDOR,
                                               CL_PLATFORM_VERSION, 
                                               CL_PLATFORM_PROFILE, 
                                           CL_PLATFORM_EXTENSIONS};
   const uint platfAttrCount = sizeof(platfAttrNames)/sizeof(char*);

   // Get total number of platforms
   // First arg must be 0. Otherwise compilation error
   err = clGetPlatformIDs(0, NULL, &num_platforms); 
   printf("Number of available platforms = %d\n", num_platforms);

   // Get ID of each platform
   platform_id_array = (cl_platform_id *) malloc(sizeof(cl_platform_id) * num_platforms);
   err = clGetPlatformIDs(num_platforms, platform_id_array, NULL);
   if (err != CL_SUCCESS) {
     printf("Error: clGetPlatformIDs failed!\n"); 
     return EXIT_FAILURE;
   }

   // Get characteristics for each platform
   for (i = 0; i < num_platforms; i++) 
   {
     printf("n %d. Platform \n", i+1);

     for(j = 0; j < platfAttrCount; j++) {
      // Get platform attribute value size
      err = clGetPlatformInfo(platform_id_array[i], platfAttrTypes[j], 0, NULL, &infoSize);
      info = (char*) malloc(sizeof(char) * infoSize);

      // Get platform attribute value
      err = clGetPlatformInfo(platform_id_array[i], platfAttrTypes[j], infoSize, info, NULL);
      if (err != CL_SUCCESS) {
        printf("Error: clGetPlatformInfo - %s failed!\n", platfAttrNames[j]); 
        return EXIT_FAILURE;
       }
       printf("%s = %s\n", platfAttrNames[j], info); free(info);
     }
   }

   // Get total number of devices
   // Work with the first platform (the only one available)
   cl_uint num_devices;
   err = clGetDeviceIDs(platform_id_array[0], CL_DEVICE_TYPE_ALL, 0, NULL, &num_devices);
   if (err != CL_SUCCESS) {
     printf("Error: clGetDeviceIDs couldn't find any devices!\n"); 
   }
   printf("Number of available devices of platform[0] = %d\n", num_devices);
 free(platform_id_array);
 return 0;
}

I use a tcl script to compile and build this. The output is:

Number of available platforms = 1
n 1. Platform 
Name = Xilinx
Vendor = Xilinx
Version = OpenCL 1.0 
Profile = EMBEDDED_PROFILE
Extensions = cl_khr_icd
Error: clGetDeviceIDs couldn't find any devices!
Number of available devices of platform[0] = 0
Segmentation fault (core dumped)

The problem is that:

  • (1) clGetDeviceIDs returns CL_DEVICE_NOT_FOUND,
  • (2) there is always segmentation fault on every run, and
  • (3) running on emulation environments (cpu and hw), none of the problems above appears.

Finally, I think the drivers are correctly installed. If I run:

lspci -v 

The relevant part of the output is:

01:00.0 Memory controller: Xilinx Corporation Device 7038
Subsystem: Xilinx Corporation Device 0010
Flags: bus master, fast devsel, latency 0, IRQ 129
Memory at df000000 (32-bit, non-prefetchable) [size=4M]
Memory at df400000 (32-bit, non-prefetchable) [size=1M]
Capabilities: <access denied>
Kernel driver in use: xdma
Kernel modules: xdma

Still I am not able to get it working on the FPGA.

Do you have any suggestion that could help me?

like image 737
L30nardo SV. Avatar asked May 27 '26 10:05

L30nardo SV.


2 Answers

Which OS do you use? Xilinx supports RedHat and CentOS, so check that!

I also had this problem with the segmentation fault! Maybe you have to update the bitstream for the board for the first time using a JTAG cable. Once you have that the board will be ready for use with SDAccel. Look in the SDAccel tutorial: it has an appendix that describes the steps to get the boards updated. Also avoid using the precompiled example! Try to compile the other examples provided by Xilinx!

like image 64
Dennis Avatar answered Jun 03 '26 15:06

Dennis


There is a system level command which provided by xilinx can give you an overall system information. Check out "sudo sdxsyschk". And fix any Errors displayed.

In general, run something like "hello world" to make sure driver/DSA are installed correctly. Then hard reboot the machine.

Try it again. it should work now.

like image 37
xiaoyong Avatar answered Jun 03 '26 15:06

xiaoyong



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!