Error using my .h files in Kernel OpenCL

Hi,

I successfully include my .h file in kernel, no erros in compile process
in VS 2010 occurs.
However, when kernel is compiled a error occour.
I guess that error is because of the link process.

I put the full path in #include statment.
Add path in VS2010 Linker option and copy .o file in all possible
directories.

The error is:
C:\DOCUME~1\A\CONFIG~1\Temp\OCL256.tmp.obj:fake:(.text+0x29): undefined
reference to i_imprime' C:\DOCUME~1\A\CONFIG~1\Temp\OCL256.tmp.obj:fake:(.text+0x92): undefined refer ence toi_imprime’

i_imprime is a function in my .h file.

Please help me, i don’t know more what i can do.

Very Thanks,
Luiz.

It sounds like you are mixing host code with kernel code. A few things are unclear to me after reading your question. What is the content of the header file? Where is it included? What is i_imprime? What object file are you placing in all possible directories? What does the kernel source look like?

Hi,

I had a sequential algorithm and i want paralelize with openCL.

Almost of the functions that i need to use in kernel, is in my .h file. So, i
put the sentence #include inside of kernel to use these functions.
When compile kernel no error occours in the #include sentence, but occours in
calling of functions described in my .h file.

i_imprime is one function present in my .h file.

The object file is .obj file compiled by VS2010, as i thought that in
kernel compile process was not find the .obj file to incorporate in .exe
file, i copy this .obj file in all directories of my project and includes
this paths in linker and include options of project.

The Kernel at first don’t do anything, because i need to make this
working first.

Very Thanks for help,

I too am having trouble identifying the problem. However, if you are mixing host and kernel code, you could have some issues from my past experience. Without seeing your code, I can only take a stab at what is wrong (if you want to post it here, more eyes can see it; otherwise you could email the solution to me and I could try to replicate and solve the issue). The following thoughts are random ideas that popped into my mind:

From what I understand, you have a bunch of functions from your sequential algorithm. Those are in a .h file. You have converted these functions to kernels, and they are also in the .h file.

Are you checking the error code when you build the OpenCL program, identify kernels, etc? That would be a great place to start. If you have a typo in the program, you’d probably get an error message, allowing you to track that down.

I have found that, when I compile OpenCL programs with the NVIDIA drivers, the kernel is stored in the temporary files location on your computer. That could be what it is trying to find, but can’t.

I’ve gotta head to class…should finish this post in about 3-4 hours.

Note that the compilation of the kernels is completely separate from the compilation of the host application. Kernel compilation normally happens during runtime and has nothing to do with the .obj-files created by Visual Studio.

Thanks for everyone that help me.

I know that the compilation of kernel is in run time.

Here is my problem, i put this example to help you to understand me.
The code descript below is my kernel


#include <D:/Meus Documentos/Programação/2010/OpenCL/Testes de Códigos/PrjTeste1/PrjTeste1/intervalar.h> //Here is my .h file that i create with functions that i need to work in my kernel

__kernel void soma_de_vetores( __global uint *vetor1,
__global uint *vetor2,
__global uint *vetor_resultante){
i_imprime(vetor[0]); //This function is inside of intervalar.h

}

The problem is, no error occur in #include sentence, but when i call the function i_imprime a error below happen:

O erro é:
C: \ DOCUME ~ 1 \ A CONFIG \ ~ 1 \ Temp \ OCL256.tmp.obj: (text +0
x29).:: fake indefinido
referência a «i_imprime ’
C: \ DOCUME ~ 1 \ A CONFIG \ ~ 1 \ Temp \ OCL256.tmp.obj: (text +0
x92).:: fake indefinido
referem-se
referência à «i_imprime ’

I guess that i found the problem, altough i don’t know how solve this.

When i put inside the Kernel #include with my .h file, all functions described in my .h file don’t were to for .obj file of kernel.

You can pass the definition (implementation) of your functions to clBuildProgramWithSource().

That is, your header file contains this:

void foo(__global float* bar);

Then your “library” string contains this:


#include <myheader.h>
void foo(__global float* bar)
{
    // Example implementation
    bar[get_global_id(0)] = get_global_id(0);
}

Your main program could look like this:


#include <myheader.h>

__kernel void mykernel(__global float* a, __global float* b)
{
    // ... do some stuff here...
    // ...then call into the "library"
    foo(a);
}

Finally, your host code would do something like this:


cl_char* mysources[2] = {mylibrary, mykernel};
cl_program program = clCreateProgramWithSource(context, 2, &mysources[0], NULL, &errcode);

Hi david.garcia,

Very Thanks, it is exactly what i needed.

Already that you help me, i want to ask something more.

I did exactly you sent, but a error happened in compilation of kernel.

      "_intervalo" has already been declared in the current scope

struct _intervalo

_intervalo is a struct that i declared in my .h file.

Thanks,

Luiz Drumond.

sounds like you included the .h file from several sources. try this:


#ifndef INTERVALO
#define INTERVALO
struct _intervalo
{
// your struct here
};

#endif

or alternatively (and i’m not sure if this will work in OCL, it does in c/c++), put this line at the top of your .h file.


#pragma once

These preprocessor directives simply tell the compiler not to define the same struct (or function/global variable/other shared resources) more than once.

its works!!!

Very Thanks Chai!!!