使用GPU时,OpenCL程序会冻结

时间:2015-04-16 23:13:06

标签: c++ opencl gpu

我的程序无法使用CPU和GPU:

ret = clGetDeviceIDs(platform_id, CL_DEVICE_TYPE_CPU, 1, &device_id, &ret_num_devices);
ret = clGetDeviceIDs(platform_id, CL_DEVICE_TYPE_GPU, 1, &device_id, &ret_num_devices);

使用CPU时,我收到此消息:

  

在0x000007FEE30E8F90(amdocl64.dll)中的第一次机会异常   Project2.exe:0xC0000005:访问冲突读取位置   0xFFFFFFFFFFFFFFFF。如果有这个例外的处理程序,那么   程序可以安全地继续。

执行此命令时出现问题:

ret = clEnqueueReadBuffer(command_queue, Cmobj, CL_TRUE, 0,
K*L*sizeof(float), C, 0, NULL, NULL);

执行此命令时使用GPU程序冻结:

ret = clBuildProgram(program, 1, &device_id, NULL, NULL, NULL);

内存有问题吗?或者是其他东西? 我使用Visual Studio 2012,AMD Radeon HD 6470M,AMD APP SDK 2.9-1

1 个答案:

答案 0 :(得分:1)

您是如何初始化device_idret_num_devices的?

通常,您需要调用clGetDeviceIDs两次:首先获取可用设备的数量,然后为设备ID分配内存,然后再次调用以填充该内存,如下所示:

cl_uint       numDevices = 0;
cl_device_id  *devices;
status = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 0, NULL, &numDevices);    
if (numDevices > 0)
{
    devices = (cl_device_id*)malloc(numDevices * sizeof(cl_device_id));
    status = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, numDevices, devices, NULL);
}
else
{
  // error: no device available: exit or fall back to CPU ...      
}

// use any of the devices[0 .. numDevices-1]
// after compiling/loading the kernel, you can free(devices)

APP SDK附带的一些示例也显示了这种模式,例如samples / opencl / cl / app / HelloWorld / HelloWorld.cpp。也许您只是使用其中一个示例并根据您的需求进行调整?

相关问题