-1

我编写了以下 C++ 代码。在clSetKernelArg( kernel, 8, sizeof( cl_mem ), (void *) &mob_whdis );,它返回error code -49,我不明白为什么。其他一切正常运行。谁能帮我?

cl_mem mob_X = NULL;
cl_mem mob_Y = NULL;
cl_mem mob_Z = NULL;
cl_mem mob_WAT = NULL;
cl_mem mob_POL = NULL;
cl_mem mob_FSW = NULL;
cl_mem mob_nop = NULL;
cl_mem mob_nofsw = NULL;
cl_mem mob_whdis = NULL;
cl_mem mob_watwp = NULL;
cl_mem mob_watp = NULL;
cl_mem mob_distp = NULL;
cl_mem mob_watww = NULL;
cl_mem mob_watw = NULL;
cl_mem mob_distw = NULL;
cl_program program = NULL;
cl_kernel kernel = NULL;
cl_uint ret_num_devices;
cl_uint ret_num_platforms;
cl_int err;
float whdis=3.5;
mob_X = clCreateBuffer( context, CL_MEM_READ_WRITE, na * sizeof(float), NULL, &err );
mob_Y = clCreateBuffer( context, CL_MEM_READ_WRITE, na * sizeof(float), NULL, &err );
mob_Z = clCreateBuffer( context, CL_MEM_READ_WRITE, na * sizeof(float), NULL, &err );
mob_WAT = clCreateBuffer( context, CL_MEM_READ_WRITE, now * sizeof(int), NULL, &err );
mob_POL = clCreateBuffer( context, CL_MEM_READ_WRITE, nop * sizeof(int), NULL, &err );
mob_FSW = clCreateBuffer( context, CL_MEM_READ_WRITE, now * sizeof(int), NULL, &err );
mob_nop = clCreateBuffer( context, CL_MEM_READ_WRITE, sizeof(int), NULL, &err );
mob_nofsw = clCreateBuffer( context, CL_MEM_READ_WRITE, sizeof(int), NULL, &err );
mob_whdis =  clCreateBuffer( context, CL_MEM_READ_WRITE, sizeof(float), NULL, &err );
mob_watwp = clCreateBuffer( context, CL_MEM_READ_WRITE, sizeof(int) * now * 40, NULL, &err );
mob_watp = clCreateBuffer( context, CL_MEM_READ_WRITE, sizeof(int) * now * 40, NULL, &err );
mob_distp = clCreateBuffer( context, CL_MEM_READ_WRITE, sizeof(float) * now * 40, NULL, &err );
mob_watww = clCreateBuffer( context, CL_MEM_READ_WRITE, sizeof(int) * now * 40, NULL, &err );
mob_watw = clCreateBuffer( context, CL_MEM_READ_WRITE, sizeof(int) * now * 40, NULL, &err );
mob_distw = clCreateBuffer( context, CL_MEM_READ_WRITE, sizeof(float) * now * 40, NULL, &err );
err = clEnqueueWriteBuffer( command_queue, mob_X, CL_TRUE, 0, na * sizeof(float), X, 0, NULL, NULL );
err = clEnqueueWriteBuffer( command_queue, mob_Y, CL_TRUE, 0, na * sizeof(float), Y, 0, NULL, NULL );
err = clEnqueueWriteBuffer( command_queue, mob_Z, CL_TRUE, 0, na * sizeof(float), Z, 0, NULL, NULL );
err = clEnqueueWriteBuffer( command_queue, mob_WAT, CL_TRUE, 0, now * sizeof(int), wat, 0, NULL, NULL );
err = clEnqueueWriteBuffer( command_queue, mob_POL, CL_TRUE, 0, nop * sizeof(int), pol, 0, NULL, NULL );
err = clEnqueueWriteBuffer( command_queue, mob_FSW, CL_TRUE, 0, now * sizeof(int), fsw, 0, NULL, NULL );
err = clEnqueueWriteBuffer( command_queue, mob_nop, CL_TRUE, 0, sizeof(int), &nop, 0, NULL, NULL );
err = clEnqueueWriteBuffer( command_queue, mob_nofsw, CL_TRUE, 0, sizeof(int), &nofsw, 0, NULL, NULL );
err = clEnqueueWriteBuffer( command_queue, mob_whdis, CL_TRUE, 0, sizeof(float), &whdis, 0, NULL, NULL );
err_check( err, "clSetKernelArg" );
err = clSetKernelArg( kernel, 0, sizeof( cl_mem ), (void *) &mob_X );
err = clSetKernelArg( kernel, 1, sizeof( cl_mem ), (void *) &mob_Y );
err = clSetKernelArg( kernel, 2, sizeof( cl_mem ), (void *) &mob_Z );
err = clSetKernelArg( kernel, 3, sizeof( cl_mem ), (void *) &mob_WAT );
err = clSetKernelArg( kernel, 4, sizeof( cl_mem ), (void *) &mob_POL );
err = clSetKernelArg( kernel, 5, sizeof( cl_mem ), (void *) &mob_FSW );
err = clSetKernelArg( kernel, 6, sizeof( cl_mem ), (void *) &mob_nop );
err = clSetKernelArg( kernel, 7, sizeof( cl_mem ), (void *) &mob_nofsw );
err = clSetKernelArg( kernel, 8, sizeof( cl_mem ), (void *) &mob_whdis );

    // Step 11: Execute OpenCL kernel in data parallel
size_t worksize[] = { now, 1, 1 };
clEnqueueNDRangeKernel( command_queue, kernel, 1, NULL, worksize, 0, 0, 0, 0 );
err_check( err, "clEnqueueNDRangeKernel" );
// Step 12: Read (Transfer result) from the memory buffer
4

2 回答 2

2

错误 -49 是CL_INVALID_ARG_INDEX. 您应该检查您的 opencl 内核源参数。

此外,在您的代码中,您应该clCreateProgramWithSource使用程序的 OpenCL 源代码clBuildProgram来编译和链接它,然后使用它clCreateKernel来获取有效的内核引用。然后就可以clSetKernelArg正常使用了。

于 2013-07-15T10:37:07.683 回答
1

只是一个快速的反问:

mob_whdis 是一个 sizeof(float) 的设备缓冲区。这意味着全局内存中有一个浮点值。全局内存在读写时对性能有很大影响。您可以改为使用私有 const,例如:

浮动 mob_whdis = 0.0f; ... SetKernalArg(kernel, 8, sizeof(float), &mob_whdis);

这会在私有内存中的所有内核中放置一个浮点常量,这非常快,比全局快得多。

mob_nofsw 和 mob_nop 也是如此。

于 2013-07-20T19:51:08.767 回答