-
Notifications
You must be signed in to change notification settings - Fork 118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cuda safety fixes #198
Cuda safety fixes #198
Conversation
Many places (basically everywhere), we had the following idiom: template<class T> class Foo { IMATH_HOSTDEVICE float bar(); // declaration }; ... template<class T> float Foo<T>::bar() { return 0.0; } // implementation But this is wrong! When actually compiled in Cuda mode (maybe depending on the compiler?), you can get errors about how you can't overload a `__host__ __device__` declaration with a `__host__`-only implementation. Which kinda makes sense. You have to match the two. So I have a WHOLE LOT of places where I had to add IMATH_HOSTDEVICE. Also, in ImathMath.h, we used this idiom: IMATH_HOSTDEVICE IMATH_DEPRECATED("reason") float foo() { ... } Now, this seems to work with `cudacc`, but when you use `clang++ --language=cuda` to compile Cuda to PTX (it can do that!), clang really doesn't like it when the `__host__ __device__` comes before the `[[ deprecated("msg") ]]`, it has an error about how the deprecated attribute can't go there. So we have to transpose these so that the IMATH_DEPRECATED is alwys the first thing in the declaration (which is the way we almost always write it anyway). Signed-off-by: Larry Gritz <[email protected]>
This PR is against RB-3.1 because I noticed the problem when trying to use 3.1. When accepted, it should also be cherry-picked into master and RB-3.0. (2.x is unnecessary because it predates the HOSTDEVICE annotations.) I would very much appreciate a 3.1.3 release that incorporates these fixes (when convenient), since the Imath headers are quite broken under Cuda without it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hope automation helped with this! Looks thorough and consistent
Some search & replace aid, but mostly manual, and double checking that my OSL Cuda builds against it stopped spitting out error messages. I think I got all the right spots. |
Signed-off-by: Larry Gritz <[email protected]>
Other places that appear to be missing IMATH_HOSTDEVICE: ImathShear.h line 681 (operator*) I grepped for "inline" and looked for missing IMATH_HOSTDEVICE. |
Signed-off-by: Larry Gritz <[email protected]>
Thanks for the extra pair of eyes, Cary! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
* Cuda safety fixes Many places (basically everywhere), we had the following idiom: template<class T> class Foo { IMATH_HOSTDEVICE float bar(); // declaration }; ... template<class T> float Foo<T>::bar() { return 0.0; } // implementation But this is wrong! When actually compiled in Cuda mode (maybe depending on the compiler?), you can get errors about how you can't overload a `__host__ __device__` declaration with a `__host__`-only implementation. Which kinda makes sense. You have to match the two. So I have a WHOLE LOT of places where I had to add IMATH_HOSTDEVICE. Also, in ImathMath.h, we used this idiom: IMATH_HOSTDEVICE IMATH_DEPRECATED("reason") float foo() { ... } Now, this seems to work with `cudacc`, but when you use `clang++ --language=cuda` to compile Cuda to PTX (it can do that!), clang really doesn't like it when the `__host__ __device__` comes before the `[[ deprecated("msg") ]]`, it has an error about how the deprecated attribute can't go there. So we have to transpose these so that the IMATH_DEPRECATED is alwys the first thing in the declaration (which is the way we almost always write it anyway). Signed-off-by: Larry Gritz <[email protected]> * Add missing HOSTDEVICE Signed-off-by: Larry Gritz <[email protected]> * Add missing HOSTDEVICE Signed-off-by: Larry Gritz <[email protected]>
* Cuda safety fixes from #198 Many places (basically everywhere), we had the following idiom: template<class T> class Foo { IMATH_HOSTDEVICE float bar(); // declaration }; ... template<class T> float Foo<T>::bar() { return 0.0; } // implementation But this is wrong! When actually compiled in Cuda mode (maybe depending on the compiler?), you can get errors about how you can't overload a `__host__ __device__` declaration with a `__host__`-only implementation. Which kinda makes sense. You have to match the two. So I have a WHOLE LOT of places where I had to add IMATH_HOSTDEVICE. Also, in ImathMath.h, we used this idiom: IMATH_HOSTDEVICE IMATH_DEPRECATED("reason") float foo() { ... } Now, this seems to work with `cudacc`, but when you use `clang++ --language=cuda` to compile Cuda to PTX (it can do that!), clang really doesn't like it when the `__host__ __device__` comes before the `[[ deprecated("msg") ]]`, it has an error about how the deprecated attribute can't go there. So we have to transpose these so that the IMATH_DEPRECATED is alwys the first thing in the declaration (which is the way we almost always write it anyway). * Some minor cuda corrections to address warnings Signed-off-by: Larry Gritz <[email protected]>
* Cuda safety fixes from AcademySoftwareFoundation#198 Many places (basically everywhere), we had the following idiom: template<class T> class Foo { IMATH_HOSTDEVICE float bar(); // declaration }; ... template<class T> float Foo<T>::bar() { return 0.0; } // implementation But this is wrong! When actually compiled in Cuda mode (maybe depending on the compiler?), you can get errors about how you can't overload a `__host__ __device__` declaration with a `__host__`-only implementation. Which kinda makes sense. You have to match the two. So I have a WHOLE LOT of places where I had to add IMATH_HOSTDEVICE. Also, in ImathMath.h, we used this idiom: IMATH_HOSTDEVICE IMATH_DEPRECATED("reason") float foo() { ... } Now, this seems to work with `cudacc`, but when you use `clang++ --language=cuda` to compile Cuda to PTX (it can do that!), clang really doesn't like it when the `__host__ __device__` comes before the `[[ deprecated("msg") ]]`, it has an error about how the deprecated attribute can't go there. So we have to transpose these so that the IMATH_DEPRECATED is alwys the first thing in the declaration (which is the way we almost always write it anyway). * Some minor cuda corrections to address warnings Signed-off-by: Larry Gritz <[email protected]> Signed-off-by: Cary Phillips <[email protected]>
* Cuda safety fixes from #198 Many places (basically everywhere), we had the following idiom: template<class T> class Foo { IMATH_HOSTDEVICE float bar(); // declaration }; ... template<class T> float Foo<T>::bar() { return 0.0; } // implementation But this is wrong! When actually compiled in Cuda mode (maybe depending on the compiler?), you can get errors about how you can't overload a `__host__ __device__` declaration with a `__host__`-only implementation. Which kinda makes sense. You have to match the two. So I have a WHOLE LOT of places where I had to add IMATH_HOSTDEVICE. Also, in ImathMath.h, we used this idiom: IMATH_HOSTDEVICE IMATH_DEPRECATED("reason") float foo() { ... } Now, this seems to work with `cudacc`, but when you use `clang++ --language=cuda` to compile Cuda to PTX (it can do that!), clang really doesn't like it when the `__host__ __device__` comes before the `[[ deprecated("msg") ]]`, it has an error about how the deprecated attribute can't go there. So we have to transpose these so that the IMATH_DEPRECATED is alwys the first thing in the declaration (which is the way we almost always write it anyway). * Some minor cuda corrections to address warnings Signed-off-by: Larry Gritz <[email protected]> Signed-off-by: Cary Phillips <[email protected]>
PR AcademySoftwareFoundation#198 added IMATH_HOSTDEVICE to the RB-3.1 branch, and PR AcademySoftwareFoundation#202 cherry-picked the change into main, but that cherry-pick somehow lost the IMATH_HOSTDEVICE on Matrix33<T>::invert(bool). Signed-off-by: Cary Phillips <[email protected]>
PR #198 added IMATH_HOSTDEVICE to the RB-3.1 branch, and PR #202 cherry-picked the change into main, but that cherry-pick somehow lost the IMATH_HOSTDEVICE on Matrix33<T>::invert(bool). Signed-off-by: Cary Phillips <[email protected]>
Many places (basically everywhere), we had the following idiom:
But this is wrong! When actually compiled in Cuda mode (maybe depending
on the compiler?), you can get errors about how you can't overload
a
__host__ __device__
declaration with a__host__
-only implementation.Which kinda makes sense. You have to match the two. So I have a WHOLE LOT
of places where I had to add IMATH_HOSTDEVICE.
Also, in ImathMath.h, we used this idiom:
Now, this seems to work with
cudacc
, but when you useclang++ --language=cuda
to compile Cuda to PTX (it can do that!), clangreally doesn't like it when the
__host__ __device__
comes before the[[ deprecated("msg") ]]
, it has an error about how the deprecatedattribute can't go there. So we have to transpose these so that the
IMATH_DEPRECATED is alwys the first thing in the declaration (which is
the way we almost always write it anyway).
Signed-off-by: Larry Gritz [email protected]