cancel
Showing results for 
Search instead for 
Did you mean: 

OpenCL

fresto
Journeyman III

How to include external library in kernel?

I use a OpenCL for my operations and I already have 30 files that differ only in a couple of functions. I read about this problem on the forums and realized that before version OpenCL 2.1  i can not add my library to the kernel. Is it true? I need to use an external library in the kernel to add all the functions and use them in the main file. I have use AMD RX Vega 64. Sorry for my english.

Tags (2)
0 Likes
Reply
2 Replies
fresto
Journeyman III

Re: How to include external library in kernel?

I found that can add external library in the kernel, but need add path of library to cpp code. Can someone tell me, how to add clCreateProgramWithSource() in C++ with path of library?

Thats part of my code

std::ifstream sourceFile(name);

std::string sourceCode(

std::istreambuf_iterator<char>(sourceFile),

(std::istreambuf_iterator<char>()));

Program::Sources source(1, std::make_pair(sourceCode.c_str(), sourceCode.length() + 1));

// Make program of the source code in the context

Program program = Program(context, source);

// Build program for these specific devices

errcode = program.build(devices);

if (errcode != CL_SUCCESS)

{

cout << "There were error during build kernel code. Please, check program code. Errcode = " << errcode << "\n";

cout << "BUILD LOG: " + program.getBuildInfo<CL_PROGRAM_BUILD_LOG>(devices[0]) + "\n";

getchar();

return;

}

// Make kernel

Kernel kernel(program, "vector_add");

0 Likes
Reply
dipak
Staff
Staff

Re: How to include external library in kernel?

Use clLinkProgram to link a set of compiled program objects and libraries to your kernel program. For that, first compile your source code using clCompileProgram  and generate the compiled objects. Then link the compile objects and other libraries to create final executable.