0

Im a programming OpenCL via pyopenCL on a Ubuntu 16.04.3 64bit, on Nvidia's Tesla K10.G2.8GB.

So far, anything runs smoothly as long as I don't include header files into my OpenCL kernel. As soon, as I put #include <stdlib.h> on top of my header file, the compilation of my openCL kernels fails with different files missing, amongst them being

gnu/stubs-32.h
sys/cdefs.h

Searching for that problem, brings up answers like

Error "gnu/stubs-32.h: No such file or directory" while compiling Nachos source code

or

https://askubuntu.com/questions/470796/fatal-error-sys-cdefs-h-no-such-file-or-directory

baiscally suggesting to install libc6-dev-i386 or gcc-multilib and g++-multilib, supposing that the underlying problem is a 64bit/32bit problem. My question is, are my OpenCL binaries for the GPU compiled as 32bit binaries (how can I check?)?

If yes:

Are there other caveats, when I want to compile 32bit binaries on a 64bit OS?

Furthermore: Can I use 64bit floats, when my kernel is compiled in 32bit? (e.g., will #pragma OPENCL EXTENSION cl_khr_fp64 : enable still work?)

If no:

Do I have to manually locate / copy all the needed header files and include them by hand?

Also: Some of my co-workers even doubt, that including standard C headers into OpenCL kernels is possible due to missing linkers. Any light on that is also appreciated.

Dschoni
  • 3,476
  • 5
  • 38
  • 72
  • I am not sure, but I think OpenCL might just be the language https://www.khronos.org/files/opencl-1-2-quick-reference-card.pdf and related resources: https://www.khronos.org/opencl/resources . In my very limited knowledge of PyOpenCL, I have not written or seen `#include _any_library_` in a kernel. – benshope Sep 26 '17 at 08:20
  • A quick search for `include header openCL` here on SO turns up at least some people who included their own headers into OpenCL kernel code. I'm talking about kernel code written in OpenCL C (basically a subset of C) – Dschoni Sep 26 '17 at 08:24
  • Oh, yea I guess so. Just saw this one: https://stackoverflow.com/questions/14502925/include-headers-to-opencl-cl-file I'll let someone who knows more about PyOpenCL answer your question... – benshope Sep 26 '17 at 08:32

1 Answers1

3

Standard C library and other system headers cannot be included into OpenCL C code, basically because they are only compatible with the current system (a host), whereas an OpenCL C code could run on a different device with a different architecture (a GPU in your case).

As a replacement for standard C functions, OpenCL C defines a set of built-in functions, which are available without any #include: printf, large number of math functions, atomics, image-related functions, etc.

See the "OpenCL Specification: 6.12 Built-in Functions" for a complete list: https://www.khronos.org/registry/OpenCL/specs/opencl-1.2.pdf

That doesn't mean you can't create a header with OpenCL C code and #include it into an OpenCL C program. This works fine:

// foo.h
void foo() {
  printf("hello world!");
}

// kernel.cl
#include "foo.h"
__kernel void use_foo() {
  foo();
}