Including C header files in OpenCL kernels

Hi everybody,

I am using OpenCL on Ubuntu 16.4 64 bit with Nvidia Titan cards.
I am trying to include standard C header files into my OpenCL kernels, and am not sure if this is even possible.

If I add

#include <stdlib.h>

to the top of my *.cl kernel file, on compilation I get errors for missing header files, amongst them being

cdefs.h
stubs-32.h

and others. I installed gcc-multilib as well as g+±multilib, because these seem to be necessary for cross-compiling 32-bit libraries,
nevertheless I cannot make this work. Any insights?

Hi,

Did you read the standard? It states that there are not standard headers available, as OpenCL is just a subset of C99.

In 2.x it’s also C++ but you still can’t #include <stdlib.h> – these kernels execute on a GPU with far fewer resources than your CPU. The standard library is not supported there, C or C++.

ở việt nam bọn em đồn là diễn đàn này đi link chất lượng lắm, cho em đặt thử 1 liên kết xem chất lượng thật không nhé :)) các thánh cho em xin 1 phát nhấp chuột về web em nhé :smiley: hộp đựng rượu vang

      • Updated - - -

à, quên mất, file header của thím bị lỗi thì lên web của em mà tìm cách fix lỗi nhé

[QUOTE=desquang;42723]ở việt nam bọn em đồn là diễn đàn này đi link chất lượng lắm, cho em đặt thử 1 liên kết xem chất lượng thật không nhé :)) các thánh cho em xin 1 phát nhấp chuột về web em nhé :smiley: hộp đựng rượu vang

      • Updated - - -

à, quên mất, file header của thím bị lỗi thì lên web của em mà tìm cách fix lỗi nhé[/QUOTE]

ok its best for you

TLDR : not pre-compiled CPU libraries on a GPU.

It depends

If you use a header only C library, that does not depend on anything else, then pass
‘-I <folder_containing_header>’ to ‘clBuildProgram(…)’ .

Otherwise…

OpenCL explicitly provides for the use of libraries in the kernels.
See cl_program clLinkProgram(...) in the OpenCL API documentation.

However, any library must be compiled for the processor on which it will be run.
If you run your kernel on a multi-core CPU, in that case some of the OS libraries may be usable,
but where you run your kernels on other processors (GPU, TPU, DSP, FPGA),
then the library will need to be compiled in the machine code of that processor, (not just the bit-count).

Depending on the particular processor, there will be limits to the size of the device program, individual kernels, and the number and size of variables.

For most cases, this means that you would want relatively small libraries (compared to programming for a desktop CPU), and you would need the complete C source code of the libraries you wish to use in your kernel.

(For some more recent processors and OpenCL drivers, you may be able to use C++ libraries within certain constraints - read the documentation for the version you are using.)