我正在尝试使用 clCreateImage 创建一个 cl_mem,但程序不断崩溃。我尽可能地关注我的书,但到目前为止,这是一条相当坎坷的道路。
#include "stdafx.h"
#include <iostream>
#include <CL\cl.h>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
cl_int status;
cl_platform_id platform;
status = clGetPlatformIDs(1, &platform, NULL);
cl_device_id device;
clGetDeviceIDs(platform, CL_DEVICE_TYPE_ALL, 1, &device, NULL);
cl_context_properties props[3] = { CL_CONTEXT_PLATFORM, (cl_context_properties) (platform), 0 };
cl_context context = clCreateContext(props, 1, &device, NULL, NULL, &status);
cl_image_desc desc;
desc.image_type = CL_MEM_OBJECT_IMAGE2D;
desc.image_width = 100;
desc.image_height = 100;
desc.image_depth = 0;
desc.image_array_size = 0;
desc.image_row_pitch = 0;
desc.image_slice_pitch = 0;
desc.num_mip_levels = 0;
desc.num_samples = 0;
desc.buffer = NULL;
cl_image_format format;
format.image_channel_order = CL_R;
format.image_channel_data_type = CL_FLOAT;
// crashes on the next line with -- Unhandled exception at 0x72BCC9F1 in Convolution.exe: 0xC0000005: Access violation executing location 0x00000000.
cl_mem d_inputImage = clCreateImage(context, CL_MEM_READ_ONLY, &format, &desc, NULL, &status);
// never gets here
cout << "--->"; int exit; cin >> exit;
return 0;
}