From 4f2156dfaf50f222528271f3cb183f96740fd6fc Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Tue, 2 Apr 2019 11:48:24 -0400 Subject: [PATCH] Thrust detail::aligned_reinterpret_cast doesn't warn now We specialize aligned_reinterpret_cast inside vtk-m to fix the issues related to missing __host__ __device__ markups on the function. --- vtkm/exec/cuda/internal/ThrustPatches.h | 109 ++++++++++++++++++++++-- 1 file changed, 100 insertions(+), 9 deletions(-) diff --git a/vtkm/exec/cuda/internal/ThrustPatches.h b/vtkm/exec/cuda/internal/ThrustPatches.h index 5a36ccbe3..36eb21e49 100644 --- a/vtkm/exec/cuda/internal/ThrustPatches.h +++ b/vtkm/exec/cuda/internal/ThrustPatches.h @@ -20,7 +20,17 @@ #ifndef vtk_m_exec_cuda_internal_ThrustPatches_h #define vtk_m_exec_cuda_internal_ThrustPatches_h -//Forward declare of WrappedBinaryOperator +#include + +#ifdef VTKM_ENABLE_CUDA + +//So for thrust 1.8.0 - 1.8.2 the inclusive_scan has a bug when accumulating +//values when the binary operators states it is not commutative. +//For more complex value types, we patch thrust/bulk with fix that is found +//in issue: https://github.com/thrust/thrust/issues/692 +// +//This specialization needs to be included before ANY thrust includes otherwise +//other device code inside thrust that calls it will not see it namespace vtkm { namespace exec @@ -29,7 +39,7 @@ namespace cuda { namespace internal { - +//Forward declare of WrappedBinaryOperator template class WrappedBinaryOperator; } @@ -51,13 +61,6 @@ namespace detail { namespace accumulate_detail { -//So for thrust 1.8.0 - 1.8.2 the inclusive_scan has a bug when accumulating -//values when the binary operators states it is not commutative. -//For more complex value types, we patch thrust/bulk with fix that is found -//in issue: https://github.com/thrust/thrust/issues/692 -// -//This specialization needs to be included before ANY thrust includes otherwise -//other device code inside thrust that calls it will not see it template +T aligned_reinterpret_cast(U u); + +#define ALIGN_RE_T(RT) \ + template <> \ + inline __host__ __device__ RT* aligned_reinterpret_cast(void* u) \ + { \ + return reinterpret_cast(reinterpret_cast(u)); \ + } \ + template <> \ + inline __host__ __device__ RT* aligned_reinterpret_cast(vtkm::UInt8* u) \ + { \ + return reinterpret_cast(reinterpret_cast(u)); \ + } \ + struct SwallowSemicolon + +#define ALIGN_RE_VEC(RT, N) \ + template <> \ + inline __host__ __device__ vtkm::Vec* aligned_reinterpret_cast(void* u) \ + { \ + return reinterpret_cast*>(reinterpret_cast(u)); \ + } \ + template <> \ + inline __host__ __device__ vtkm::Vec* aligned_reinterpret_cast(vtkm::UInt8* u) \ + { \ + return reinterpret_cast*>(reinterpret_cast(u)); \ + } \ + struct SwallowSemicolon + +#define ALIGN_RE_PAIR(T, U) \ + template <> \ + inline __host__ __device__ vtkm::Pair* aligned_reinterpret_cast(void* u) \ + { \ + return reinterpret_cast*>(reinterpret_cast(u)); \ + } \ + template <> \ + inline __host__ __device__ vtkm::Pair* aligned_reinterpret_cast(vtkm::UInt8* u) \ + { \ + return reinterpret_cast*>(reinterpret_cast(u)); \ + } \ + struct SwallowSemicolon + +#ifndef VTKM_DONT_FIX_THRUST +ALIGN_RE_T(char); +ALIGN_RE_T(vtkm::Int8); +ALIGN_RE_T(vtkm::UInt8); +ALIGN_RE_T(vtkm::Int16); +ALIGN_RE_T(vtkm::UInt16); +ALIGN_RE_T(vtkm::Int32); +ALIGN_RE_T(vtkm::UInt32); +ALIGN_RE_T(vtkm::Int64); +ALIGN_RE_T(vtkm::UInt64); +ALIGN_RE_T(vtkm::Float32); +ALIGN_RE_T(vtkm::Float64); +#endif + +ALIGN_RE_VEC(vtkm::UInt8, 3); +ALIGN_RE_VEC(vtkm::Int32, 3); +ALIGN_RE_VEC(vtkm::Int64, 3); +ALIGN_RE_VEC(vtkm::Float32, 3); +ALIGN_RE_VEC(vtkm::Float64, 3); + +ALIGN_RE_VEC(vtkm::UInt8, 4); +ALIGN_RE_VEC(vtkm::Float32, 4); +ALIGN_RE_VEC(vtkm::Float64, 4); + +ALIGN_RE_PAIR(vtkm::Int32, vtkm::Float32); +ALIGN_RE_PAIR(vtkm::Int32, vtkm::Float64); +ALIGN_RE_PAIR(vtkm::Int64, vtkm::Float32); +ALIGN_RE_PAIR(vtkm::Int64, vtkm::Float64); + +#undef ALIGN_RE_T +#undef ALIGN_RE_VEC +#undef ALIGN_RE_PAIR +} +} + #endif //vtk_m_exec_cuda_internal_ThrustPatches_h