Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NVCC warning level

Tags:

c++

cuda

nvcc

I would like NVCC to treat the warning below as an error:

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".

like image 822
user2030298 Avatar asked Jan 31 '13 19:01

user2030298


1 Answers

Quoting the CUDA COMPILER DRIVER NVCC reference guide, Section 3.2.8. "Generic Tool Options":

--Werror kind Make warnings of the specified kinds into errors. 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. The compiler will generate an error instead of a warning for a call from a __host__ __device__ to a __host__ function.

Therefore, do the following:

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.

like image 179
Vitality Avatar answered Oct 01 '22 00:10

Vitality