49 #ifndef __INTREPID2_UTILS_HPP__ 50 #define __INTREPID2_UTILS_HPP__ 52 #include "Intrepid2_ConfigDefs.hpp" 56 #include "Kokkos_Core.hpp" 57 #include "Kokkos_Macros.hpp" 58 #include "Kokkos_Random.hpp" 60 #ifdef HAVE_INTREPID2_SACADO 61 #include "Kokkos_LayoutNatural.hpp" 66 #if defined(KOKKOS_OPT_RANGE_AGGRESSIVE_VECTORIZATION) && defined(KOKKOS_ENABLE_PRAGMA_IVDEP) && !defined(__CUDA_ARCH__) 67 #define INTREPID2_USE_IVDEP 74 #define INTREPID2_TEST_FOR_WARNING(test, msg) \ 76 printf("[Intrepid2] Warning in file %s, line %d\n",__FILE__,__LINE__); \ 77 printf(" Test that evaluated to true: %s\n", #test); \ 78 printf(" %s \n", msg); \ 81 #define INTREPID2_TEST_FOR_EXCEPTION(test, x, msg) \ 83 printf("[Intrepid2] Error in file %s, line %d\n",__FILE__,__LINE__); \ 84 printf(" Test that evaluated to true: %s\n", #test); \ 85 printf(" %s \n", msg); \ 89 #ifndef KOKKOS_ENABLE_CUDA 90 #define INTREPID2_TEST_FOR_EXCEPTION_DEVICE_SAFE(test, x, msg) \ 92 std::cout << "[Intrepid2] Error in file " << __FILE__ << ", line " << __LINE__ << "\n"; \ 93 std::cout << " Test that evaluated to true: " << #test << "\n"; \ 94 std::cout << " " << msg << " \n"; \ 98 #define INTREPID2_TEST_FOR_EXCEPTION_DEVICE_SAFE(test, x, msg) device_assert(!(test)); 101 #define INTREPID2_TEST_FOR_ABORT(test, msg) \ 103 printf("[Intrepid2] Error in file %s, line %d\n",__FILE__,__LINE__); \ 104 printf(" Test that evaluated to true: %s\n", #test); \ 105 printf(" %s \n", msg); \ 106 Kokkos::abort( "[Intrepid2] Abort\n"); \ 109 #ifndef KOKKOS_ENABLE_CUDA 110 #define INTREPID2_TEST_FOR_ABORT_DEVICE_SAFE(test, msg) \ 112 printf("[Intrepid2] Error in file %s, line %d\n",__FILE__,__LINE__); \ 113 printf(" Test that evaluated to true: %s\n", #test); \ 114 printf(" %s \n", msg); \ 115 Kokkos::abort( "[Intrepid2] Abort\n"); \ 118 #define INTREPID2_TEST_FOR_ABORT_DEVICE_SAFE(test, msg) device_assert(!(test)); 123 #ifdef INTREPID2_TEST_FOR_DEBUG_ABORT_OVERRIDE_TO_CONTINUE 124 #define INTREPID2_TEST_FOR_DEBUG_ABORT(test, info, msg) \ 125 if (!(info) && (test)) { \ 126 printf("[Intrepid2] Error in file %s, line %d\n",__FILE__,__LINE__); \ 127 printf(" Test that evaluated to true: %s\n", #test); \ 128 printf(" %s \n", msg); \ 132 #define INTREPID2_TEST_FOR_DEBUG_ABORT(test, info, msg) \ 133 if (!(info) && (test)) { \ 134 printf("[Intrepid2] Error in file %s, line %d\n",__FILE__,__LINE__); \ 135 printf(" Test that evaluated to true: %s\n", #test); \ 136 printf(" %s \n", msg); \ 138 Kokkos::abort( "[Intrepid2] Abort\n"); \ 147 typedef typename T::scalar_type scalar_type;
156 typedef float scalar_type;
163 typedef double scalar_type;
170 typedef int scalar_type;
177 typedef long int scalar_type;
184 typedef long long scalar_type;
192 template<
typename ViewSpaceType,
typename UserSpaceType>
194 typedef UserSpaceType ExecSpaceType;
200 template<
typename ViewSpaceType>
202 typedef ViewSpaceType ExecSpaceType;
209 template <
typename ViewType>
211 using input_layout =
typename ViewType::array_layout;
212 using default_layout =
typename ViewType::device_type::execution_space::array_layout;
213 using result_layout =
214 typename std::conditional<
215 std::is_same< input_layout, Kokkos::LayoutStride >::value,
217 input_layout >::type;
226 template<
typename IdxType,
typename DimType,
typename IterType>
227 KOKKOS_FORCEINLINE_FUNCTION
229 unrollIndex(IdxType &i, IdxType &j,
232 const IterType iter) {
242 template<
typename IdxType,
typename DimType,
typename IterType>
243 KOKKOS_FORCEINLINE_FUNCTION
245 unrollIndex(IdxType &i, IdxType &j, IdxType &k,
249 const IterType iter) {
255 unrollIndex( i, tmp, dim0, dim1*dim2, iter);
256 unrollIndex( j, k, dim1, dim2, tmp);
265 KOKKOS_FORCEINLINE_FUNCTION
266 static T min(
const T a,
const T b) {
267 return (a < b ? a : b);
270 KOKKOS_FORCEINLINE_FUNCTION
271 static T max(
const T a,
const T b) {
272 return (a > b ? a : b);
275 KOKKOS_FORCEINLINE_FUNCTION
276 static T abs(
const T a) {
277 return (a > 0 ? a : T(-a));
283 KOKKOS_FORCEINLINE_FUNCTION
284 static T min(
const T &a,
const T &b) {
285 return (a < b ? a : b);
289 KOKKOS_FORCEINLINE_FUNCTION
290 static T max(
const T &a,
const T &b) {
291 return (a > b ? a : b);
295 KOKKOS_FORCEINLINE_FUNCTION
296 static T abs(
const T &a) {
297 return (a > 0 ? a : T(-a));
308 KOKKOS_FORCEINLINE_FUNCTION
310 std::enable_if< !std::is_pod<T>::value,
typename ScalarTraits<T>::scalar_type >::type
314 KOKKOS_FORCEINLINE_FUNCTION
316 std::enable_if< std::is_pod<T>::value,
typename ScalarTraits<T>::scalar_type >::type
317 get_scalar_value(
const T& obj){
return obj;}
326 template<
typename T,
typename ...P>
327 KOKKOS_INLINE_FUNCTION
329 std::enable_if< std::is_pod<T>::value,
unsigned >::type
332 template<
typename T,
typename ...P>
333 KOKKOS_INLINE_FUNCTION
335 std::enable_if< std::is_pod<
typename Kokkos::View<T, P...>::value_type >::value,
unsigned >::type
336 dimension_scalar(
const Kokkos::View<T, P...> ) {
return 1;}
338 template<
typename T,
typename ...P>
339 KOKKOS_FORCEINLINE_FUNCTION
340 static ordinal_type get_dimension_scalar(
const Kokkos::DynRankView<T, P...> &view) {
344 template<
typename T,
typename ...P>
345 KOKKOS_FORCEINLINE_FUNCTION
346 static ordinal_type get_dimension_scalar(
const Kokkos::View<T, P...> &view) {
358 template<
class ViewType,
class ... DimArgs>
360 Kokkos::DynRankView<typename ViewType::value_type, typename DeduceLayout< ViewType >::result_layout,
typename ViewType::device_type >
363 using ValueType =
typename ViewType::value_type;
364 using ResultLayout =
typename DeduceLayout< ViewType >::result_layout;
365 using DeviceType =
typename ViewType::device_type;
366 using ViewTypeWithLayout = Kokkos::DynRankView<ValueType, ResultLayout, DeviceType >;
368 const bool allocateFadStorage = !std::is_pod<ValueType>::value;
369 if (!allocateFadStorage)
371 return ViewTypeWithLayout(label,dims...);
375 const int derivative_dimension = get_dimension_scalar(view);
376 return ViewTypeWithLayout(label,dims...,derivative_dimension);
383 template <
typename T>
387 struct two {
char x[2]; };
389 template <
typename C>
static one test(
typename std::remove_reference<decltype( std::declval<C>().
operator()(0))>::type );
390 template <
typename C>
static two test(...);
393 enum { value =
sizeof(test<T>(0)) ==
sizeof(char) };
399 template <
typename T>
403 struct two {
char x[2]; };
405 template <
typename C>
static one test(
typename std::remove_reference<decltype( std::declval<C>().
operator()(0,0))>::type ) ;
406 template <
typename C>
static two test(...);
409 enum { value =
sizeof(test<T>(0)) ==
sizeof(char) };
415 template <
typename T>
419 struct two {
char x[2]; };
421 template <
typename C>
static one test(
typename std::remove_reference<decltype( std::declval<C>().
operator()(0,0,0))>::type ) ;
422 template <
typename C>
static two test(...);
425 enum { value =
sizeof(test<T>(0)) ==
sizeof(char) };
431 template <
typename T>
435 struct two {
char x[2]; };
437 template <
typename C>
static one test(
typename std::remove_reference<decltype( std::declval<C>().
operator()(0,0,0,0))>::type ) ;
438 template <
typename C>
static two test(...);
441 enum { value =
sizeof(test<T>(0)) ==
sizeof(char) };
447 template <
typename T>
451 struct two {
char x[2]; };
453 template <
typename C>
static one test(
typename std::remove_reference<decltype( std::declval<C>().
operator()(0,0,0,0,0))>::type ) ;
454 template <
typename C>
static two test(...);
457 enum { value =
sizeof(test<T>(0)) ==
sizeof(char) };
463 template <
typename T>
467 struct two {
char x[2]; };
469 template <
typename C>
static one test(
typename std::remove_reference<decltype( std::declval<C>().
operator()(0,0,0,0,0,0))>::type ) ;
470 template <
typename C>
static two test(...);
473 enum { value =
sizeof(test<T>(0)) ==
sizeof(char) };
479 template <
typename T>
483 struct two {
char x[2]; };
485 template <
typename C>
static one test(
typename std::remove_reference<decltype( std::declval<C>().
operator()(0,0,0,0,0,0,0))>::type ) ;
486 template <
typename C>
static two test(...);
489 enum { value =
sizeof(test<T>(0)) ==
sizeof(char) };
495 template <
typename T,
int rank>
499 enum { value =
false };
505 template <
typename T>
513 template <
typename T>
521 template <
typename T>
529 template <
typename T>
537 template <
typename T>
545 template <
typename T>
553 template <
typename T>
565 template<
typename Scalar,
int rank>
573 template<
typename Scalar>
576 using value_type = Scalar;
582 template<
typename Scalar>
585 using value_type = Scalar*;
591 template<
typename Scalar>
594 using value_type = Scalar**;
600 template<
typename Scalar>
603 using value_type = Scalar***;
609 template<
typename Scalar>
612 using value_type = Scalar****;
618 template<
typename Scalar>
621 using value_type = Scalar*****;
627 template<
typename Scalar>
630 using value_type = Scalar******;
636 template<
typename Scalar>
639 using value_type = Scalar*******;
657 template <
typename T>
661 struct two {
char x[2]; };
663 template <
typename C>
static one test( decltype( std::declval<C>().rank() ) ) ;
664 template <
typename C>
static two test(...);
667 enum { value =
sizeof(test<T>(0)) ==
sizeof(char) };
670 static_assert( has_rank_method<Kokkos::DynRankView<double> >::value,
"DynRankView implements rank(), so this assert should pass -- if not, something may be wrong with has_rank_method.");
671 static_assert(! has_rank_method<Kokkos::View<double> >::value,
"View does not implement rank() -- if this assert fails, something may be wrong with has_rank_method.");
673 template<
bool B,
class T >
674 using enable_if_t =
typename std::enable_if<B,T>::type;
679 template<
class Functor>
680 enable_if_t<has_rank_method<Functor>::value,
unsigned>
681 KOKKOS_INLINE_FUNCTION
684 return functor.rank();
690 template<
class Functor>
691 enable_if_t<!has_rank_method<Functor>::value,
unsigned>
692 KOKKOS_INLINE_FUNCTION
701 #ifdef HAVE_INTREPID2_SACADO 702 template <
typename ValueType>
703 struct NaturalLayoutForType {
705 typename std::conditional<std::is_pod<ValueType>::value,
707 Kokkos::LayoutNatural<Kokkos::LayoutLeft> >::type;
710 template <
typename ValueType>
712 using layout = Kokkos::LayoutLeft;
717 const int VECTOR_SIZE = 1;
718 #if defined(SACADO_VIEW_CUDA_HIERARCHICAL_DFAD) && defined(KOKKOS_ENABLE_CUDA) 719 const int FAD_VECTOR_SIZE = 32;
721 const int FAD_VECTOR_SIZE = 1;
727 template<
typename Scalar>
730 return std::is_pod<Scalar>::value ? VECTOR_SIZE : FAD_VECTOR_SIZE;
738 template<
typename ViewType>
739 KOKKOS_INLINE_FUNCTION
742 return (std::is_pod<typename ViewType::value_type>::value) ? 0 : get_dimension_scalar(view);
SFINAE helper to detect whether a type supports a 5-integral-argument operator(). ...
constexpr int getVectorSizeForHierarchicalParallelism()
Returns a vector size to be used for the provided Scalar type in the context of hierarchically-parall...
SFINAE helper to detect whether a type supports a 1-integral-argument operator(). ...
SFINAE helper to detect whether a type supports a 6-integral-argument operator(). ...
SFINAE helper to detect whether a type supports a 7-integral-argument operator(). ...
SFINAE helper to detect whether a type supports a rank-integral-argument operator().
SFINAE helper to detect whether a type supports a 2-integral-argument operator(). ...
Implementation of an assert that can safely be called from device code.
Helper to get Scalar[*+] where the number of *'s matches the given rank.
SFINAE helper to detect whether a type supports a 3-integral-argument operator(). ...
KOKKOS_INLINE_FUNCTION constexpr std::enable_if< std::is_pod< T >::value, unsigned >::type dimension_scalar(const Kokkos::DynRankView< T, P... >)
specialization of functions for pod types, returning the scalar dimension (1 for pod types) of a view...
Tests whether a class implements rank(). Used in getFunctorRank() method below; allows us to do one t...
KOKKOS_INLINE_FUNCTION constexpr unsigned getScalarDimensionForView(const ViewType &view)
Returns the size of the Scalar dimension for the View. This is 0 for non-AD types. This method is useful for sizing scratch storage in hierarchically parallel kernels. Whereas get_dimension_scalar() returns 1 for POD types, this returns 0 for POD types.
Contains definitions of custom data types in Intrepid2.
Define layout that will allow us to wrap Sacado Scalar objects in Views without copying.
SFINAE helper to detect whether a type supports a 4-integral-argument operator(). ...
Kokkos::DynRankView< typename ViewType::value_type, typename DeduceLayout< ViewType >::result_layout, typename ViewType::device_type > getMatchingViewWithLabel(const ViewType &view, const std::string &label, DimArgs... dims)
Creates and returns a view that matches the provided view in Kokkos Layout.
KOKKOS_FORCEINLINE_FUNCTION constexpr std::enable_if< !std::is_pod< T >::value, typename ScalarTraits< T >::scalar_type >::type get_scalar_value(const T &obj)
functions returning the scalar value. for pod types, they return the input object itself...
layout deduction (temporary meta-function)
enable_if_t< has_rank_method< Functor >::value, unsigned > KOKKOS_INLINE_FUNCTION getFunctorRank(const Functor &functor)