Application Acceleration With FPGAs
Programmable Acceleration Cards (PACs), DCP, FPGA AI Suite, Software Stack, and Reference Designs
477 Discussions

C standard headers and macros

GRodr21
Beginner
843 Views

Hello:

I am having some trouble with C standard headers and macros in my kernels. I am trying to use some intrincate macros that work fine when they are resolved by the gcc preprocessor. However, aoc is unable to deal with them. It can not find <string.h>, for example (the files that contain these macro include this header, among others), so I have to force the inclusion of /usr/include with -I. As this is a standard header, I do not see why it should not be found straightforwardly. After that it will not found other headers, and will keep asking for more headers as soon as I provide the path to the compiler (aoc). All of them are standard and are found by gcc. The amount of errors apart from the inclusion of headers grows each time I include a new one and they refer to macro expansion.

 

Could someone give me a clue about what is happening? Are macros not supported by aoc preprocessor? What is going on with the inclusion of headers?

0 Kudos
2 Replies
HRZ
Valued Contributor III
672 Views

"aoc" is an OpenCL compiler, not a C compiler, and OpenCL only supports a subset of C at kernel level. Macros are certainly supported by aoc, but I am not sure what you are trying to do that requires including of C standard headers. Maybe if you post a simplified example kernel that shows the issue, we would be able to find a solution/work-around. At the same time, you can try compiling your kernel against NVIDIA or AMD's OpenCL SDK; if it still didn't work, then you know what you are trying to do is not supported in OpenCL.

0 Kudos
GRodr25
Beginner
672 Views

Since the problem stems from the files that contain the macros including standard C headers I am trying to reproduce the scenario with this minimal kernel:

 

#include <string.h>

 

__kernel void prueba() {

int a = 1;

}

 

Since aoc cannot find string.h I compile this kernel with:

aoc -I /usr/include -march=emulator min_example.cl

 

Then aoc outputs it cannot find stdef.h, so I include a new directory:

aoc -I /usr/include -I /usr/include/linux -march=emulator min_example.cl

 

Then 21 errors are generated. Among them:

In file included from /usr/include/string.h:633:

/usr/include/bits/string2.h:972:3: error: OpenCL does not support the 'register' storage class specifier

 register size_t __result = 0;

 

/usr/include/bits/string2.h:1128:25: error: use of undeclared identifier 'NULL'

 return *__s == '\0' ? NULL : (char *) (size_t) __s;

 

Any idea of what is going on here?

 

Edit:

It seems OpenCL 1.0 will not allow including string.h, among other C99 headers (https://www.khronos.org/registry/OpenCL/sdk/1.0/docs/man/xhtml/restrictions.html). Does this apply to the OpenCL version leveraged by Intel FPGA SDK for OpenCL?

 

Edit2:

According to https://www.intel.com/content/dam/www/programmable/us/en/pdfs/literature/hb/opencl-sdk/aocl_programming_guide.pdf (A.1.2 p.193) Intel FPGA SDK for OpenCL has this restriction.

0 Kudos
Reply