4

我正在尝试将参数传递给其中包含空格的 OpenCL 编译器,但我找不到如何让它正确处理空格(即不仅仅是将它们解释为下一个参数的开始)。我的代码是这样的:

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

显然,这会导致编译器错误

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

有谁知道正确的语法以使其理解我希望它定义OutputTypeunsigned char

4

3 回答 3

3

即使这个问题很老,我仍然不时遇到它。AMD 的 OpenCL 工具链仍然不能处理在命令行中定义的宏中的空格,而它现在似乎可以与 NVIDIA 一起使用。

简单的解决方案是用 \t 替换所有空格。

制表符算作编译器的空白,但不算作预处理器的标记分隔符。

于 2015-11-06T12:02:11.510 回答
1

This is a bug in the command line space handling, it is not (at least on recent NVIDIA platforms) working as a standard Unix (or at least Windows) commandline should.

I've tried putting many braces, including \' \" \\" \\' and the backtick `. I've even tried escaping the space itself (-D OutputType=unsigned\ char). This does not help, the command line string is probably simply chopped to tokens based on positions of spaces, and noone seems to care about braces.

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

#define OutputType unsigned char

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

#define MKTWOWORD(a,b) a b

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 have to do string processing only on the commandline and not on the whole source code.

It's a bummer, but getting the MKTWOWORD macro inside the source code using the -D option is not possible, as it would result in a chiken-or-egg problem. You just have to include that in your kernels.

于 2013-10-25T11:06:24.793 回答
0

您是否尝试过使用 \" 来逃避它们:

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

?

于 2012-11-23T16:12:30.243 回答