问题
When compiling CUDA programs which use Google Test, nvcc
will emit false-positive warnings:
function <name> was declared but never referenced
An MCVE:
// test.cu
#include <gtest/gtest.h>
namespace {
__global__ void a_kernel() {
printf("Works");
}
TEST(ExampleTest, ExampleTestCase) {
a_kernel<<<1, 1>>>();
}
}
Compiling it gives:
$ nvcc test.cu -lgtest -lgtest_main
test.cu(9): warning: function "<unnamed>::ExampleTest_ExampleTestCase_Test::ExampleTest_ExampleTestCase_Test()" was declared but never referenced
This is confirmed with the master branch of google test and CUDA 9.1 (I believe it started happening with CUDA 9.0, and the bug is not present in CUDA 8.0). The problem doesn't happen if the test is in the global namespace.
Is there a way to disable these warnings? I know I can use -w
to disable all warnings, but I would like to keep other types of warnings.
回答1:
You could try the brute force way:
#pragma push
#pragma diag_suppress 177 // suppress "function was declared but never referenced warning"
.. your function ..
#pragma pop
来源:https://stackoverflow.com/questions/49836419/how-to-hide-nvccs-function-was-declared-but-never-referenced-warnings