2013-07-15 244 views
-1

我寫了下面的C++代碼。在clSetKernelArg(kernel, 8, sizeof(cl_mem), (void *) &mob_whdis);,它返回error code -49,我不明白爲什麼。其他一切正常運行。誰能幫我?clSetKernelArg返回錯誤代碼-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 
+0

我冒昧地對您的問題進行了重新說明。我希望沒問題。 :) – weltraumpirat

+0

一開始就是[搞清楚'-49'的實際含義](http://www.google.de/#gs_rn=19&gs_ri=psy-ab&cp=9&gs_id=57&xhr=t&q=opencl+error+codes&es_nrs=真PF = p&sclient = PSY-AB和OQ = OpenCL的+ ER&gs_l =&PBX = 1&BAV = on.2,or.r_qf。&BVM = bv.48705608,d.Yms&FP = 1becc00280c7e15&BIW = 1920&波黑= 1034)。 –

回答

2

錯誤-49是CL_INVALID_ARG_INDEX。你應該檢查你的opencl內核源碼參數。

此外,在您的代碼中,您應該使用程序的OpenCL源代碼clCreateProgramWithSource編譯並鏈接它,然後使用clCreateKernel獲取有效的內核引用。然後你可以正確使用clSetKernelArg

1

只是一個快速反問題:

mob_whdis是是的sizeof(浮動)的裝置緩衝器。這意味着全局內存中有一個浮點值。全球記憶在閱讀和寫作時會受到很大的影響。你可以改爲使用私人常量,如:

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

這使得在私有內存中的所有內核都有一個浮點常量,該內核非常快,比Global快得多。

同樣適用於mob_nofsw和mob_nop。