invalid address space for argument to _kernel function


I wrote a kernel that takes a vector<int> type as an argument,
but when I run it the compiler seems not to recognize this type,
vector<int> is defined in “c:\Program Files\Microsoft Visual Studio 9.0\VC\include\vector”

my Kernel is defined in a .cl file.

How can I include header files to a .cl file to allow kernels to take structures defined in those files as arguments?

__kernel void findPairs( __global const CvSeq* objectKeypoints, __global const CvSeq* objectDescriptors,
           __global const CvSeq* imageKeypoints, __global const CvSeq* imageDescriptors, __global vector<int>& ptpairs )

Actually it’s an Opencv code I’m trying to run on GPU using Opencl.

Thanks in advancs, I really need help with this
I can give more details if needed

the vector class is part of the STL of C++. The CL compiler do not know any STL stuff (cause it is an OpenCL compiler, not C++)

A extra warning : Each compiling of any structure or class in different compilers could lead into data missalignment.

Thanks for your reply,

  • is there a type that I can replace vector with, and that is opencl compliant ?

I also have another question:
does structures must be defined in .cl file before using it in kernels,
when I use structures defined in .h I got errors, when I copy them to .cl file it works.


OpenCL just provides buffers. You can put whatever you’d like in them. So if you want a long list of ints just make it the right size and copy them in. You can then access it as an array. You won’t have any of the nice OO features of STL, though.

OpenCL will compile your .h files if you include them either from the compile command or with a #include in your kernel and they are in the right location. Otherwise it will not include anything other than the actual string you use to create a program.

I added the path to include files to my program like this:

ciErrNum = clBuildProgram(cpProgram, 0, NULL, "-Ic:\Program Files\OpenCV\cv\include", NULL, NULL);

like it’s described in the opencl spec but when I run it I got:

  • clang: Unknown command line argument ‘FilesOpencvinclude’. Try ‘clang --help’

does anyone knows what’s could be the problem ?
Go to the top of the pageReport Post

Seem like it couldn’t handle spaces in the include path.
Better use / (windows this is valid too, could help when develop multiplatform).
So you need an include path without any spaces in the name.

I did change the path and use / like this

ciErrNum = clBuildProgram(cpProgram, 0, NULL, "-I C:/Users/localcontrol/internship/OpenCV/cv/include", NULL, NULL);

but this time it doesn’t run my kernels, I don’t get ‘cv.h’ file not found like before,
it just run the program until clBuildProgram, and then nothing

Try directly copy-and-pasting your header into the cl code you’re passing to clCreateProgram and see if that works. If it does, then it sounds like a driver bug accessing the header file. If not, then there’s a problem with your header file.