Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"warning: __host__ annotation on a defaulted function is ignored" <- why?

Switching from CUDA 8.0 to CUDA 9.0 RC, I get a warning about:

__host__ __device__ ~Foo() = default;

The warning is:

path/to/Foo.cuh(69): warning: __host__ annotation on a defaulted function("~Foo") is ignored

which I didn't use to get before. Should I really be getting this warning? What's wrong with indicating you want the default destructor on both the device and the host side?

like image 233
einpoklum Avatar asked Sep 28 '17 12:09

einpoklum


1 Answers

What's wrong with indicating you want the default destructor on both the device and the host side?

But that isn't what the code says. It says you want the same trivial default destructor in both host and device, and that is why there is a warning, because neither compiler (host and device) will potentially emit the same default destructor (and because the the way the compilation trajectory works that can't happen).

NVIDIA claim that the recent device toolchains support N2346. If you want that behaviour (and actually understand what it entails), then the correct code should just be:

~Foo() = default;

Both compilers will automagically emit their own default destructors in both codes and everything will just work.

If you want a hacky workaround for an existing code base, adding

-Xcudafe="--diag_suppress=2886" 

to your nvcc build commands should eliminate the warning, although I counsel against suppressing warnings.

[Answer added as a summary of comments discussion to get question off the unanswered list for the CUDA tag. ]

like image 179
4 revs Avatar answered Nov 12 '22 09:11

4 revs