ingowald / optix7course

Apache License 2.0
452 stars 80 forks source link

Compiler warning due to a missing of annotation #25

Closed Han-ga86caq closed 2 years ago

Han-ga86caq commented 2 years ago

During the compilation, an annoying warning constantly showing:

/optix7course/common/gdt/gdt/math/LinearSpace.h(306): warning: calling a __host__ function from a __host__ __device__ function is not allowed detected during instantiation of "gdt::LinearSpace3<T> gdt::operator*(const gdt::LinearSpace3<T> &, const gdt::LinearSpace3<T> &) [with T=gdt::vec3f]" /optix7course/common/glfWindow/GLFWindow.h(432): here

After reading the code, I found that the warning comes from /optix7course/common/gdt/gdt/math/LinearSpace.h line 305:

template<typename T> inline T  operator*(const LinearSpace3<T>& a, const T & b) { return b.x*a.vx + b.y*a.vy + b.z*a.vz; }

where the annotation __both__ (aka. __host__ __device__ ) is missing.

After adding the annotation, that is, changing line 305 into

template<typename T> inline __both__ T operator*(const LinearSpace3<T>& a, const T & b) { return b.x*a.vx + b.y*a.vy + b.z*a.vz; }

the warning is gone.

However, I noticed the indentation of this line does not match the other operator definition, does this imply that deleting __both__ annotation is intended for avoiding other issues? (This is my first time submitting issues, please forgive me if my question is stupid...)

ingowald commented 2 years ago

Hey - First of all: thanks for submitting this, even though I didn't even see it until today :-/ (for some reason github doesn't ping me on new issues, no idea why... oh well).

Re that missing "both" : Reason I didn't see this in the first place is that I mostly develop on linux, which seems to be more forgiving re that annotation; but you're right it should be there, so just added it. Hope that fixes is for windows too; if not, let me know! (and in future, feel free to send a push request on your changes; i'd be happy to accept!).

Re indentation: in my editor (emacs, under linux) it actually does look good after I indent, so probably again some windows/linux difference, and not something to worry about. The reason that some of the lines to have these annotations and other not is simply that the entirety of the gdt/ subdirectory is based on some originally cpu-only library (blatantly stolen from embree and ospray), with the port to CUDA happening "on demand" - ie, i only ever added the "both" to those functions I actually used. So again, not something to worry about all too much ... ( I appreciate the thoughtfulness, though :-) )