How to hide NVCC's “function was declared but never referenced” warnings?

与世无争的帅哥 提交于 2019-12-22 09:50:48

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!