clCreateProgramWithSource error

Hello,

I’m getting “Access violation reading location 0x4c432f2f” when trying to create a program from source. My code looks like this:

char * source = "__kernel void VectorAdd(__global const float* a, __global const float* b, \

__global float* c, int iNumElements)\

{\

   some CL code here\

}";

szKernelLength = strlen(source); //szKernelLength is of size_t type

cpProgram = clCreateProgramWithSource(cxGPUContext, 1, (const char **)source, &szKernelLength, &ciErr1);

I have no idea, whats wrong. I’ve also copy-pasted two support functions (shrFindFilePath and oclLoadProgSource) from SDK source files to do the job, but the result was the same…

Any help would be greatly appreciated

In the last statement, instead of

(char**)source

you need

(char**)&source

Thank You! This just saved my day…

I got another problem, this time with clBuildProgram… it returns “1”, which does not correspond to any return value mentioned in the specs. Code here:

[url=“http://pastebin.com/f563a6893”]http://pastebin.com/f563a6893[/url]
(I coulnt make it show the code, each time I was redirected to the main page, so pastebin…)

I tried to query the context, source code and the number of devices of the program using clGetProgramInfo, acquired values matched, so I guss that program created with clCreateProgramWithSource is OK. But when I tried to query binary size, I got zero, so the build was unsuccessful. Any ideas? And is there any way to see compile output? Thanks in advance…

See this. Then, use clGetProgramBuildInfo() to lookup syntax errors in your OpenCL code.

Just add this after the clBuildProgram to catch syntax problem

if (ciErr1 != CL_SUCCESS)

{

		size_t ret_val_size;

		char *build_log = NULL;

		clGetProgramBuildInfo(cpProgram, cdDevices, CL_PROGRAM_BUILD_LOG, 0, NULL, &ret_val_size);

		build_log = (char *) calloc(ret_val_size + 1, sizeof(char));

		clGetProgramBuildInfo(cpProgram, cdDevicesInfo, CL_PROGRAM_BUILD_LOG, ret_val_size, build_log, NULL);

		build_log[ret_val_size] = '

if (ciErr1 != CL_SUCCESS)

{

	size_t ret_val_size;

	char *build_log = NULL;

	clGetProgramBuildInfo(cpProgram, cdDevices, CL_PROGRAM_BUILD_LOG, 0, NULL, &ret_val_size);

	build_log = (char *) calloc(ret_val_size + 1, sizeof(char));

	clGetProgramBuildInfo(cpProgram, cdDevicesInfo, CL_PROGRAM_BUILD_LOG, ret_val_size, build_log, NULL);

	build_log[ret_val_size] = '\0';

	printf("%s", build_log);

	free(build_log);

}

';

		printf("%s", build_log);

		free(build_log);

}