Results 1 to 7 of 7

Thread: opencl API : include headers to .cl file

  1. #1
    Junior Member
    Join Date
    Mar 2010
    Posts
    18

    opencl API : include headers to .cl file

    Hi,

    I wrote a kernel in a .cl file, but when I include a .h file, and run code,
    I get ""file.h" not found".
    so I read the opencl spec, and found that I have to add the path to the headers to my buildprogram API (5.4.3 of 1.0spec), so this is my code line:
    Code :
    ciErrNum = clBuildProgram(cpProgram, 0, NULL, "-I C:/Users/localcontrol/internship/OpenCV/cv/include", NULL, NULL);

    but it doesn't work, the program crashes at this line,

    is anyone seeing what could be the problem,
    I really need help with this.
    thanks

  2. #2
    Junior Member
    Join Date
    Dec 2009
    Posts
    22

    Re: opencl API : include headers to .cl file

    when you use clCreateProgramWithSource, you transfer your .cl file. You can do the same thing for .h file, assuming your .h is for .cl file. Just transfer them together.

  3. #3
    Junior Member
    Join Date
    Mar 2010
    Posts
    18

    Re: opencl API : include headers to .cl file

    I did what you said,
    I included the .h file to clCreateProgramWithSource, just as source file, this is my code:
    Code :
    const char* clSourcefile = "oclfind_obj.cl";// source file
    const char* cvincludefile = "cv.h"; //include file
     // Program Setup
    	const char* strings[2];
     
        size_t program_length;
        const char* source_path = shrFindFilePath(clSourcefile, argv[0]);
        char *source = oclLoadProgSource(source_path, "", &program_length);
        shrCheckErrorEX(source != NULL, shrTRUE, pCleanup);
     
    	size_t include_length;
        const char* include_path = shrFindFilePath(cvincludefile, argv[0]);
        char *cvinclude = oclLoadProgSource(include_path, "", &include_length);
        shrCheckErrorEX(cvinclude != NULL, shrTRUE, pCleanup);
     
    	strings[0] = source;
    	strings[1] = cvinclude;
    	size_t lenghts[2];
    	lenghts[0] = program_length;
    	lenghts[1] = include_length;
        // create the program
    	cpProgram = clCreateProgramWithSource(cxGPUContext, 2,(const char **) &strings, (const size_t *) &lenghts, &ciErrNum);
        shrCheckErrorEX(ciErrNum, CL_SUCCESS, pCleanup);
     
        // build the program
        ciErrNum = clBuildProgram(cpProgram, 0, NULL, NULL, NULL, NULL);
        if (ciErrNum != CL_SUCCESS)
        {
    But when I run it I got nothing in the build log, before adding the .h file, I was getting errors tha it doesn't recognize
    undefined variables (defined in .h file), now I get nothing.,
    can you see if I maid an error in my code please.

  4. #4
    Junior Member
    Join Date
    Dec 2009
    Posts
    22

    Re: opencl API : include headers to .cl file

    I am not familiar with the class you use here for reading the files. But there must be something wrong when you do that. So what about, you just try to read a very simple .cl file. just to do some simple operation(not use variable you define in .h) to make sure the way of file reading is correct.

    then you can proceed to the .h file part.

  5. #5
    Junior Member
    Join Date
    Mar 2010
    Posts
    18

    Re: opencl API : include headers to .cl file

    actually I copied this syntaxe from nvidia exemples from sdk, and it's working fine to read .cl file
    it's working with my code too because I have errors returned from my .cl file
    so it can read .cl file, when I add .h it returns a buildprogram error,
    so I'm assuming it didn't read the .h right
    it's very anoying, all this opencl syntaxe just to include a header

  6. #6
    Junior Member
    Join Date
    Dec 2009
    Posts
    22

    Re: opencl API : include headers to .cl file

    'it's working with my code too because I have errors returned from my .cl file'

    this does not mean your code is good(you still can't run your code). 'you got error for .cl file' != you successfully read the file for the building of program.

    why don't you just follow my suggestion to read a simple .cl file to test. do some simple operation, plus/minus, whatever you like

  7. #7
    Junior Member
    Join Date
    Mar 2010
    Posts
    18

    Re: opencl API : include headers to .cl file

    I did what you said,
    the compiler is working fine,
    actually it's a problem with my code

Similar Threads

  1. include headers to OpenCL .cl file
    By yakovm in forum OpenCL
    Replies: 0
    Last Post: 01-24-2013, 07:09 AM
  2. include headers to .cl file
    By opencl_JEDI in forum OpenCL
    Replies: 1
    Last Post: 03-06-2010, 06:33 PM

Posting Permissions

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