invalid address space for argument to _kernel function

Hi,

I wrote a kernel that takes a vector type as an argument,

but when I run it the compiler seems not to recognize this type,

vector is defined in “c:\Program Files\Microsoft Visual Studio 9.0\VC\include\vector” (visual studio file)

my Kernel is defined in a .cl file.

How can I include header files to a .cl file?

I want 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 advance, I really need help with this

I can give more details if needed

OpenCL does not support classes nor templates so you can’t use vector even if you include the correct header files.
You have to replace vector with an int array with a size variable.

Thanks for your reply,

I’m a beginner, so can you please explain to me how to specify an int array with size variable ?

I have another question:

How can we add header files to .cl file,

when I include them it doesn’t work, I get ‘file.h’ file not found, even though it works when I add it in .c file in the same project

Thanks.

You have to allocate memory buffer through OpenCL’s API anyway (which you can specify its size at run time). You also need another argument for the size.

You can use #include as a normal C file, but you need to pass the “-I path” option when calling clBuildProgram.

Thanks, it really helped,

I’m reading Opencl spec for building program options

I added the path to my program like this:

[codebox]

ciErrNum = clBuildProgram(cpProgram, 0, NULL, “-Ic:\Program Files\OpenCV\cv\include”, NULL, NULL);[/codebox]

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 ?

I post more details of my problem

this is what I have in my kernel in .cl file

[codebox]__kernel void findPairs( __global const CvSeq* objectKeypoints, __global const CvSeq* objectDescriptors,

       __global const CvSeq* imageKeypoints, __global const CvSeq* imageDescriptors, __global int* ptpairs )

{

int i; int j;

CvSeqReader reader, kreader;

cvStartReadSeq( objectKeypoints, &kreader, 0);

cvStartReadSeq( objectDescriptors, &reader, 0);

//ptpairs.clear();

ptpairs = 0; // ptpairs.clear()?

for( i = 0; i < objectDescriptors->total; i++ )

{

    const CvSURFPoint* kp = (const CvSURFPoint*)kreader.ptr;

    const float* descriptor = (const float*)reader.ptr;

    CV_NEXT_SEQ_ELEM( kreader.seq->elem_size, kreader );

    CV_NEXT_SEQ_ELEM( reader.seq->elem_size, reader );

    int nearest_neighbor = naiveNearestNeighbor( descriptor, kp->laplacian, imageKeypoints, imageDescriptors );

    if( nearest_neighbor >= 0 )

    {

     for( j = 0; i < 2*objectDescriptors->total; j++ )

     {

        //ptpairs.push_back(i);

        ptpairs[j] = i; //ptpairs.push_back(i)?

        //ptpairs.push_back(nearest_neighbor);

        ptpairs[j+1] = nearest_neighbor; //ptpairs.push_back(nearest_neighbor);

        j=j+1;

     }

    }

}

} [/codebox]

I got an error because it doesn’t recognise CvSeq structure in argument, the structure is defined in header file

so I include the file .h and add the path to clbuildprogram like this

[codebox]const char* cvinclude = “cv.h”;

const char* cvinclude_path = shrFindFilePath(cvinclude, argv[0]);

ciErrNum = clBuildProgram(cpProgram, 0, NULL, "-Icvinclude_path", NULL, NULL);[/codebox]

But I still get cv.h not found

please help, I hope I made my problem clear enough,

I post more details of my problem

this is what I have in my kernel in .cl file

[codebox]__kernel void findPairs( __global const CvSeq* objectKeypoints, __global const CvSeq* objectDescriptors,

       __global const CvSeq* imageKeypoints, __global const CvSeq* imageDescriptors, __global int* ptpairs )

{

int i; int j;

CvSeqReader reader, kreader;

cvStartReadSeq( objectKeypoints, &kreader, 0);

cvStartReadSeq( objectDescriptors, &reader, 0);

//ptpairs.clear();

ptpairs = 0; // ptpairs.clear()?

for( i = 0; i < objectDescriptors->total; i++ )

{

    const CvSURFPoint* kp = (const CvSURFPoint*)kreader.ptr;

    const float* descriptor = (const float*)reader.ptr;

    CV_NEXT_SEQ_ELEM( kreader.seq->elem_size, kreader );

    CV_NEXT_SEQ_ELEM( reader.seq->elem_size, reader );

    int nearest_neighbor = naiveNearestNeighbor( descriptor, kp->laplacian, imageKeypoints, imageDescriptors );

    if( nearest_neighbor >= 0 )

    {

     for( j = 0; i < 2*objectDescriptors->total; j++ )

     {

        //ptpairs.push_back(i);

        ptpairs[j] = i; //ptpairs.push_back(i)?

        //ptpairs.push_back(nearest_neighbor);

        ptpairs[j+1] = nearest_neighbor; //ptpairs.push_back(nearest_neighbor);

        j=j+1;

     }

    }

}

} [/codebox]

I got an error because it doesn’t recognise CvSeq structure in argument, the structure is defined in header file

so I include the file .h and add the path to clbuildprogram like this

[codebox]const char* cvinclude = “cv.h”;

const char* cvinclude_path = shrFindFilePath(cvinclude, argv[0]);

ciErrNum = clBuildProgram(cpProgram, 0, NULL, "-Icvinclude_path", NULL, NULL);[/codebox]

But I still get cv.h not found

please help, I hope I made my problem clear enough,

Actually, I can see another problem, because you are making calls to cv functions that are defined in external libraries, which are, in all likelihood, not built for GPUs. Even if you can get past the include option, there will be a problem with linking. So I’m not sure you can actually use OpenCV functions in your kernel. So the problem with the #include may be the least of your issues.

OK, that may explain a lot.

I think I did added the .h file but it didn’t build the program,

now I’m assuming that’s because of what you said