Escaping space in OpenCL compiler arguments

I am trying to pass arguments to the OpenCL compiler that have spaces in it, but I cannot find how to handle it correctly (i.e. not just interpreting them as the beginning of the next argument). My code is as follows:

status = clBuildProgram(output_program, 1, devices, "-D OutputType=unsigned char", 0, 0);

Obviously this leads to a compiler error

Error in processing command line: Don't understand command line argument "char"!

Does anyone know the correct syntax to understand that I want it to define OutputType as an unsigned char ?

+4
source share
3 answers

Even if this question is out of date, I still come across it from time to time. The AMD OpenCL toolchain still doesn't handle spaces in macros defined on the command line, and now it seems to work with NVIDIA.

A simple solution is to replace all spaces with \ t.

Tabs are counted as omissions for the compiler, but are not considered as a separator token for the preprocessor.

+2
source

This is a mistake in processing the command line space; it is not (at least on the latest NVIDIA platforms) working as a standard Unix command line (or at least Windows).

I tried putting a lot of curly braces, including \' \" \\" \\' and the back of ` . I even tried to escape from the space itself ( -D OutputType=unsigned\ char ). This does not help, the command line is probably just chopped into tokens based on the positions of the spaces, and nobody seems to care about curly braces.

One solution is to read the source code in a line and prefix it with a single line:

 #define OutputType unsigned char 

There is, however, one simpler solution. You need to include the following macros in your files:

 #define MKTWOWORD(a,b) ab 

And then you can use any of:

 status = clBuildProgram(output_program, 1, devices, "-D OutputType=MKTWOWORD(unsigned,char)", 0, 0); status = clBuildProgram(output_program, 1, devices, "-D OutputType=MKTWOWORD(unsigned,int)", 0, 0); status = clBuildProgram(output_program, 1, devices, "-D OutputType=MKTWOWORD(signed,int)", 0, 0); status = clBuildProgram(output_program, 1, devices, "-D OutputType=int", 0, 0); 

The advantage is that you should only perform line processing on the command line, and not on the entire source code.

This is a bummer, but getting the MKTWOWORD macro inside the source code using the -D option is not possible, as this will lead to a chiken-or-egg problem. You just have to include this in your kernels.

+1
source

You tried to escape from them with \ ":

 status = clBuildProgram(output_program, 1, devices, "-D OutputType=\"unsigned char\"", 0, 0); 

?

0
source

Source: https://habr.com/ru/post/1447965/


All Articles