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

北战南征 提交于 2020-01-01 11:37:10

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/46469062/warning-host-annotation-on-a-defaulted-function-is-ignored-why

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