Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CUDA: NVCC gives controlling expression is constant warning on assert

I get the warning controlling expression is constant on assert statement like this:

assert(... && "error message");

Why this warning on this assert? How can I suppress this warning?

NVCC is the NVIDIA cuda compiler, I think it is based on LLVM. Why does it give this warning, when the same compiles fine with GCC or Visual C++ compilers?

like image 820
Anycorn Avatar asked Nov 11 '09 02:11

Anycorn


2 Answers

A portable alternative (possibly wrapped in a macro) would be something like:

 {
     const bool error_message = true;
     assert([...] && error_message);
 }

To clear up what i meant:

#define myAssert(msg, exp) { const bool msg(true); assert(msg && (exp)); }
// usage:
myAssert(ouch, a && b);

... gives e.g.:

assertion "ouch && (a && b)" failed [...]

like image 147
Georg Fritzsche Avatar answered Sep 19 '22 05:09

Georg Fritzsche


I ran into this exact problem and finally found a way to disable warnings on the device. Here are the details...

To disable a specific warning, you need to use the -Xcudafe flag combined with a token listed on this page (http://www.ssl.berkeley.edu/~jimm/grizzly_docs/SSL/opt/intel/cc/9.0/lib/locale/en_US/mcpcom.msg). For example, to disable the "controlling expression is constant" warning, pass the following to NVCC:

-Xcudafe "--diag_suppress=boolean_controlling_expr_is_constant"

This worked for me! For other warnings, see the above link.

like image 43
user2333829 Avatar answered Sep 20 '22 05:09

user2333829