我正在基于Eclipse CDT(Mars)和intel_sdk_for_opencl_setup_6.1.0.1600在Windows 10上开发OpenCL应用程序。我的电脑设备如下:
操作系统:Windows 10专业版 CPU:I7-5500U 驱动:win64_15407.4279.exe
问题:尽管代码是在Eclipse CDT中成功构建的,但它在Eclipse CDT中作为 - >本地C / C ++应用程序运行时崩溃并挂起。事实上,它可以在同一个IDE和操作系统中成功构建和运行,方法是替换文件OpenCL.lib(它来自intel OpenCL SDK并位于C:\ Program Files(x86)\ Intel \ OpenCL SDK \ 6.1 \ lib \ x64 \ OpenCL.lib)与AMD OpenCL SDK(*** \ AMD APP \ lib \ x64 \ OpenCL.lib)对应。
除了用(*** \ AMD APP \ lib \ x64 \ OpenCL.lib)替换文件(C:\ Program Files(x86)\ Intel \ OpenCL SDK \ 6.1 \ lib \ x64 \ OpenCL.lib)之外,如何使用本机intel_sdk_for_opencl_setup_6.1.0.1600和Eclipse CDT成功运行代码?
#include <stdio.h>
#include <stdlib.h>
#include<CL/cl.h>
int main(int argc, char *argv[]) {
cl_uint err;
cl_uint num_platform;
cl_platform_id *platform;
err = clGetPlatformIDs(0, NULL, &num_platform);
if (CL_SUCCESS == err)
printf("Number of Detected OpenCL platforms: %d\n\n", num_platform);
else
printf("Error calling clGetPlatformIDs. Error code: %d \n", err);
platform = (cl_platform_id *) malloc(sizeof(cl_platform_id) * num_platform);
err = clGetPlatformIDs(num_platform, platform, NULL);
size_t size;
for (cl_uint i = 0; i < num_platform; i++) {
err = clGetPlatformInfo(platform[i], CL_PLATFORM_NAME, 0, NULL, &size);
char *PName = (char *) malloc(size);
err = clGetPlatformInfo(platform[i], CL_PLATFORM_NAME, size, PName,NULL);
printf("PName:%s\n", PName);
err = clGetPlatformInfo(platform[i], CL_PLATFORM_VENDOR, 0, NULL,&size);
char *PVendor = (char *) malloc(size);
err = clGetPlatformInfo(platform[i], CL_PLATFORM_VENDOR, size, PVendor,NULL);
printf("PVendor:%s\n", PVendor);
err = clGetPlatformInfo(platform[i], CL_PLATFORM_VERSION, 0, NULL,&size);
char *PVersion = (char *) malloc(size);
err = clGetPlatformInfo(platform[i], CL_PLATFORM_VERSION, size,PVersion, NULL);
printf("PVersion:%s\n", PVersion);
printf("i=%d err=%d\n\n", i, err);
}
return 0;
}
答案 0 :(得分:0)
它在哪里崩溃?在其中一个OpenCL电话?我出于各种原因(包括OpenCL.dll的糟糕供应商分发)在clGetPlatformID中看到了崩溃。在Windows上,OpenCL.lib只是OpenCL.dll的静态包装器,两者通常与Khronos分发的OpenCL ICD相同(可安装的客户端驱动程序,它是安装任何供应商驱动程序的蹦床)。但是,一些供应商会更改它们(例如,要进行NVIDIA Nsight跟踪,您需要NVIDIA的版本)。因此,虽然我无法解释为什么一个人为你而崩溃,但我可以自信地说你可以将崩溃的一个换成一个非崩溃的一个并且没问题。