OpenCL 程序在使用 GPU 时冻结

OpenCL program freezes when using GPU

本文关键字:GPU 冻结 程序 OpenCL      更新时间:2023-10-16

我的程序在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) 的首次机会异常 项目2.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

你是如何初始化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例如。也许您只是使用其中一个示例并根据您的需求进行调整?