编译使用 Google Test 的 CUDA 程序时,nvcc
将发出误报警告:
function <name> was declared but never referenced
一个 MCVE:
// test.cu
#include <gtest/gtest.h>
namespace {
__global__ void a_kernel() {
printf("Works");
}
TEST(ExampleTest, ExampleTestCase) {
a_kernel<<<1, 1>>>();
}
}
编译它给出:
$ nvcc test.cu -lgtest -lgtest_main
test.cu(9): warning: function "<unnamed>::ExampleTest_ExampleTestCase_Test::ExampleTest_ExampleTestCase_Test()" was declared but never referenced
这在 google test 和 CUDA 9.1 的 master 分支中得到了确认(我相信它是从 CUDA 9.0 开始发生的,并且该错误在 CUDA 8.0 中不存在)。如果测试在全局命名空间中,则不会发生此问题。
有没有办法禁用这些警告?我知道我可以使用
-w
禁用 全部 警告,但我想保留其他类型的警告。
最佳答案
你可以试试蛮力的方式:
#pragma push
#pragma diag_suppress 177 // suppress "function was declared but never referenced warning"
.. your function ..
#pragma pop
关于cuda - 如何隐藏 NVCC 的 "function was declared but never referenced"警告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49836419/