add AMD HIP support

Add support for AMD HIP.
This commit is contained in:
René Widera 2021-08-05 11:54:10 +02:00
parent 06ed280db4
commit a1d88cf991
5 changed files with 41 additions and 19 deletions

View File

@ -24,7 +24,7 @@ namespace detail
} }
}; };
#if GLM_COMPILER & GLM_COMPILER_CUDA #if (GLM_COMPILER & GLM_COMPILER_CUDA) || (GLM_COMPILER & GLM_COMPILER_HIP)
template<> template<>
struct compute_abs<float, true> struct compute_abs<float, true>
{ {

View File

@ -401,7 +401,7 @@ namespace detail
template<typename genType> template<typename genType>
GLM_FUNC_QUALIFIER genType mod(genType x, genType y) GLM_FUNC_QUALIFIER genType mod(genType x, genType y)
{ {
# if GLM_COMPILER & GLM_COMPILER_CUDA # if (GLM_COMPILER & GLM_COMPILER_CUDA) || (GLM_COMPILER & GLM_COMPILER_HIP)
// Another Cuda compiler bug https://github.com/g-truc/glm/issues/530 // Another Cuda compiler bug https://github.com/g-truc/glm/issues/530
vec<1, genType, defaultp> Result(mod(vec<1, genType, defaultp>(x), y)); vec<1, genType, defaultp> Result(mod(vec<1, genType, defaultp>(x), y));
return Result.x; return Result.x;
@ -601,7 +601,7 @@ namespace detail
# endif # endif
# elif (GLM_COMPILER & (GLM_COMPILER_GCC | GLM_COMPILER_CLANG)) && (GLM_PLATFORM & GLM_PLATFORM_ANDROID) && __cplusplus < 201103L # elif (GLM_COMPILER & (GLM_COMPILER_GCC | GLM_COMPILER_CLANG)) && (GLM_PLATFORM & GLM_PLATFORM_ANDROID) && __cplusplus < 201103L
return _isnan(x) != 0; return _isnan(x) != 0;
# elif GLM_COMPILER & GLM_COMPILER_CUDA # elif (GLM_COMPILER & GLM_COMPILER_CUDA) || (GLM_COMPILER & GLM_COMPILER_HIP)
return ::isnan(x) != 0; return ::isnan(x) != 0;
# else # else
return std::isnan(x); return std::isnan(x);
@ -642,7 +642,7 @@ namespace detail
# else # else
return std::isinf(x); return std::isinf(x);
# endif # endif
# elif GLM_COMPILER & GLM_COMPILER_CUDA # elif (GLM_COMPILER & GLM_COMPILER_CUDA) || (GLM_COMPILER & GLM_COMPILER_HIP)
// http://developer.download.nvidia.com/compute/cuda/4_2/rel/toolkit/docs/online/group__CUDA__MATH__DOUBLE_g13431dd2b40b51f9139cbb7f50c18fab.html#g13431dd2b40b51f9139cbb7f50c18fab // http://developer.download.nvidia.com/compute/cuda/4_2/rel/toolkit/docs/online/group__CUDA__MATH__DOUBLE_g13431dd2b40b51f9139cbb7f50c18fab.html#g13431dd2b40b51f9139cbb7f50c18fab
return ::isinf(double(x)) != 0; return ::isinf(double(x)) != 0;
# else # else

View File

@ -144,6 +144,8 @@
# define GLM_HAS_CXX11_STL 0 # define GLM_HAS_CXX11_STL 0
#elif (GLM_COMPILER & GLM_COMPILER_CUDA_RTC) == GLM_COMPILER_CUDA_RTC #elif (GLM_COMPILER & GLM_COMPILER_CUDA_RTC) == GLM_COMPILER_CUDA_RTC
# define GLM_HAS_CXX11_STL 0 # define GLM_HAS_CXX11_STL 0
#elif (GLM_COMPILER & GLM_COMPILER_HIP)
# define GLM_HAS_CXX11_STL 0
#elif GLM_COMPILER & GLM_COMPILER_CLANG #elif GLM_COMPILER & GLM_COMPILER_CLANG
# if (defined(_LIBCPP_VERSION) || (GLM_LANG & GLM_LANG_CXX11_FLAG) || defined(GLM_LANG_STL11_FORCED)) # if (defined(_LIBCPP_VERSION) || (GLM_LANG & GLM_LANG_CXX11_FLAG) || defined(GLM_LANG_STL11_FORCED))
# define GLM_HAS_CXX11_STL 1 # define GLM_HAS_CXX11_STL 1
@ -167,7 +169,8 @@
#else #else
# define GLM_HAS_STATIC_ASSERT ((GLM_LANG & GLM_LANG_CXX0X_FLAG) && (\ # define GLM_HAS_STATIC_ASSERT ((GLM_LANG & GLM_LANG_CXX0X_FLAG) && (\
((GLM_COMPILER & GLM_COMPILER_CUDA)) || \ ((GLM_COMPILER & GLM_COMPILER_CUDA)) || \
((GLM_COMPILER & GLM_COMPILER_VC)))) ((GLM_COMPILER & GLM_COMPILER_VC)) || \
((GLM_COMPILER & GLM_COMPILER_HIP))))
#endif #endif
// N1988 // N1988
@ -177,7 +180,8 @@
# define GLM_HAS_EXTENDED_INTEGER_TYPE (\ # define GLM_HAS_EXTENDED_INTEGER_TYPE (\
((GLM_LANG & GLM_LANG_CXX0X_FLAG) && (GLM_COMPILER & GLM_COMPILER_VC)) || \ ((GLM_LANG & GLM_LANG_CXX0X_FLAG) && (GLM_COMPILER & GLM_COMPILER_VC)) || \
((GLM_LANG & GLM_LANG_CXX0X_FLAG) && (GLM_COMPILER & GLM_COMPILER_CUDA)) || \ ((GLM_LANG & GLM_LANG_CXX0X_FLAG) && (GLM_COMPILER & GLM_COMPILER_CUDA)) || \
((GLM_LANG & GLM_LANG_CXX0X_FLAG) && (GLM_COMPILER & GLM_COMPILER_CLANG))) ((GLM_LANG & GLM_LANG_CXX0X_FLAG) && (GLM_COMPILER & GLM_COMPILER_CLANG)) || \
((GLM_COMPILER & GLM_COMPILER_HIP)))
#endif #endif
// N2672 Initializer lists http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2672.htm // N2672 Initializer lists http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2672.htm
@ -189,7 +193,8 @@
# define GLM_HAS_INITIALIZER_LISTS ((GLM_LANG & GLM_LANG_CXX0X_FLAG) && (\ # define GLM_HAS_INITIALIZER_LISTS ((GLM_LANG & GLM_LANG_CXX0X_FLAG) && (\
((GLM_COMPILER & GLM_COMPILER_VC) && (GLM_COMPILER >= GLM_COMPILER_VC15)) || \ ((GLM_COMPILER & GLM_COMPILER_VC) && (GLM_COMPILER >= GLM_COMPILER_VC15)) || \
((GLM_COMPILER & GLM_COMPILER_INTEL) && (GLM_COMPILER >= GLM_COMPILER_INTEL14)) || \ ((GLM_COMPILER & GLM_COMPILER_INTEL) && (GLM_COMPILER >= GLM_COMPILER_INTEL14)) || \
((GLM_COMPILER & GLM_COMPILER_CUDA)))) ((GLM_COMPILER & GLM_COMPILER_CUDA)) || \
((GLM_COMPILER & GLM_COMPILER_HIP))))
#endif #endif
// N2544 Unrestricted unions http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2544.pdf // N2544 Unrestricted unions http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2544.pdf
@ -200,7 +205,8 @@
#else #else
# define GLM_HAS_UNRESTRICTED_UNIONS (GLM_LANG & GLM_LANG_CXX0X_FLAG) && (\ # define GLM_HAS_UNRESTRICTED_UNIONS (GLM_LANG & GLM_LANG_CXX0X_FLAG) && (\
(GLM_COMPILER & GLM_COMPILER_VC) || \ (GLM_COMPILER & GLM_COMPILER_VC) || \
((GLM_COMPILER & GLM_COMPILER_CUDA))) ((GLM_COMPILER & GLM_COMPILER_CUDA)) || \
((GLM_COMPILER & GLM_COMPILER_HIP)))
#endif #endif
// N2346 // N2346
@ -212,7 +218,8 @@
# define GLM_HAS_DEFAULTED_FUNCTIONS ((GLM_LANG & GLM_LANG_CXX0X_FLAG) && (\ # define GLM_HAS_DEFAULTED_FUNCTIONS ((GLM_LANG & GLM_LANG_CXX0X_FLAG) && (\
((GLM_COMPILER & GLM_COMPILER_VC) && (GLM_COMPILER >= GLM_COMPILER_VC12)) || \ ((GLM_COMPILER & GLM_COMPILER_VC) && (GLM_COMPILER >= GLM_COMPILER_VC12)) || \
((GLM_COMPILER & GLM_COMPILER_INTEL)) || \ ((GLM_COMPILER & GLM_COMPILER_INTEL)) || \
(GLM_COMPILER & GLM_COMPILER_CUDA))) (GLM_COMPILER & GLM_COMPILER_CUDA)) || \
((GLM_COMPILER & GLM_COMPILER_HIP)))
#endif #endif
// N2118 // N2118
@ -223,7 +230,8 @@
#else #else
# define GLM_HAS_RVALUE_REFERENCES ((GLM_LANG & GLM_LANG_CXX0X_FLAG) && (\ # define GLM_HAS_RVALUE_REFERENCES ((GLM_LANG & GLM_LANG_CXX0X_FLAG) && (\
((GLM_COMPILER & GLM_COMPILER_VC)) || \ ((GLM_COMPILER & GLM_COMPILER_VC)) || \
((GLM_COMPILER & GLM_COMPILER_CUDA)))) ((GLM_COMPILER & GLM_COMPILER_CUDA)) || \
((GLM_COMPILER & GLM_COMPILER_HIP))))
#endif #endif
// N2437 http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2437.pdf // N2437 http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2437.pdf
@ -235,7 +243,8 @@
# define GLM_HAS_EXPLICIT_CONVERSION_OPERATORS ((GLM_LANG & GLM_LANG_CXX0X_FLAG) && (\ # define GLM_HAS_EXPLICIT_CONVERSION_OPERATORS ((GLM_LANG & GLM_LANG_CXX0X_FLAG) && (\
((GLM_COMPILER & GLM_COMPILER_INTEL) && (GLM_COMPILER >= GLM_COMPILER_INTEL14)) || \ ((GLM_COMPILER & GLM_COMPILER_INTEL) && (GLM_COMPILER >= GLM_COMPILER_INTEL14)) || \
((GLM_COMPILER & GLM_COMPILER_VC) && (GLM_COMPILER >= GLM_COMPILER_VC12)) || \ ((GLM_COMPILER & GLM_COMPILER_VC) && (GLM_COMPILER >= GLM_COMPILER_VC12)) || \
((GLM_COMPILER & GLM_COMPILER_CUDA)))) ((GLM_COMPILER & GLM_COMPILER_CUDA)) || \
((GLM_COMPILER & GLM_COMPILER_HIP))))
#endif #endif
// N2258 http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2258.pdf // N2258 http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2258.pdf
@ -247,7 +256,8 @@
# define GLM_HAS_TEMPLATE_ALIASES ((GLM_LANG & GLM_LANG_CXX0X_FLAG) && (\ # define GLM_HAS_TEMPLATE_ALIASES ((GLM_LANG & GLM_LANG_CXX0X_FLAG) && (\
((GLM_COMPILER & GLM_COMPILER_INTEL)) || \ ((GLM_COMPILER & GLM_COMPILER_INTEL)) || \
((GLM_COMPILER & GLM_COMPILER_VC) && (GLM_COMPILER >= GLM_COMPILER_VC12)) || \ ((GLM_COMPILER & GLM_COMPILER_VC) && (GLM_COMPILER >= GLM_COMPILER_VC12)) || \
((GLM_COMPILER & GLM_COMPILER_CUDA)))) ((GLM_COMPILER & GLM_COMPILER_CUDA)) || \
((GLM_COMPILER & GLM_COMPILER_HIP))))
#endif #endif
// N2930 http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2930.html // N2930 http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2930.html
@ -259,7 +269,8 @@
# define GLM_HAS_RANGE_FOR ((GLM_LANG & GLM_LANG_CXX0X_FLAG) && (\ # define GLM_HAS_RANGE_FOR ((GLM_LANG & GLM_LANG_CXX0X_FLAG) && (\
((GLM_COMPILER & GLM_COMPILER_INTEL)) || \ ((GLM_COMPILER & GLM_COMPILER_INTEL)) || \
((GLM_COMPILER & GLM_COMPILER_VC)) || \ ((GLM_COMPILER & GLM_COMPILER_VC)) || \
((GLM_COMPILER & GLM_COMPILER_CUDA)))) ((GLM_COMPILER & GLM_COMPILER_CUDA)) || \
((GLM_COMPILER & GLM_COMPILER_HIP))))
#endif #endif
// N2341 http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2341.pdf // N2341 http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2341.pdf
@ -271,7 +282,8 @@
# define GLM_HAS_ALIGNOF ((GLM_LANG & GLM_LANG_CXX0X_FLAG) && (\ # define GLM_HAS_ALIGNOF ((GLM_LANG & GLM_LANG_CXX0X_FLAG) && (\
((GLM_COMPILER & GLM_COMPILER_INTEL) && (GLM_COMPILER >= GLM_COMPILER_INTEL15)) || \ ((GLM_COMPILER & GLM_COMPILER_INTEL) && (GLM_COMPILER >= GLM_COMPILER_INTEL15)) || \
((GLM_COMPILER & GLM_COMPILER_VC) && (GLM_COMPILER >= GLM_COMPILER_VC14)) || \ ((GLM_COMPILER & GLM_COMPILER_VC) && (GLM_COMPILER >= GLM_COMPILER_VC14)) || \
((GLM_COMPILER & GLM_COMPILER_CUDA)))) ((GLM_COMPILER & GLM_COMPILER_CUDA)) || \
((GLM_COMPILER & GLM_COMPILER_HIP))))
#endif #endif
// N2235 Generalized Constant Expressions http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2235.pdf // N2235 Generalized Constant Expressions http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2235.pdf
@ -335,7 +347,8 @@
#else #else
# define GLM_HAS_MAKE_SIGNED ((GLM_LANG & GLM_LANG_CXX0X_FLAG) && (\ # define GLM_HAS_MAKE_SIGNED ((GLM_LANG & GLM_LANG_CXX0X_FLAG) && (\
((GLM_COMPILER & GLM_COMPILER_VC) && (GLM_COMPILER >= GLM_COMPILER_VC12)) || \ ((GLM_COMPILER & GLM_COMPILER_VC) && (GLM_COMPILER >= GLM_COMPILER_VC12)) || \
((GLM_COMPILER & GLM_COMPILER_CUDA)))) ((GLM_COMPILER & GLM_COMPILER_CUDA)) || \
((GLM_COMPILER & GLM_COMPILER_HIP))))
#endif #endif
// //
@ -410,7 +423,7 @@
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
// Qualifiers // Qualifiers
#if GLM_COMPILER & GLM_COMPILER_CUDA #if (GLM_COMPILER & GLM_COMPILER_CUDA) || (GLM_COMPILER & GLM_COMPILER_HIP)
# define GLM_CUDA_FUNC_DEF __device__ __host__ # define GLM_CUDA_FUNC_DEF __device__ __host__
# define GLM_CUDA_FUNC_DECL __device__ __host__ # define GLM_CUDA_FUNC_DECL __device__ __host__
#else #else
@ -425,7 +438,7 @@
# elif GLM_COMPILER & (GLM_COMPILER_GCC | GLM_COMPILER_CLANG) # elif GLM_COMPILER & (GLM_COMPILER_GCC | GLM_COMPILER_CLANG)
# define GLM_INLINE inline __attribute__((__always_inline__)) # define GLM_INLINE inline __attribute__((__always_inline__))
# define GLM_NEVER_INLINE __attribute__((__noinline__)) # define GLM_NEVER_INLINE __attribute__((__noinline__))
# elif GLM_COMPILER & GLM_COMPILER_CUDA # elif (GLM_COMPILER & GLM_COMPILER_CUDA) || (GLM_COMPILER & GLM_COMPILER_HIP)
# define GLM_INLINE __forceinline__ # define GLM_INLINE __forceinline__
# define GLM_NEVER_INLINE __noinline__ # define GLM_NEVER_INLINE __noinline__
# else # else
@ -512,7 +525,7 @@
#elif GLM_COMPILER & (GLM_COMPILER_GCC | GLM_COMPILER_CLANG | GLM_COMPILER_INTEL) #elif GLM_COMPILER & (GLM_COMPILER_GCC | GLM_COMPILER_CLANG | GLM_COMPILER_INTEL)
# define GLM_DEPRECATED __attribute__((__deprecated__)) # define GLM_DEPRECATED __attribute__((__deprecated__))
# define GLM_ALIGNED_TYPEDEF(type, name, alignment) typedef type name __attribute__((aligned(alignment))) # define GLM_ALIGNED_TYPEDEF(type, name, alignment) typedef type name __attribute__((aligned(alignment)))
#elif GLM_COMPILER & GLM_COMPILER_CUDA #elif (GLM_COMPILER & GLM_COMPILER_CUDA) || (GLM_COMPILER & GLM_COMPILER_HIP)
# define GLM_DEPRECATED # define GLM_DEPRECATED
# define GLM_ALIGNED_TYPEDEF(type, name, alignment) typedef type name __align__(x) # define GLM_ALIGNED_TYPEDEF(type, name, alignment) typedef type name __align__(x)
#else #else
@ -970,6 +983,8 @@ namespace detail
// Report compiler detection // Report compiler detection
# if GLM_COMPILER & GLM_COMPILER_CUDA # if GLM_COMPILER & GLM_COMPILER_CUDA
# pragma message("GLM: CUDA compiler detected") # pragma message("GLM: CUDA compiler detected")
# elif GLM_COMPILER & GLM_COMPILER_HIP
# pragma message("GLM: HIP compiler detected")
# elif GLM_COMPILER & GLM_COMPILER_VC # elif GLM_COMPILER & GLM_COMPILER_VC
# pragma message("GLM: Visual C++ compiler detected") # pragma message("GLM: Visual C++ compiler detected")
# elif GLM_COMPILER & GLM_COMPILER_CLANG # elif GLM_COMPILER & GLM_COMPILER_CLANG

View File

@ -235,7 +235,7 @@
#include "./gtx/rotate_vector.hpp" #include "./gtx/rotate_vector.hpp"
#include "./gtx/spline.hpp" #include "./gtx/spline.hpp"
#include "./gtx/std_based_type.hpp" #include "./gtx/std_based_type.hpp"
#if !(GLM_COMPILER & GLM_COMPILER_CUDA) #if !((GLM_COMPILER & GLM_COMPILER_CUDA) || (GLM_COMPILER & GLM_COMPILER_HIP))
# include "./gtx/string_cast.hpp" # include "./gtx/string_cast.hpp"
#endif #endif
#include "./gtx/transform.hpp" #include "./gtx/transform.hpp"

View File

@ -97,6 +97,9 @@
#define GLM_COMPILER_CLANG41 0x200000C0 #define GLM_COMPILER_CLANG41 0x200000C0
#define GLM_COMPILER_CLANG42 0x200000D0 #define GLM_COMPILER_CLANG42 0x200000D0
// HIP
#define GLM_COMPILER_HIP 0x40000000
// Build model // Build model
#define GLM_MODEL_32 0x00000010 #define GLM_MODEL_32 0x00000010
#define GLM_MODEL_64 0x00000020 #define GLM_MODEL_64 0x00000020
@ -135,6 +138,10 @@
# error "GLM requires CUDA 7.0 or higher" # error "GLM requires CUDA 7.0 or higher"
# endif # endif
// HIP
#elif defined(__HIP__)
# define GLM_COMPILER GLM_COMPILER_HIP
// SYCL // SYCL
#elif defined(__SYCL_DEVICE_ONLY__) #elif defined(__SYCL_DEVICE_ONLY__)
# define GLM_COMPILER GLM_COMPILER_SYCL # define GLM_COMPILER GLM_COMPILER_SYCL