简体   繁体   English

NVCC 警告级别

[英]NVCC warning level

I would like NVCC to treat the warning below as an error:我希望 NVCC 将以下警告视为错误:

warning : calling a __host__ function("foo") from a __host__ __device__ function("bar")

NVCC documentation "NVIDIA CUDA Compiler Driver NVCC" doesn't even contain the word "warning". NVCC 文档“NVIDIA CUDA Compiler Driver NVCC”甚至不包含“警告”一词。

Quoting the CUDA COMPILER DRIVER NVCC reference guide, Section 3.2.8.引用 CUDA 编译器驱动程序 NVCC 参考指南, 第 3.2.8 节。 "Generic Tool Options" : “通用工具选项”

--Werror kind Make warnings of the specified kinds into errors. --Werror kind将指定种类的警告转化为错误。 The following is the list of warning kinds accepted by this option:以下是此选项接受的警告种类列表:

cross-execution-space-call Be more strict about unsupported cross execution space calls. cross-execution-space-call对不受支持的交叉执行空间调用更加严格。 The compiler will generate an error instead of a warning for a call from a __host__ __device__ to a __host__ function.对于从__host__ __device____host__函数的调用,编译器将生成错误而不是警告。

Therefore, do the following:因此,请执行以下操作:

Project -> Properties -> Configuration Properties -> CUDA C/C++ -> Command Line -> Additional Optics -> add --Werror cross-execution-space-call Project -> Properties -> Configuration Properties -> CUDA C/C++ -> Command Line -> Additional Optics -> add --Werror cross-execution-space-call

This test program这个测试程序

#include <cuda.h>
#include <cuda_runtime.h>

void foo() { int a = 2;}

__host__ __device__ void test() {
    int tId = 1;
    foo();
}

int main(int argc, char **argv) { }

returns the following warning返回以下警告

warning : calling a __host__ function("foo") from a __host__ __device__ function("test") is not allowed

without the above mentioned additional compilation option and returns the following error没有上面提到的额外编译选项并返回以下错误

Error   3   error : calling a __host__ function("foo") from a __host__ __device__ function("test") is not allowed

with the above mentioned additional compilation option.使用上面提到的附加编译选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM