diff --git a/projects/clr/hipamd/include/hip/amd_detail/amd_hip_vector_types.h b/projects/clr/hipamd/include/hip/amd_detail/amd_hip_vector_types.h index b561dbcefb..ada471d353 100644 --- a/projects/clr/hipamd/include/hip/amd_detail/amd_hip_vector_types.h +++ b/projects/clr/hipamd/include/hip/amd_detail/amd_hip_vector_types.h @@ -2427,6 +2427,118 @@ typedef union { type r{x, y, z, w}; \ return r; \ } + +template +__HOST_DEVICE__ +__forceinline__ +typename std::enable_if< + sizeof(T) / sizeof(typename T::value_type) == 1 && + sizeof(U) / sizeof(typename U::value_type) >= 1, T>::type +mapElem(const U &u) { + T t; + t.x = static_cast(u.x); + return t; +} + +template +__HOST_DEVICE__ +__forceinline__ +typename std::enable_if< + sizeof(T) / sizeof(typename T::value_type) == 2 && + sizeof(U) / sizeof(typename U::value_type) >= 2, T>::type +mapElem(const U &u) { + T t; + t.x = static_cast(u.x); + t.y = static_cast(u.y); + return t; +} + +template +__HOST_DEVICE__ +__forceinline__ +typename std::enable_if< + sizeof(T) / sizeof(typename T::value_type) == 3 && + sizeof(U) / sizeof(typename U::value_type) >= 3, T>::type +mapElem(const U &u) { + T t; + t.x = static_cast(u.x); + t.y = static_cast(u.y); + t.z = static_cast(u.z); + return t; +} + +template +__HOST_DEVICE__ +__forceinline__ +typename std::enable_if< + sizeof(T) / sizeof(typename T::value_type) == 4 && + sizeof(U) / sizeof(typename U::value_type) >= 4, T>::type +mapElem(const U &u) { + T t; + t.x = static_cast(u.x); + t.y = static_cast(u.y); + t.z = static_cast(u.z); + t.w = static_cast(u.w); + return t; +} + +template +__HOST_DEVICE__ +__forceinline__ +typename std::enable_if< + std::is_same::value || + std::is_same::value || + std::is_same::value || + std::is_same::value || + std::is_same::value || + std::is_same::value || + std::is_same::value, const T>::type +mapFrom(const U &u) { + union { + U u; + T t; + } d = { u }; + return d.t; +} + +template +__HOST_DEVICE__ +__forceinline__ +typename std::enable_if< + (sizeof(T) == sizeof(typename T::value_type)) || + std::is_same::value || + std::is_same::value || + std::is_same::value, const T>::type +mapFrom(const U &u) { + union { + U u; + T t; + } d = { u }; + return d.t; +} + +template +__HOST_DEVICE__ +__forceinline__ +typename std::enable_if< + (sizeof(T) > sizeof(typename T::value_type)) && ( + std::is_same::value || + std::is_same::value || + std::is_same::value || + std::is_same::value), const T>::type +mapFrom(const U &u) { + union { + U u; + int4 i4; + uint4 u4; + } d = { u }; + if(std::is_signed::value) { + return mapElem(d.i4) ; + } else { + return mapElem(d.u4); + } +} + #else #define DECLOP_MAKE_ONE_COMPONENT(comp, type) \ static inline __HOST_DEVICE__ type make_##type(comp x) { \ diff --git a/projects/clr/hipamd/include/hip/amd_detail/texture_fetch_functions.h b/projects/clr/hipamd/include/hip/amd_detail/texture_fetch_functions.h index 47dfdbe9c2..f7b7e3f67b 100644 --- a/projects/clr/hipamd/include/hip/amd_detail/texture_fetch_functions.h +++ b/projects/clr/hipamd/include/hip/amd_detail/texture_fetch_functions.h @@ -142,7 +142,7 @@ static __forceinline__ __device__ __hip_img_chk__ __hip_tex_ret_t t { TEXTURE_PARAMETERS_INIT; auto tmp = __ockl_image_load_1Db(i, x); - return *reinterpret_cast<__hip_tex_ret_t*>(&tmp); + return mapFrom<__hip_tex_ret_t>(tmp); } template diff --git a/projects/clr/hipamd/include/hip/amd_detail/texture_indirect_functions.h b/projects/clr/hipamd/include/hip/amd_detail/texture_indirect_functions.h index e583b94006..5bd3f6f9db 100644 --- a/projects/clr/hipamd/include/hip/amd_detail/texture_indirect_functions.h +++ b/projects/clr/hipamd/include/hip/amd_detail/texture_indirect_functions.h @@ -68,7 +68,7 @@ static __device__ __hip_img_chk__ T tex1Dfetch(hipTextureObject_t textureObject, { TEXTURE_OBJECT_PARAMETERS_INIT auto tmp = __ockl_image_load_1Db(i, x); - return *reinterpret_cast(&tmp); + return mapFrom(tmp); } template <