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?