[QUOTE=mjgcl1;30041]Hi all,
I have the following kernel in a file called “addone.cl” and the following kernel text inside:
#PRAGMA OPENCL EXTENSION cl_khr_fp64 : enable
"__kernel void addone(__global cl_double *dataBuffer,
"
"__global cl_double *resultBuffer){
"
"cl_int id=get_global_id(0);
"
"resultBuffer[id] = dataBuffer[id] + 1.0;}
"
When I try to build a program with the NVIDIA OpenCL, I’m getting a -33 error. The Intel OpenCL builds the kernel but returns and error -46 which appears to mean it cannot find a kernel
with the stated name “addone”. I’ve formatted the kernel in this way following a similar problem reported on Stackoverflow.
I’m using Windows 7 64-bit and Notepad++ editor to write addone.cl and save it as plain ANSI encoded text.
Should I use a different editor or format encoding?
I would appreciate any advice. Many thanks![/QUOTE]
Try this:
Write the kernel in that file, as if it was normal code. Just the function. Make sure it is in the same folder, and that you’re running from that folder the program.
Then, on the main program file use this:
char *ReadSources(const char *fileName)
{
FILE *file = fopen(fileName, "rb");
if (!file)
{
printf("ERROR: Failed to open file '%s'
", fileName);
return NULL;
}
if (fseek(file, 0, SEEK_END))
{
printf("ERROR: Failed to seek file '%s'
", fileName);
fclose(file);
return NULL;
}
long size = ftell(file);
if (size == 0)
{
printf("ERROR: Failed to check position on file '%s'
", fileName);
fclose(file);
return NULL;
}
rewind(file);
char *src = (char *)malloc(sizeof(char) * size + 1);
if (!src)
{
printf("ERROR: Failed to allocate memory for file '%s'
", fileName);
fclose(file);
return NULL;
}
printf("Reading file '%s' (size %ld bytes)
", fileName, size);
size_t res = fread(src, 1, sizeof(char) * size, file);
if (res != sizeof(char) * size)
{
printf("ERROR: Failed to read file '%s'
", fileName);
fclose(file);
free(src);
return NULL;
}
src[size] = '\0'; /* NULL terminated */
fclose(file);
return src;
}
int main(){
...
char *sources = ReadSources("addone.cl");
if( NULL == sources ){
printf("Error: Failed to read sources into memory...
");
clReleaseContext(context);
return -1;}
program = clCreateProgramWithSource(context, 1, (const char**)&sources, NULL, NULL);
if(program == (cl_program)0){
printf("ERROR: Failed to create Program with source...
");
clReleaseContext(context);
free(sources);
return -1;
}
ciErrNum=clBuildProgram(program,0, NULL, NULL, NULL, NULL);
if(ciErrNum == CL_SUCCESS){
printf("OK!
");
}else{
printf("Error %i!
", ciErrNum);
ciErrNum=clGetProgramBuildInfo (program,devices[0],CL_PROGRAM_BUILD_LOG, sizeof(Buffer), Buffer, NULL);
if(ciErrNum == CL_SUCCESS)
{
printf("CL_PROGRAM_BUILD_LOG: %s
", Buffer);
}else{
printf("Error %i!
", ciErrNum);
return 1;
}
return 1;
}
ciErrNum=clGetProgramBuildInfo (program,devices[0],CL_PROGRAM_BUILD_LOG, sizeof(Buffer), Buffer, NULL);
if(ciErrNum == CL_SUCCESS)
{
printf("CL_PROGRAM_BUILD_LOG: %s
", Buffer);
}else{
printf("Error %i!
", ciErrNum);
return 1;
}
kernel = clCreateKernel(program, "addone", &err);
...
}