View Full Version : opencl API : include headers to .cl file
03-05-2010, 03:56 AM
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:
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.
03-05-2010, 01:22 PM
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.
03-08-2010, 02:56 AM
I did what you said,
I included the .h file to clCreateProgramWithSource, just as source file, this is my code:
const char* clSourcefile = "oclfind_obj.cl";// source file
const char* cvincludefile = "cv.h"; //include file
// Program Setup
const char* strings;
const char* source_path = shrFindFilePath(clSourcefile, argv);
char *source = oclLoadProgSource(source_path, "", &program_length);
shrCheckErrorEX(source != NULL, shrTRUE, pCleanup);
const char* include_path = shrFindFilePath(cvincludefile, argv);
char *cvinclude = oclLoadProgSource(include_path, "", &include_length);
shrCheckErrorEX(cvinclude != NULL, shrTRUE, pCleanup);
strings = source;
strings = cvinclude;
lenghts = program_length;
lenghts = 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.
03-08-2010, 06:34 PM
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.
03-09-2010, 01:30 AM
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
03-10-2010, 02:49 PM
'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
03-11-2010, 01:11 AM
I did what you said,
the compiler is working fine,
actually it's a problem with my code
Powered by vBulletin® Version 4.2.2 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.