简体   繁体   English

使用GPU时OpenCL程序冻结

[英]OpenCL program freezes when using GPU

My program doesn't work both using CPU and 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);

When using CPU I receive this message: 使用CPU时,我收到以下消息:

First-chance exception at 0x000007FEE30E8F90 (amdocl64.dll) in Project2.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF. Project2.exe中0x000007FEE30E8F90(amdocl64.dll)的第一次机会异常:0xC0000005:访问冲突读取位置0xFFFFFFFFFFFFFFFF。 If there is a handler for this exception, the program may be safely continued. 如果有用于此异常的处理程序,则可以安全地继续执行该程序。

The problem appears while executing this command: 执行此命令时出现问题:

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

When using GPU program freezes when executing this command: 当使用GPU程序执行以下命令时冻结:

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

Is there problem with memory? 内存有问题吗? Or something else? 或者是其他东西? I use Visual Studio 2012, AMD Radeon HD 6470M, AMD APP SDK 2.9-1 我使用Visual Studio 2012,AMD Radeon HD 6470M,AMD APP SDK 2.9-1

How did you initialize device_id and ret_num_devices ? 您如何初始化device_idret_num_devices

Normally, you need to call clGetDeviceIDs twice: first get the number of available devices, then allocate memory for the device IDs, then call it again to fill that memory, like this: 通常,您需要调用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)

Some of the examples that come with the APP SDK also show this pattern, samples/opencl/cl/app/HelloWorld/HelloWorld.cpp for example. APP SDK随附的一些示例也显示了这种模式,例如samples / opencl / cl / app / HelloWorld / HelloWorld.cpp。 Maybe you just use one of the examples and adapt it to your needs? 也许您只是使用其中一个示例并使其适应您的需求?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM