如何隐藏NVCC的“功能已被声明但从未被引用”。警告? [英] How to hide NVCC's "function was declared but never referenced" warnings?

查看:137
本文介绍了如何隐藏NVCC的“功能已被声明但从未被引用”。警告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在编译使用Google Test的CUDA程序时, nvcc 会发出假阳性警告:

When compiling CUDA programs which use Google Test, nvcc will emit false-positive warnings:


function< name>被声明但从未引用

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

谷歌测试和CUDA 9.1(我相信它是在CUDA 9.0中开始发生的,并且该错误在CUDA 8.0中不存在)。如果测试在全局名称空间中,则不会发生此问题。

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.

是否可以禁用这些警告?我知道我可以使用 -w 禁用所有警告,但是我想保留其他类型的警告。

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.

推荐答案

您可以尝试蛮力方式:

   #pragma push
   #pragma diag_suppress 177 // suppress "function was declared but never referenced warning"

   .. your function ..

   #pragma pop

这篇关于如何隐藏NVCC的“功能已被声明但从未被引用”。警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆