From: Daniel Arndt Date: Wed, 1 Feb 2023 22:02:19 +0000 (-0500) Subject: Avoid __CUDA_ARCH__ in source code X-Git-Tag: v9.5.0-rc1~584^2~4 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9159365987a1d9ce74b27d89785c85b098471b10;p=dealii.git Avoid __CUDA_ARCH__ in source code --- diff --git a/include/deal.II/base/exceptions.h b/include/deal.II/base/exceptions.h index b0648add4a..c0ab82d72c 100644 --- a/include/deal.II/base/exceptions.h +++ b/include/deal.II/base/exceptions.h @@ -28,6 +28,7 @@ # include #endif +#include DEAL_II_NAMESPACE_OPEN @@ -1505,39 +1506,91 @@ namespace deal_II_exceptions * @ingroup Exceptions */ #ifdef DEBUG -# ifdef DEAL_II_HAVE_BUILTIN_EXPECT -# define Assert(cond, exc) \ - { \ - if (__builtin_expect(!(cond), false)) \ - ::dealii::deal_II_exceptions::internals::issue_error_noreturn( \ - ::dealii::deal_II_exceptions::internals::ExceptionHandling:: \ - abort_or_throw_on_exception, \ - __FILE__, \ - __LINE__, \ - __PRETTY_FUNCTION__, \ - #cond, \ - #exc, \ - exc); \ - } -# else /*ifdef DEAL_II_HAVE_BUILTIN_EXPECT*/ -# define Assert(cond, exc) \ - { \ - if (!(cond)) \ - ::dealii::deal_II_exceptions::internals::issue_error_noreturn( \ - ::dealii::deal_II_exceptions::internals::ExceptionHandling:: \ - abort_or_throw_on_exception, \ - __FILE__, \ - __LINE__, \ - __PRETTY_FUNCTION__, \ - #cond, \ - #exc, \ - exc); \ - } -# endif /*ifdef DEAL_II_HAVE_BUILTIN_EXPECT*/ -#else +# ifdef KOKKOS_VERSION >= 30600 +# ifdef DEAL_II_HAVE_BUILTIN_EXPECT +# define Assert(cond, exc) \ + { \ + KOKKOS_IF_ON_HOST(({ \ + if (__builtin_expect(!(cond), false)) \ + ::dealii::deal_II_exceptions::internals::issue_error_noreturn( \ + ::dealii::deal_II_exceptions::internals::ExceptionHandling:: \ + abort_or_throw_on_exception, \ + __FILE__, \ + __LINE__, \ + __PRETTY_FUNCTION__, \ + #cond, \ + #exc, \ + exc); \ + })) \ + KOKKOS_IF_ON_DEVICE(({ \ + if (!(cond)) \ + Kokkos::abort(#cond); \ + })) \ + } +# else /*ifdef DEAL_II_HAVE_BUILTIN_EXPECT*/ +# define Assert(cond, exc) \ + { \ + KOKKOS_IF_ON_HOST(({ \ + if (!(cond)) \ + ::dealii::deal_II_exceptions::internals::issue_error_noreturn( \ + ::dealii::deal_II_exceptions::internals::ExceptionHandling:: \ + abort_or_throw_on_exception, \ + __FILE__, \ + __LINE__, \ + __PRETTY_FUNCTION__, \ + #cond, \ + #exc, \ + exc); \ + })) \ + KOKKOS_IF_ON_DEVICE(({ \ + if (!(cond)) \ + Kokkos::abort(#cond); \ + })) \ + } +# endif /*ifdef DEAL_II_HAVE_BUILTIN_EXPECT*/ +# else /*ifdef KOKKOS_VERSION >= 30600*/ +# ifdef KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST +# ifdef DEAL_II_HAVE_BUILTIN_EXPECT +# define Assert(cond, exc) \ + { \ + if (__builtin_expect(!(cond), false)) \ + ::dealii::deal_II_exceptions::internals::issue_error_noreturn( \ + ::dealii::deal_II_exceptions::internals::ExceptionHandling:: \ + abort_or_throw_on_exception, \ + __FILE__, \ + __LINE__, \ + __PRETTY_FUNCTION__, \ + #cond, \ + #exc, \ + exc); \ + } +# else /*ifdef DEAL_II_HAVE_BUILTIN_EXPECT*/ +# define Assert(cond, exc) \ + { \ + if (!(cond)) \ + ::dealii::deal_II_exceptions::internals::issue_error_noreturn( \ + ::dealii::deal_II_exceptions::internals::ExceptionHandling:: \ + abort_or_throw_on_exception, \ + __FILE__, \ + __LINE__, \ + __PRETTY_FUNCTION__, \ + #cond, \ + #exc, \ + exc); \ + } +# endif /*ifdef DEAL_II_HAVE_BUILTIN_EXPECT*/ +# else /*#ifdef KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST*/ +# define Assert(cond, exc) \ + { \ + if (!(cond)) \ + Kokkos::abort(#cond); \ + } +# endif /*ifdef KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST*/ +# endif /*KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST*/ +#else /*ifdef DEBUG*/ # define Assert(cond, exc) \ {} -#endif +#endif /*ifdef DEBUG*/ diff --git a/include/deal.II/base/point.h b/include/deal.II/base/point.h index ce28ad3c41..858428fce6 100644 --- a/include/deal.II/base/point.h +++ b/include/deal.II/base/point.h @@ -363,14 +363,12 @@ template inline DEAL_II_HOST_DEVICE Point::Point(const Number x) { -# ifndef __CUDA_ARCH__ Assert(dim == 1, ExcMessage( "You can only initialize Point<1> objects using the constructor " "that takes only one argument. Point objects with dim!=1 " "require initialization with the constructor that takes 'dim' " "arguments.")); -# endif // we can only get here if we pass the assertion. use the switch anyway so // as to avoid compiler warnings about uninitialized elements or writing @@ -391,14 +389,12 @@ template inline DEAL_II_HOST_DEVICE Point::Point(const Number x, const Number y) { -# ifndef __CUDA_ARCH__ Assert(dim == 2, ExcMessage( "You can only initialize Point<2> objects using the constructor " "that takes two arguments. Point objects with dim!=2 " "require initialization with the constructor that takes 'dim' " "arguments.")); -# endif // we can only get here if we pass the assertion. use the indirection anyway // so as to avoid compiler warnings about uninitialized elements or writing @@ -414,14 +410,12 @@ template inline DEAL_II_HOST_DEVICE Point::Point(const Number x, const Number y, const Number z) { -# ifndef __CUDA_ARCH__ Assert(dim == 3, ExcMessage( "You can only initialize Point<3> objects using the constructor " "that takes three arguments. Point objects with dim!=3 " "require initialization with the constructor that takes 'dim' " "arguments.")); -# endif // we can only get here if we pass the assertion. use the indirection anyway // so as to avoid compiler warnings about uninitialized elements or writing @@ -470,9 +464,7 @@ template inline DEAL_II_HOST_DEVICE Number Point::operator()(const unsigned int index) const { -# ifndef __CUDA_ARCH__ AssertIndexRange(static_cast(index), dim); -# endif return this->values[index]; } @@ -482,9 +474,7 @@ template inline DEAL_II_HOST_DEVICE Number & Point::operator()(const unsigned int index) { -# ifndef __CUDA_ARCH__ AssertIndexRange(static_cast(index), dim); -# endif return this->values[index]; } diff --git a/include/deal.II/base/tensor.h b/include/deal.II/base/tensor.h index 55db04f176..4bc8797b08 100644 --- a/include/deal.II/base/tensor.h +++ b/include/deal.II/base/tensor.h @@ -1039,11 +1039,8 @@ template constexpr DEAL_II_HOST_DEVICE_ALWAYS_INLINE Tensor<0, dim, Number>::operator Number &() { - // We cannot use Assert inside a CUDA kernel -# ifndef __CUDA_ARCH__ Assert(dim != 0, ExcMessage("Cannot access an object of type Tensor<0,0,Number>")); -# endif return value; } @@ -1052,11 +1049,8 @@ template constexpr inline DEAL_II_ALWAYS_INLINE DEAL_II_HOST_DEVICE Tensor<0, dim, Number>::operator const Number &() const { - // We cannot use Assert inside a CUDA kernel -# ifndef __CUDA_ARCH__ Assert(dim != 0, ExcMessage("Cannot access an object of type Tensor<0,0,Number>")); -# endif return value; } @@ -1162,15 +1156,29 @@ namespace internal val *= s; } -# ifdef __CUDA_ARCH__ template constexpr DEAL_II_HOST_DEVICE_ALWAYS_INLINE void - multiply_assign_scalar(std::complex &, const OtherNumber &) + multiply_assign_scalar(std::complex &val, const OtherNumber &s) { - printf("This function is not implemented for std::complex!\n"); - assert(false); - } +# ifdef KOKKOS_VERSION >= 30600 + KOKKOS_IF_ON_HOST((val *= s;)) + KOKKOS_IF_ON_DEVICE(({ + (void)val; + (void)s; + Kokkos::abort( + "This function is not implemented for std::complex!\n"); + })) +# else +# ifdef KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST + val *= s; +# else + (void)val; + (void)s; + Kokkos::abort( + "This function is not implemented for std::complex!\n"); +# endif # endif + } } // namespace ComplexWorkaround } // namespace internal @@ -1219,11 +1227,8 @@ constexpr DEAL_II_HOST_DEVICE inline DEAL_II_ALWAYS_INLINE typename Tensor<0, dim, Number>::real_type Tensor<0, dim, Number>::norm_square() const { - // We cannot use Assert inside a CUDA kernel -# ifndef __CUDA_ARCH__ Assert(dim != 0, ExcMessage("Cannot access an object of type Tensor<0,0,Number>")); -# endif return numbers::NumberTraits::abs_square(value); } @@ -1321,10 +1326,7 @@ constexpr DEAL_II_HOST_DEVICE_ALWAYS_INLINE Tensor::Tensor( const ArrayView &initializer) { - // We cannot use Assert in a CUDA kernel -# ifndef __CUDA_ARCH__ AssertDimension(initializer.size(), n_independent_components); -# endif for (unsigned int i = 0; i < n_independent_components; ++i) (*this)[unrolled_to_component_indices(i)] = initializer[i]; @@ -1391,10 +1393,7 @@ namespace internal const unsigned int i, std::integral_constant) { - // We cannot use Assert in a CUDA kernel -# ifndef __CUDA_ARCH__ AssertIndexRange(i, dim); -# endif return values[i]; } @@ -1404,13 +1403,10 @@ namespace internal const unsigned int, std::integral_constant) { - // We cannot use Assert in a CUDA kernel -# ifndef __CUDA_ARCH__ Assert( false, ExcMessage( "Cannot access elements of an object of type Tensor.")); -# endif return *dummy; } } // namespace TensorSubscriptor