runtime error

Hi, i am trying to “unwrapp” this Hello world C++ code http://developer.amd.com/gpu/ATIStreamS … penCL.aspx to C. But during executing clEnqueueNDRangeKernel program drops with this msg:

Unhandled exception at 0x006adeea in LUA.exe: 0xC0000005: Access violation writing location 0x00b495fc.

here is my program code:


int main (int argc, char *argv[])
{

...
char outH[200]; 
cl_mem out = clCreateBuffer(context, CL_MEM_WRITE_ONLY | CL_MEM_USE_HOST_PTR, 200, outH, &err);

	const char * ker = "#pragma OPENCL EXTENSION cl_khr_byte_addressable_store : enable 
" \
					   "__constant char hw[] = \"Hello world!\
\";						
" \
					   "__kernel void hello(__global char * out)                        
" \
					   "{                                                               
" \
					   "    size_t tid = get_local_id(0);                              
" \
					   "    out[0] = hw[0];                                         
" \
					   "}";
	cl_program prog = clCreateProgramWithSource(context, 1,(const char **) &ker, NULL, &err);
	err = clBuildProgram(prog, num_devices, devices, NULL, NULL, NULL);

	cl_kernel krnl = clCreateKernel(prog, "hello", &err);
	err = clSetKernelArg(krnl, 0, sizeof(out), out);  
	cl_command_queue queue = clCreateCommandQueue(context, devices[0], 0, &err);
	size_t global_size[] = {13, 0, 0};
	size_t local_size[] = {1, 0, 0};

	err = clEnqueueNDRangeKernel(queue,
								 krnl,
								 1,
								 NULL,
								 global_size,
								 local_size, 0, NULL, NULL
								 );
...

C++ code from amd.com runs smoothly.
Can anybody help ?

The code is not checking whether any of the functions is returning an error. That is the first thing that you should look at.

that’s the first thing that I check in debug mode…every previous function returns CL_SUCCESS…

Did you check the compilation status of the program after calling clBuildProgram()?

Anyway, I think I found the problem:

err = clSetKernelArg(krnl, 0, sizeof(out), out);

…should be instead:

err = clSetKernelArg(krnl, 0, sizeof(out), &out);

thanks!