Results 1 to 3 of 3

Thread: OpenCL kernel not found

  1. #1
    Junior Member
    Join Date
    Dec 2013
    Posts
    5

    OpenCL kernel not found

    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, \n"
    "__global cl_double *resultBuffer){\n"
    "cl_int id=get_global_id(0);\n"
    "resultBuffer[id] = dataBuffer[id] + 1.0;}\n"


    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!

  2. #2
    Newbie
    Join Date
    Jan 2014
    Posts
    4
    Quote Originally Posted by mjgcl1 View Post
    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, \n"
    "__global cl_double *resultBuffer){\n"
    "cl_int id=get_global_id(0);\n"
    "resultBuffer[id] = dataBuffer[id] + 1.0;}\n"


    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!

    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:

    Code :
     
    char *ReadSources(const char *fileName)
    {
    	FILE *file = fopen(fileName, "rb");
    	if (!file)
    	{
    		printf("ERROR: Failed to open file '%s'\n", fileName);
    		return NULL;
    	}
     
    	if (fseek(file, 0, SEEK_END))
    	{
    		printf("ERROR: Failed to seek file '%s'\n", fileName);
    		fclose(file);
    		return NULL;
    	}
     
    	long size = ftell(file);
    	if (size == 0)
    	{
    		printf("ERROR: Failed to check position on file '%s'\n", 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'\n", fileName);
    		fclose(file);
    		return NULL;
    	}
     
    	printf("Reading file '%s' (size %ld bytes)\n", fileName, size);
    	size_t res = fread(src, 1, sizeof(char) * size, file);
    	if (res != sizeof(char) * size)
    	{
    		printf("ERROR: Failed to read file '%s'\n", 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...\n");
    		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...\n");
    		clReleaseContext(context);
    		free(sources);
    	return -1;
    	}    
     
     
     
     
    	ciErrNum=clBuildProgram(program,0, NULL, NULL, NULL, NULL);
    	if(ciErrNum == CL_SUCCESS){
    		printf("OK!\n\n");
    	}else{
    		printf("Error %i!\n\n", ciErrNum);
     
     
    		ciErrNum=clGetProgramBuildInfo (program,devices[0],CL_PROGRAM_BUILD_LOG, sizeof(Buffer), Buffer, NULL);
    		if(ciErrNum == CL_SUCCESS)
    		{
    			printf("CL_PROGRAM_BUILD_LOG: \t%s\n", Buffer);
    		}else{
    			printf("Error %i!\n\n", 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: \t%s\n", Buffer);
        }else{
    		printf("Error %i!\n\n", ciErrNum);
    		return 1;
        }
     
     
     
     
      kernel = clCreateKernel(program, "addone", &err);
      ...
     
    }

  3. #3
    Junior Member
    Join Date
    Dec 2013
    Posts
    5

    C++ bindings and NVIDIA

    Many thanks for this! This is very elegant. As a byproduct I now have a nice program to test kernels prior to incorporating them into the main program. It looks like cl_double and cl_int were the problem. Kernel
    formatting appears ok including the #pragma statement. In case of success, the Intel OpenCL returns a bit of info about what it did, whilst the NVIDIA one is just empty but did not give any error messages. Perhaps this is ok. I actually prefer the C++ bindings. The only slightly annoying thing is that the kernel file has to be in the same directory as the where the program is executed. My program would be run from any directory on external data located in any directory. With the C++ bindings, I get a -33 error from clBuildProgram in NVIDIA, whilst it just

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •