【发布时间】:2016-08-28 01:04:58
【问题描述】:
我正在尝试使用 SDAccel 构建 OpenCL 应用程序;然后在基于 PCIe FPGA 的卡上运行它(alpha 数据)。
我尝试使用给出的示例,但到目前为止没有成功。在任何 Xilinx 论坛中也没有类似的帖子(也没有回复我的问题)。
所以我决定创建一个小型 OpenCL 应用程序来进行详尽的测试。
这里是源代码:
#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;
}
我使用 tcl 脚本来编译和构建它。输出是:
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)
问题是:
- (1) clGetDeviceIDs 返回 CL_DEVICE_NOT_FOUND,
- (2) 每次运行总是存在分段错误,并且
- (3) 在仿真环境(cpu 和硬件)上运行,没有 出现上述问题。
最后,我认为驱动程序已正确安装。如果我跑:
lspci -v
输出的相关部分是:
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
我仍然无法让它在 FPGA 上运行。
你有什么建议可以帮助我吗?
【问题讨论】:
标签: segmentation-fault opencl fpga xilinx