将预处理变量传递给 NVCC 来编译 CUDA?
当我使用 NVCC 编译 CUDA 代码并且我已经在代码中定义了一个预处理变量(例如 #define DEBUG_OUTPUT 0
)时,有没有办法在编译时动态覆盖这样的变量?我尝试指定 NVCC 选项 -DDEBUG_OUTPUT=1
但这不起作用:它给了我:
警告 C4005:“DEBUG_OUTPUT”:宏重新定义
When I compile my CUDA code with NVCC and I have already defined a preprocessing variable in the code, e.g. #define DEBUG_OUTPUT 0
, is there a way to overwrite such a variable on the fly when compiling? I tried so specify the NVCC option -DDEBUG_OUTPUT=1
but this doesn't work: It gives me:
warning C4005: 'DEBUG_OUTPUT': Macro-Redefinition
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
无论您在 -D 之后指定什么,它都会在处理输入文件之前定义。但是,它不会删除文件中出现的定义。因此,如果您编写了
-DDEBUG_OUTPUT
但文件中有#define DEBUG_OUTPUT
,则后者是前者的重新定义。为了处理这种情况,你可以在文件中写入:注意,它实际上与 nvcc 无关。同样的行为也出现在 C/C++ 中。
Whatever you specify after -D, it gets defined before processing the input files. However, it does not remove the definitions that occur in the file. So, if you write
-DDEBUG_OUTPUT
but then you have#define DEBUG_OUTPUT
in the file, the latter is a redefinition of the former. To handle that case, you can write in the file:Note, it has actually nothing to do with nvcc. Same behaviour appears in C/C++.
如果已经定义了预处理器宏并且您确定不需要它原来的内容,只需有条件地重新定义它:
If a preprocessor macro is already defined and you are sure that you don't need whatever it was originally, just redefine it conditionally: