Intrepid2
Intrepid2_Utils.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ************************************************************************
3 //
4 // Intrepid2 Package
5 // Copyright (2007) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Kyungjoo Kim (kyukim@sandia.gov), or
38 // Mauro Perego (mperego@sandia.gov)
39 //
40 // ************************************************************************
41 // @HEADER
42 
49 #ifndef __INTREPID2_UTILS_HPP__
50 #define __INTREPID2_UTILS_HPP__
51 
52 #include "Intrepid2_ConfigDefs.hpp"
54 #include "Intrepid2_Types.hpp"
55 
56 #include "Kokkos_Core.hpp"
57 #include "Kokkos_Macros.hpp" // provides some preprocessor values used in definitions of INTREPID2_DEPRECATED, etc.
58 #include "Kokkos_Random.hpp"
59 
60 #ifdef HAVE_INTREPID2_SACADO
61 #include "Kokkos_LayoutNatural.hpp"
62 #endif
63 
64 namespace Intrepid2 {
65 
66 #if defined(__CUDA_ARCH__) || defined(__HIP_DEVICE_COMPILE__) || defined(__SYCL_DEVICE_ONLY__)
67 #define INTREPID2_COMPILE_DEVICE_CODE
68 #endif
69 
70 #if defined(KOKKOS_ENABLE_CUDA) || defined(KOKKOS_ENABLE_HIP) || defined(KOKKOS_ENABLE_SYCL)
71 #define INTREPID2_ENABLE_DEVICE
72 #endif
73 
74 #if defined(KOKKOS_OPT_RANGE_AGGRESSIVE_VECTORIZATION) \
75  && defined(KOKKOS_ENABLE_PRAGMA_IVDEP) \
76  && !defined(INTREPID2_COMPILE_DEVICE_CODE)
77 #define INTREPID2_USE_IVDEP
78 #endif
79 
80  //
81  // test macros
82  //
83 
84 #define INTREPID2_TEST_FOR_WARNING(test, msg) \
85  if (test) { \
86  Kokkos::printf("[Intrepid2] Warning in file %s, line %d\n",__FILE__,__LINE__); \
87  Kokkos::printf(" Test that evaluated to true: %s\n", #test); \
88  Kokkos::printf(" %s \n", msg); \
89  }
90 
91 #define INTREPID2_TEST_FOR_EXCEPTION(test, x, msg) \
92  if (test) { \
93  Kokkos::printf("[Intrepid2] Error in file %s, line %d\n",__FILE__,__LINE__); \
94  Kokkos::printf(" Test that evaluated to true: %s\n", #test); \
95  Kokkos::printf(" %s \n", msg); \
96  throw x(msg); \
97  }
98 
101 #ifndef INTREPID2_ENABLE_DEVICE
102 #define INTREPID2_TEST_FOR_EXCEPTION_DEVICE_SAFE(test, x, msg) \
103  if (test) { \
104  std::cout << "[Intrepid2] Error in file " << __FILE__ << ", line " << __LINE__ << "\n"; \
105  std::cout << " Test that evaluated to true: " << #test << "\n"; \
106  std::cout << " " << msg << " \n"; \
107  throw x(msg); \
108  }
109 #else
110 #define INTREPID2_TEST_FOR_EXCEPTION_DEVICE_SAFE(test, x, msg) \
111  if (test) { \
112  Kokkos::printf("[Intrepid2] Error in file %s, line %d\n",__FILE__,__LINE__); \
113  Kokkos::printf(" Test that evaluated to true: %s\n", #test); \
114  Kokkos::printf(" %s \n", msg); \
115  Kokkos::abort( "[Intrepid2] Abort\n"); \
116  }
117 #endif
118 #if defined(INTREPID2_ENABLE_DEBUG) || defined(NDEBUG) || 1
119 #define INTREPID2_TEST_FOR_ABORT(test, msg) \
120  if (test) { \
121  Kokkos::printf("[Intrepid2] Error in file %s, line %d\n",__FILE__,__LINE__); \
122  Kokkos::printf(" Test that evaluated to true: %s\n", #test); \
123  Kokkos::printf(" %s \n", msg); \
124  Kokkos::abort( "[Intrepid2] Abort\n"); \
125  }
126 #else
127 #define INTREPID2_TEST_FOR_ABORT(test, msg) ((void)0)
128 #endif
129  // check the first error only
130 #ifdef INTREPID2_TEST_FOR_DEBUG_ABORT_OVERRIDE_TO_CONTINUE
131 #define INTREPID2_TEST_FOR_DEBUG_ABORT(test, info, msg) \
132  if (!(info) && (test)) { \
133  Kokkos::printf("[Intrepid2] Error in file %s, line %d\n",__FILE__,__LINE__); \
134  Kokkos::printf(" Test that evaluated to true: %s\n", #test); \
135  Kokkos::printf(" %s \n", msg); \
136  info = true; \
137  }
138 #else
139 #define INTREPID2_TEST_FOR_DEBUG_ABORT(test, info, msg) \
140  if (!(info) && (test)) { \
141  Kokkos::printf("[Intrepid2] Error in file %s, line %d\n",__FILE__,__LINE__); \
142  Kokkos::printf(" Test that evaluated to true: %s\n", #test); \
143  Kokkos::printf(" %s \n", msg); \
144  info = true ; \
145  Kokkos::abort( "[Intrepid2] Abort\n"); \
146  }
147 #endif
148 
152  template<typename T>
153  struct ScalarTraits {
154  typedef typename T::scalar_type scalar_type;
155  };
156 
157  // this is built in types to support
161  template<>
162  struct ScalarTraits<float> {
163  typedef float scalar_type;
164  };
168  template<>
169  struct ScalarTraits<double> {
170  typedef double scalar_type;
171  };
175  template<>
176  struct ScalarTraits<int> {
177  typedef int scalar_type;
178  };
182  template<>
183  struct ScalarTraits<long int> {
184  typedef long int scalar_type;
185  };
189  template<>
190  struct ScalarTraits<long long> {
191  typedef long long scalar_type;
192  };
193 
194 
195 
199  template<typename ViewSpaceType, typename UserSpaceType>
200  struct ExecSpace {
201  typedef UserSpaceType ExecSpaceType;
202  };
203 
207  template<typename ViewSpaceType>
208  struct ExecSpace<ViewSpaceType,void> {
209  typedef ViewSpaceType ExecSpaceType;
210  };
211 
212 
216  template <typename ViewType>
217  struct DeduceLayout {
218  using input_layout = typename ViewType::array_layout;
219  using default_layout = typename ViewType::device_type::execution_space::array_layout;
220  using result_layout =
221  typename std::conditional<
222  std::is_same< input_layout, Kokkos::LayoutStride >::value,
223  default_layout,
224  input_layout >::type;
225  };
226 
227 
228  //
229  // utilities device comparible
230  //
231 
232  // this will be gone
233  template<typename IdxType, typename DimType, typename IterType>
234  KOKKOS_FORCEINLINE_FUNCTION
235  static void
236  unrollIndex(IdxType &i, IdxType &j,
237  const DimType /* dim0 */,
238  const DimType dim1,
239  const IterType iter) {
240  // left index
241  //j = iter/dim0;
242  //i = iter%dim0;
243 
244  // right index
245  i = iter/dim1;
246  j = iter%dim1;
247  }
248 
249  template<typename IdxType, typename DimType, typename IterType>
250  KOKKOS_FORCEINLINE_FUNCTION
251  static void
252  unrollIndex(IdxType &i, IdxType &j, IdxType &k,
253  const DimType dim0,
254  const DimType dim1,
255  const DimType dim2,
256  const IterType iter) {
257  IdxType tmp;
258 
259  //unrollIndex(tmp, k, dim0*dim1, dim2, iter);
260  //unrollIndex( i, j, dim0, dim1, tmp);
261 
262  unrollIndex( i, tmp, dim0, dim1*dim2, iter);
263  unrollIndex( j, k, dim1, dim2, tmp);
264  }
265 
269  template<typename T>
270  class Util {
271  public:
272  KOKKOS_FORCEINLINE_FUNCTION
273  static T min(const T a, const T b) {
274  return (a < b ? a : b);
275  }
276 
277  KOKKOS_FORCEINLINE_FUNCTION
278  static T max(const T a, const T b) {
279  return (a > b ? a : b);
280  }
281 
282  KOKKOS_FORCEINLINE_FUNCTION
283  static T abs(const T a) {
284  return (a > 0 ? a : T(-a));
285  }
286 
287  };
288 
289  template<typename T>
290  KOKKOS_FORCEINLINE_FUNCTION
291  static T min(const T &a, const T &b) {
292  return (a < b ? a : b);
293  }
294 
295  template<typename T>
296  KOKKOS_FORCEINLINE_FUNCTION
297  static T max(const T &a, const T &b) {
298  return (a > b ? a : b);
299  }
300 
301  template<typename T>
302  KOKKOS_FORCEINLINE_FUNCTION
303  static T abs(const T &a) {
304  return (a > 0 ? a : T(-a));
305  }
306 
314  template<typename T>
315  KOKKOS_FORCEINLINE_FUNCTION
316  constexpr typename
317  std::enable_if< !std::is_pod<T>::value, typename ScalarTraits<T>::scalar_type >::type
318  get_scalar_value(const T& obj) {return obj.val();}
319 
320  template<typename T>
321  KOKKOS_FORCEINLINE_FUNCTION
322  constexpr typename
323  std::enable_if< std::is_pod<T>::value, typename ScalarTraits<T>::scalar_type >::type
324  get_scalar_value(const T& obj){return obj;}
325 
326 
333  template<typename T, typename ...P>
334  KOKKOS_INLINE_FUNCTION
335  constexpr typename
336  std::enable_if< std::is_pod<T>::value, unsigned >::type
337  dimension_scalar(const Kokkos::DynRankView<T, P...> /* view */) {return 1;}
338 
339  template<typename T, typename ...P>
340  KOKKOS_INLINE_FUNCTION
341  constexpr typename
342  std::enable_if< std::is_pod< typename Kokkos::View<T, P...>::value_type >::value, unsigned >::type
343  dimension_scalar(const Kokkos::View<T, P...> /*view*/) {return 1;}
344 
345  template<typename T, typename ...P>
346  KOKKOS_FORCEINLINE_FUNCTION
347  static ordinal_type get_dimension_scalar(const Kokkos::DynRankView<T, P...> &view) {
348  return dimension_scalar(view);
349  }
350 
351  template<typename T, typename ...P>
352  KOKKOS_FORCEINLINE_FUNCTION
353  static ordinal_type get_dimension_scalar(const Kokkos::View<T, P...> &view) {
354  return dimension_scalar(view);
355  }
356 
365  template<class ViewType, class ... DimArgs>
366  inline
367  Kokkos::DynRankView<typename ViewType::value_type, typename DeduceLayout< ViewType >::result_layout, typename ViewType::device_type >
368  getMatchingViewWithLabel(const ViewType &view, const std::string &label, DimArgs... dims)
369  {
370  using ValueType = typename ViewType::value_type;
371  using ResultLayout = typename DeduceLayout< ViewType >::result_layout;
372  using DeviceType = typename ViewType::device_type;
373  using ViewTypeWithLayout = Kokkos::DynRankView<ValueType, ResultLayout, DeviceType >;
374 
375  const bool allocateFadStorage = !std::is_pod<ValueType>::value;
376  if (!allocateFadStorage)
377  {
378  return ViewTypeWithLayout(label,dims...);
379  }
380  else
381  {
382  const int derivative_dimension = get_dimension_scalar(view);
383  return ViewTypeWithLayout(label,dims...,derivative_dimension);
384  }
385  }
386 
387  using std::enable_if_t;
388 
392  template <typename T, typename = void>
393  struct has_rank_member : std::false_type{};
394 
398  template <typename T>
399  struct has_rank_member<T, decltype((void)T::rank, void())> : std::true_type {};
400 
401  static_assert(! has_rank_member<Kokkos::DynRankView<double> >::value, "DynRankView does not have a member rank, so this assert should pass -- if not, something may be wrong with has_rank_member.");
402 #if KOKKOS_VERSION < 40099
403  static_assert( has_rank_member<Kokkos::View<double*> >::value, "View has a member rank -- if this assert fails, something may be wrong with has_rank_member.");
404 #endif
405 
409  template<class Functor, ordinal_type default_value>
410  constexpr
411  enable_if_t<has_rank_member<Functor>::value, ordinal_type>
412  getFixedRank()
413  {
414  return Functor::rank;
415  }
416 
420  template<class Functor, ordinal_type default_value>
421  constexpr
422  enable_if_t<!has_rank_member<Functor>::value, ordinal_type>
423  getFixedRank()
424  {
425  return default_value;
426  }
427 
431  template <typename T>
433  {
434  typedef char one;
435  struct two { char x[2]; };
436 
437  template <typename C> static one test( typename std::remove_reference<decltype( std::declval<C>().operator()(0))>::type );
438  template <typename C> static two test(...);
439 
440  public:
441  enum { value = sizeof(test<T>(0)) == sizeof(char) && (getFixedRank<T,1>() == 1) };
442  };
443 
447  template <typename T>
449  {
450  typedef char one;
451  struct two { char x[2]; };
452 
453  template <typename C> static one test( typename std::remove_reference<decltype( std::declval<C>().operator()(0,0))>::type ) ;
454  template <typename C> static two test(...);
455 
456  public:
457  enum { value = sizeof(test<T>(0)) == sizeof(char) && (getFixedRank<T,2>() == 2) };
458  };
459 
463  template <typename T>
465  {
466  typedef char one;
467  struct two { char x[2]; };
468 
469  template <typename C> static one test( typename std::remove_reference<decltype( std::declval<C>().operator()(0,0,0))>::type ) ;
470  template <typename C> static two test(...);
471 
472  public:
473  enum { value = (sizeof(test<T>(0)) == sizeof(char)) && (getFixedRank<T,3>() == 3) };
474  };
475 
479  template <typename T>
481  {
482  typedef char one;
483  struct two { char x[2]; };
484 
485  template <typename C> static one test( typename std::remove_reference<decltype( std::declval<C>().operator()(0,0,0,0))>::type ) ;
486  template <typename C> static two test(...);
487 
488  public:
489  enum { value = sizeof(test<T>(0)) == sizeof(char) && (getFixedRank<T,4>() == 4) };
490  };
491 
495  template <typename T>
497  {
498  typedef char one;
499  struct two { char x[2]; };
500 
501  template <typename C> static one test( typename std::remove_reference<decltype( std::declval<C>().operator()(0,0,0,0,0))>::type ) ;
502  template <typename C> static two test(...);
503 
504  public:
505  enum { value = sizeof(test<T>(0)) == sizeof(char) && (getFixedRank<T,5>() == 5) };
506  };
507 
511  template <typename T>
513  {
514  typedef char one;
515  struct two { char x[2]; };
516 
517  template <typename C> static one test( typename std::remove_reference<decltype( std::declval<C>().operator()(0,0,0,0,0,0))>::type ) ;
518  template <typename C> static two test(...);
519 
520  public:
521  enum { value = sizeof(test<T>(0)) == sizeof(char) && (getFixedRank<T,6>() == 6) };
522  };
523 
527  template <typename T>
529  {
530  typedef char one;
531  struct two { char x[2]; };
532 
533  template <typename C> static one test( typename std::remove_reference<decltype( std::declval<C>().operator()(0,0,0,0,0,0,0))>::type ) ;
534  template <typename C> static two test(...);
535 
536  public:
537  enum { value = sizeof(test<T>(0)) == sizeof(char) && (getFixedRank<T,7>() == 7) };
538  };
539 
543  template <typename T, int rank>
545  {
546  public:
547  enum { value = false };
548  };
549 
553  template <typename T>
554  class supports_rank<T,1>
555  {
556  public:
557  enum { value = supports_rank_1<T>::value };
558  };
559 
561  template <typename T>
562  class supports_rank<T,2>
563  {
564  public:
565  enum { value = supports_rank_2<T>::value };
566  };
567 
569  template <typename T>
570  class supports_rank<T,3>
571  {
572  public:
573  enum { value = supports_rank_3<T>::value };
574  };
575 
577  template <typename T>
578  class supports_rank<T,4>
579  {
580  public:
581  enum { value = supports_rank_4<T>::value };
582  };
583 
585  template <typename T>
586  class supports_rank<T,5>
587  {
588  public:
589  enum { value = supports_rank_5<T>::value };
590  };
591 
593  template <typename T>
594  class supports_rank<T,6>
595  {
596  public:
597  enum { value = supports_rank_6<T>::value };
598  };
599 
601  template <typename T>
602  class supports_rank<T,7>
603  {
604  public:
605  enum { value = supports_rank_7<T>::value };
606  };
607 
608 
609 
613  template<typename Scalar, int rank>
614  struct RankExpander {
615 
616  };
617 
621  template<typename Scalar>
622  struct RankExpander<Scalar,0>
623  {
624  using value_type = Scalar;
625  };
626 
630  template<typename Scalar>
631  struct RankExpander<Scalar,1>
632  {
633  using value_type = Scalar*;
634  };
635 
639  template<typename Scalar>
640  struct RankExpander<Scalar,2>
641  {
642  using value_type = Scalar**;
643  };
644 
648  template<typename Scalar>
649  struct RankExpander<Scalar,3>
650  {
651  using value_type = Scalar***;
652  };
653 
657  template<typename Scalar>
658  struct RankExpander<Scalar,4>
659  {
660  using value_type = Scalar****;
661  };
662 
666  template<typename Scalar>
667  struct RankExpander<Scalar,5>
668  {
669  using value_type = Scalar*****;
670  };
671 
675  template<typename Scalar>
676  struct RankExpander<Scalar,6>
677  {
678  using value_type = Scalar******;
679  };
680 
684  template<typename Scalar>
685  struct RankExpander<Scalar,7>
686  {
687  using value_type = Scalar*******;
688  };
689 
690  // positive checks of supports_rank for Kokkos::DynRankView:
691  static_assert(supports_rank<Kokkos::DynRankView<double>, 1>::value, "rank 1 check of supports_rank for DynRankView");
692  static_assert(supports_rank<Kokkos::DynRankView<double>, 2>::value, "rank 2 check of supports_rank for DynRankView");
693  static_assert(supports_rank<Kokkos::DynRankView<double>, 3>::value, "rank 3 check of supports_rank for DynRankView");
694  static_assert(supports_rank<Kokkos::DynRankView<double>, 4>::value, "rank 4 check of supports_rank for DynRankView");
695  static_assert(supports_rank<Kokkos::DynRankView<double>, 5>::value, "rank 5 check of supports_rank for DynRankView");
696  static_assert(supports_rank<Kokkos::DynRankView<double>, 6>::value, "rank 6 check of supports_rank for DynRankView");
697  static_assert(supports_rank<Kokkos::DynRankView<double>, 7>::value, "rank 7 check of supports_rank for DynRankView");
698 
699  // positive checks of supports_rank for Kokkos::View:
700  static_assert(supports_rank<Kokkos::View<double*>, 1>::value, "rank 1 check of supports_rank");
701  static_assert(supports_rank<Kokkos::View<double**>, 2>::value, "rank 2 check of supports_rank");
702  static_assert(supports_rank<Kokkos::View<double***>, 3>::value, "rank 3 check of supports_rank");
703  static_assert(supports_rank<Kokkos::View<double****>, 4>::value, "rank 4 check of supports_rank");
704  static_assert(supports_rank<Kokkos::View<double*****>, 5>::value, "rank 5 check of supports_rank");
705  static_assert(supports_rank<Kokkos::View<double******>, 6>::value, "rank 6 check of supports_rank");
706  static_assert(supports_rank<Kokkos::View<double*******>, 7>::value, "rank 7 check of supports_rank");
707 
708  // negative checks of supports_rank for Kokkos::View:
709  static_assert(!supports_rank<Kokkos::View<double*>, 2>::value, "rank 1 check of supports_rank");
710  static_assert(!supports_rank<Kokkos::View<double*>, 3>::value, "rank 1 check of supports_rank");
711  static_assert(!supports_rank<Kokkos::View<double*>, 4>::value, "rank 1 check of supports_rank");
712  static_assert(!supports_rank<Kokkos::View<double*>, 5>::value, "rank 1 check of supports_rank");
713  static_assert(!supports_rank<Kokkos::View<double*>, 6>::value, "rank 1 check of supports_rank");
714  static_assert(!supports_rank<Kokkos::View<double*>, 7>::value, "rank 1 check of supports_rank");
715  static_assert(!supports_rank<Kokkos::View<double**>, 1>::value, "rank 2 check of supports_rank");
716  static_assert(!supports_rank<Kokkos::View<double**>, 3>::value, "rank 2 check of supports_rank");
717  static_assert(!supports_rank<Kokkos::View<double**>, 4>::value, "rank 2 check of supports_rank");
718  static_assert(!supports_rank<Kokkos::View<double**>, 5>::value, "rank 2 check of supports_rank");
719  static_assert(!supports_rank<Kokkos::View<double**>, 6>::value, "rank 2 check of supports_rank");
720  static_assert(!supports_rank<Kokkos::View<double**>, 7>::value, "rank 2 check of supports_rank");
721  static_assert(!supports_rank<Kokkos::View<double***>, 1>::value, "rank 3 check of supports_rank");
722  static_assert(!supports_rank<Kokkos::View<double***>, 2>::value, "rank 3 check of supports_rank");
723  static_assert(!supports_rank<Kokkos::View<double***>, 4>::value, "rank 3 check of supports_rank");
724  static_assert(!supports_rank<Kokkos::View<double***>, 5>::value, "rank 3 check of supports_rank");
725  static_assert(!supports_rank<Kokkos::View<double***>, 6>::value, "rank 3 check of supports_rank");
726  static_assert(!supports_rank<Kokkos::View<double***>, 7>::value, "rank 3 check of supports_rank");
727  static_assert(!supports_rank<Kokkos::View<double****>, 1>::value, "rank 4 check of supports_rank");
728  static_assert(!supports_rank<Kokkos::View<double****>, 2>::value, "rank 4 check of supports_rank");
729  static_assert(!supports_rank<Kokkos::View<double****>, 3>::value, "rank 4 check of supports_rank");
730  static_assert(!supports_rank<Kokkos::View<double****>, 5>::value, "rank 4 check of supports_rank");
731  static_assert(!supports_rank<Kokkos::View<double****>, 6>::value, "rank 4 check of supports_rank");
732  static_assert(!supports_rank<Kokkos::View<double****>, 7>::value, "rank 4 check of supports_rank");
733  static_assert(!supports_rank<Kokkos::View<double*****>, 1>::value, "rank 5 check of supports_rank");
734  static_assert(!supports_rank<Kokkos::View<double*****>, 2>::value, "rank 5 check of supports_rank");
735  static_assert(!supports_rank<Kokkos::View<double*****>, 3>::value, "rank 5 check of supports_rank");
736  static_assert(!supports_rank<Kokkos::View<double*****>, 4>::value, "rank 5 check of supports_rank");
737  static_assert(!supports_rank<Kokkos::View<double*****>, 6>::value, "rank 5 check of supports_rank");
738  static_assert(!supports_rank<Kokkos::View<double*****>, 7>::value, "rank 5 check of supports_rank");
739  static_assert(!supports_rank<Kokkos::View<double******>, 1>::value, "rank 6 check of supports_rank");
740  static_assert(!supports_rank<Kokkos::View<double******>, 2>::value, "rank 6 check of supports_rank");
741  static_assert(!supports_rank<Kokkos::View<double******>, 3>::value, "rank 6 check of supports_rank");
742  static_assert(!supports_rank<Kokkos::View<double******>, 4>::value, "rank 6 check of supports_rank");
743  static_assert(!supports_rank<Kokkos::View<double******>, 5>::value, "rank 6 check of supports_rank");
744  static_assert(!supports_rank<Kokkos::View<double******>, 7>::value, "rank 6 check of supports_rank");
745  static_assert(!supports_rank<Kokkos::View<double*******>, 1>::value, "rank 7 check of supports_rank");
746  static_assert(!supports_rank<Kokkos::View<double*******>, 2>::value, "rank 7 check of supports_rank");
747  static_assert(!supports_rank<Kokkos::View<double*******>, 3>::value, "rank 7 check of supports_rank");
748  static_assert(!supports_rank<Kokkos::View<double*******>, 4>::value, "rank 7 check of supports_rank");
749  static_assert(!supports_rank<Kokkos::View<double*******>, 5>::value, "rank 7 check of supports_rank");
750  static_assert(!supports_rank<Kokkos::View<double*******>, 6>::value, "rank 7 check of supports_rank");
751 
755  template <typename T>
757  {
758  typedef char one;
759  struct two { char x[2]; };
760 
761  template <typename C> static one test( decltype( std::declval<C>().rank() ) ) ;
762  template <typename C> static two test(...);
763 
764  public:
765  enum { value = sizeof(test<T>(0)) == sizeof(char) };
766  };
767 
768  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.");
769 #if KOKKOS_VERSION < 40099
770  static_assert( has_rank_member<Kokkos::View<double*> >::value, "View has a member rank -- if this assert fails, something may be wrong with has_rank_member.");
771 #endif
772 
776  template<class Functor>
777  enable_if_t<has_rank_method<Functor>::value, unsigned>
778  KOKKOS_INLINE_FUNCTION
779  getFunctorRank(const Functor &functor)
780  {
781  return functor.rank();
782  }
783 
787  template<class Functor>
788  enable_if_t<!has_rank_method<Functor>::value, unsigned>
789  KOKKOS_INLINE_FUNCTION
790  getFunctorRank(const Functor &functor)
791  {
792  return functor.rank;
793  }
794 
798 #ifdef HAVE_INTREPID2_SACADO
799  template <typename ValueType>
800  struct NaturalLayoutForType {
801  using layout =
802  typename std::conditional<std::is_pod<ValueType>::value,
803  Kokkos::LayoutLeft, // for POD types, use LayoutLeft
804  Kokkos::LayoutNatural<Kokkos::LayoutLeft> >::type; // For FAD types, use LayoutNatural
805  };
806 #else
807  template <typename ValueType>
809  using layout = Kokkos::LayoutLeft;
810  };
811 #endif
812 
813  // define vector sizes for hierarchical parallelism
814  const int VECTOR_SIZE = 1;
815 #if defined(SACADO_VIEW_CUDA_HIERARCHICAL_DFAD) && defined(INTREPID2_ENABLE_DEVICE)
816  const int FAD_VECTOR_SIZE = 32;
817 #else
818  const int FAD_VECTOR_SIZE = 1;
819 #endif
820 
824  template<typename Scalar>
825  constexpr int getVectorSizeForHierarchicalParallelism()
826  {
827  return std::is_pod<Scalar>::value ? VECTOR_SIZE : FAD_VECTOR_SIZE;
828  }
829 
835  template<typename ViewType>
836  KOKKOS_INLINE_FUNCTION
837  constexpr unsigned getScalarDimensionForView(const ViewType &view)
838  {
839  return (std::is_pod<typename ViewType::value_type>::value) ? 0 : get_dimension_scalar(view);
840  }
841 } // end namespace Intrepid2
842 
843 #endif
SFINAE helper to detect whether a type supports a 5-integral-argument operator(). ...
small utility functions
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 *&#39;s matches the given rank.
scalar type traits
SFINAE helper to detect whether a type supports a 3-integral-argument operator(). ...
Tests whether a class implements rank(). Used in getFunctorRank() method below; allows us to do one t...
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(). ...
Tests whether a class has a member rank. Used in getFixedRank() method below, which in turn is used i...
layout deduction (temporary meta-function)