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
64namespace Intrepid2 {
65
66#if defined(__CUDA_ARCH__) || defined(__HIP_DEVICE_COMPILE__)
67#define INTREPID2_COMPILE_DEVICE_CODE
68#endif
69
70#if defined(KOKKOS_ENABLE_CUDA) || defined(KOKKOS_ENABLE_HIP)
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 printf("[Intrepid2] Warning in file %s, line %d\n",__FILE__,__LINE__); \
87 printf(" Test that evaluated to true: %s\n", #test); \
88 printf(" %s \n", msg); \
89 }
90
91#define INTREPID2_TEST_FOR_EXCEPTION(test, x, msg) \
92 if (test) { \
93 printf("[Intrepid2] Error in file %s, line %d\n",__FILE__,__LINE__); \
94 printf(" Test that evaluated to true: %s\n", #test); \
95 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 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"); \
116 }
117#endif
118#if defined(INTREPID2_ENABLE_DEBUG) || defined(NDEBUG) || 1
119#define INTREPID2_TEST_FOR_ABORT(test, msg) \
120 if (test) { \
121 printf("[Intrepid2] Error in file %s, line %d\n",__FILE__,__LINE__); \
122 printf(" Test that evaluated to true: %s\n", #test); \
123 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 printf("[Intrepid2] Error in file %s, line %d\n",__FILE__,__LINE__); \
134 printf(" Test that evaluated to true: %s\n", #test); \
135 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 printf("[Intrepid2] Error in file %s, line %d\n",__FILE__,__LINE__); \
142 printf(" Test that evaluated to true: %s\n", #test); \
143 printf(" %s \n", msg); \
144 info = true ; \
145 Kokkos::abort( "[Intrepid2] Abort\n"); \
146 }
147#endif
148
152 template<typename T>
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>
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 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.");
403
407 template<class Functor, ordinal_type default_value>
408 constexpr
409 enable_if_t<has_rank_member<Functor>::value, ordinal_type>
411 {
412 return Functor::rank;
413 }
414
418 template<class Functor, ordinal_type default_value>
419 constexpr
420 enable_if_t<!has_rank_member<Functor>::value, ordinal_type>
422 {
423 return default_value;
424 }
425
429 template <typename T>
431 {
432 typedef char one;
433 struct two { char x[2]; };
434
435 template <typename C> static one test( typename std::remove_reference<decltype( std::declval<C>().operator()(0))>::type );
436 template <typename C> static two test(...);
437
438 public:
439 enum { value = sizeof(test<T>(0)) == sizeof(char) && (getFixedRank<T,1>() == 1) };
440 };
441
445 template <typename T>
447 {
448 typedef char one;
449 struct two { char x[2]; };
450
451 template <typename C> static one test( typename std::remove_reference<decltype( std::declval<C>().operator()(0,0))>::type ) ;
452 template <typename C> static two test(...);
453
454 public:
455 enum { value = sizeof(test<T>(0)) == sizeof(char) && (getFixedRank<T,2>() == 2) };
456 };
457
461 template <typename T>
463 {
464 typedef char one;
465 struct two { char x[2]; };
466
467 template <typename C> static one test( typename std::remove_reference<decltype( std::declval<C>().operator()(0,0,0))>::type ) ;
468 template <typename C> static two test(...);
469
470 public:
471 enum { value = (sizeof(test<T>(0)) == sizeof(char)) && (getFixedRank<T,3>() == 3) };
472 };
473
477 template <typename T>
479 {
480 typedef char one;
481 struct two { char x[2]; };
482
483 template <typename C> static one test( typename std::remove_reference<decltype( std::declval<C>().operator()(0,0,0,0))>::type ) ;
484 template <typename C> static two test(...);
485
486 public:
487 enum { value = sizeof(test<T>(0)) == sizeof(char) && (getFixedRank<T,4>() == 4) };
488 };
489
493 template <typename T>
495 {
496 typedef char one;
497 struct two { char x[2]; };
498
499 template <typename C> static one test( typename std::remove_reference<decltype( std::declval<C>().operator()(0,0,0,0,0))>::type ) ;
500 template <typename C> static two test(...);
501
502 public:
503 enum { value = sizeof(test<T>(0)) == sizeof(char) && (getFixedRank<T,5>() == 5) };
504 };
505
509 template <typename T>
511 {
512 typedef char one;
513 struct two { char x[2]; };
514
515 template <typename C> static one test( typename std::remove_reference<decltype( std::declval<C>().operator()(0,0,0,0,0,0))>::type ) ;
516 template <typename C> static two test(...);
517
518 public:
519 enum { value = sizeof(test<T>(0)) == sizeof(char) && (getFixedRank<T,6>() == 6) };
520 };
521
525 template <typename T>
527 {
528 typedef char one;
529 struct two { char x[2]; };
530
531 template <typename C> static one test( typename std::remove_reference<decltype( std::declval<C>().operator()(0,0,0,0,0,0,0))>::type ) ;
532 template <typename C> static two test(...);
533
534 public:
535 enum { value = sizeof(test<T>(0)) == sizeof(char) && (getFixedRank<T,7>() == 7) };
536 };
537
541 template <typename T, int rank>
543 {
544 public:
545 enum { value = false };
546 };
547
551 template <typename T>
552 class supports_rank<T,1>
553 {
554 public:
555 enum { value = supports_rank_1<T>::value };
556 };
557
559 template <typename T>
560 class supports_rank<T,2>
561 {
562 public:
563 enum { value = supports_rank_2<T>::value };
564 };
565
567 template <typename T>
568 class supports_rank<T,3>
569 {
570 public:
571 enum { value = supports_rank_3<T>::value };
572 };
573
575 template <typename T>
576 class supports_rank<T,4>
577 {
578 public:
579 enum { value = supports_rank_4<T>::value };
580 };
581
583 template <typename T>
584 class supports_rank<T,5>
585 {
586 public:
587 enum { value = supports_rank_5<T>::value };
588 };
589
591 template <typename T>
592 class supports_rank<T,6>
593 {
594 public:
595 enum { value = supports_rank_6<T>::value };
596 };
597
599 template <typename T>
600 class supports_rank<T,7>
601 {
602 public:
603 enum { value = supports_rank_7<T>::value };
604 };
605
606
607
611 template<typename Scalar, int rank>
613
614 };
615
619 template<typename Scalar>
620 struct RankExpander<Scalar,0>
621 {
622 using value_type = Scalar;
623 };
624
628 template<typename Scalar>
629 struct RankExpander<Scalar,1>
630 {
631 using value_type = Scalar*;
632 };
633
637 template<typename Scalar>
638 struct RankExpander<Scalar,2>
639 {
640 using value_type = Scalar**;
641 };
642
646 template<typename Scalar>
647 struct RankExpander<Scalar,3>
648 {
649 using value_type = Scalar***;
650 };
651
655 template<typename Scalar>
656 struct RankExpander<Scalar,4>
657 {
658 using value_type = Scalar****;
659 };
660
664 template<typename Scalar>
665 struct RankExpander<Scalar,5>
666 {
667 using value_type = Scalar*****;
668 };
669
673 template<typename Scalar>
674 struct RankExpander<Scalar,6>
675 {
676 using value_type = Scalar******;
677 };
678
682 template<typename Scalar>
683 struct RankExpander<Scalar,7>
684 {
685 using value_type = Scalar*******;
686 };
687
688 // positive checks of supports_rank for Kokkos::DynRankView:
689 static_assert(supports_rank<Kokkos::DynRankView<double>, 1>::value, "rank 1 check of supports_rank for DynRankView");
690 static_assert(supports_rank<Kokkos::DynRankView<double>, 2>::value, "rank 2 check of supports_rank for DynRankView");
691 static_assert(supports_rank<Kokkos::DynRankView<double>, 3>::value, "rank 3 check of supports_rank for DynRankView");
692 static_assert(supports_rank<Kokkos::DynRankView<double>, 4>::value, "rank 4 check of supports_rank for DynRankView");
693 static_assert(supports_rank<Kokkos::DynRankView<double>, 5>::value, "rank 5 check of supports_rank for DynRankView");
694 static_assert(supports_rank<Kokkos::DynRankView<double>, 6>::value, "rank 6 check of supports_rank for DynRankView");
695 static_assert(supports_rank<Kokkos::DynRankView<double>, 7>::value, "rank 7 check of supports_rank for DynRankView");
696
697 // positive checks of supports_rank for Kokkos::View:
698 static_assert(supports_rank<Kokkos::View<double*>, 1>::value, "rank 1 check of supports_rank");
699 static_assert(supports_rank<Kokkos::View<double**>, 2>::value, "rank 2 check of supports_rank");
700 static_assert(supports_rank<Kokkos::View<double***>, 3>::value, "rank 3 check of supports_rank");
701 static_assert(supports_rank<Kokkos::View<double****>, 4>::value, "rank 4 check of supports_rank");
702 static_assert(supports_rank<Kokkos::View<double*****>, 5>::value, "rank 5 check of supports_rank");
703 static_assert(supports_rank<Kokkos::View<double******>, 6>::value, "rank 6 check of supports_rank");
704 static_assert(supports_rank<Kokkos::View<double*******>, 7>::value, "rank 7 check of supports_rank");
705
706 // negative checks of supports_rank for Kokkos::View:
707 static_assert(!supports_rank<Kokkos::View<double*>, 2>::value, "rank 1 check of supports_rank");
708 static_assert(!supports_rank<Kokkos::View<double*>, 3>::value, "rank 1 check of supports_rank");
709 static_assert(!supports_rank<Kokkos::View<double*>, 4>::value, "rank 1 check of supports_rank");
710 static_assert(!supports_rank<Kokkos::View<double*>, 5>::value, "rank 1 check of supports_rank");
711 static_assert(!supports_rank<Kokkos::View<double*>, 6>::value, "rank 1 check of supports_rank");
712 static_assert(!supports_rank<Kokkos::View<double*>, 7>::value, "rank 1 check of supports_rank");
713 static_assert(!supports_rank<Kokkos::View<double**>, 1>::value, "rank 2 check of supports_rank");
714 static_assert(!supports_rank<Kokkos::View<double**>, 3>::value, "rank 2 check of supports_rank");
715 static_assert(!supports_rank<Kokkos::View<double**>, 4>::value, "rank 2 check of supports_rank");
716 static_assert(!supports_rank<Kokkos::View<double**>, 5>::value, "rank 2 check of supports_rank");
717 static_assert(!supports_rank<Kokkos::View<double**>, 6>::value, "rank 2 check of supports_rank");
718 static_assert(!supports_rank<Kokkos::View<double**>, 7>::value, "rank 2 check of supports_rank");
719 static_assert(!supports_rank<Kokkos::View<double***>, 1>::value, "rank 3 check of supports_rank");
720 static_assert(!supports_rank<Kokkos::View<double***>, 2>::value, "rank 3 check of supports_rank");
721 static_assert(!supports_rank<Kokkos::View<double***>, 4>::value, "rank 3 check of supports_rank");
722 static_assert(!supports_rank<Kokkos::View<double***>, 5>::value, "rank 3 check of supports_rank");
723 static_assert(!supports_rank<Kokkos::View<double***>, 6>::value, "rank 3 check of supports_rank");
724 static_assert(!supports_rank<Kokkos::View<double***>, 7>::value, "rank 3 check of supports_rank");
725 static_assert(!supports_rank<Kokkos::View<double****>, 1>::value, "rank 4 check of supports_rank");
726 static_assert(!supports_rank<Kokkos::View<double****>, 2>::value, "rank 4 check of supports_rank");
727 static_assert(!supports_rank<Kokkos::View<double****>, 3>::value, "rank 4 check of supports_rank");
728 static_assert(!supports_rank<Kokkos::View<double****>, 5>::value, "rank 4 check of supports_rank");
729 static_assert(!supports_rank<Kokkos::View<double****>, 6>::value, "rank 4 check of supports_rank");
730 static_assert(!supports_rank<Kokkos::View<double****>, 7>::value, "rank 4 check of supports_rank");
731 static_assert(!supports_rank<Kokkos::View<double*****>, 1>::value, "rank 5 check of supports_rank");
732 static_assert(!supports_rank<Kokkos::View<double*****>, 2>::value, "rank 5 check of supports_rank");
733 static_assert(!supports_rank<Kokkos::View<double*****>, 3>::value, "rank 5 check of supports_rank");
734 static_assert(!supports_rank<Kokkos::View<double*****>, 4>::value, "rank 5 check of supports_rank");
735 static_assert(!supports_rank<Kokkos::View<double*****>, 6>::value, "rank 5 check of supports_rank");
736 static_assert(!supports_rank<Kokkos::View<double*****>, 7>::value, "rank 5 check of supports_rank");
737 static_assert(!supports_rank<Kokkos::View<double******>, 1>::value, "rank 6 check of supports_rank");
738 static_assert(!supports_rank<Kokkos::View<double******>, 2>::value, "rank 6 check of supports_rank");
739 static_assert(!supports_rank<Kokkos::View<double******>, 3>::value, "rank 6 check of supports_rank");
740 static_assert(!supports_rank<Kokkos::View<double******>, 4>::value, "rank 6 check of supports_rank");
741 static_assert(!supports_rank<Kokkos::View<double******>, 5>::value, "rank 6 check of supports_rank");
742 static_assert(!supports_rank<Kokkos::View<double******>, 7>::value, "rank 6 check of supports_rank");
743 static_assert(!supports_rank<Kokkos::View<double*******>, 1>::value, "rank 7 check of supports_rank");
744 static_assert(!supports_rank<Kokkos::View<double*******>, 2>::value, "rank 7 check of supports_rank");
745 static_assert(!supports_rank<Kokkos::View<double*******>, 3>::value, "rank 7 check of supports_rank");
746 static_assert(!supports_rank<Kokkos::View<double*******>, 4>::value, "rank 7 check of supports_rank");
747 static_assert(!supports_rank<Kokkos::View<double*******>, 5>::value, "rank 7 check of supports_rank");
748 static_assert(!supports_rank<Kokkos::View<double*******>, 6>::value, "rank 7 check of supports_rank");
749
753 template <typename T>
755 {
756 typedef char one;
757 struct two { char x[2]; };
758
759 template <typename C> static one test( decltype( std::declval<C>().rank() ) ) ;
760 template <typename C> static two test(...);
761
762 public:
763 enum { value = sizeof(test<T>(0)) == sizeof(char) };
764 };
765
766 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.");
767 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.");
768
772 template<class Functor>
773 enable_if_t<has_rank_method<Functor>::value, unsigned>
774 KOKKOS_INLINE_FUNCTION
775 getFunctorRank(const Functor &functor)
776 {
777 return functor.rank();
778 }
779
783 template<class Functor>
784 enable_if_t<!has_rank_method<Functor>::value, unsigned>
785 KOKKOS_INLINE_FUNCTION
786 getFunctorRank(const Functor &functor)
787 {
788 return functor.rank;
789 }
790
794#ifdef HAVE_INTREPID2_SACADO
795 template <typename ValueType>
796 struct NaturalLayoutForType {
797 using layout =
798 typename std::conditional<std::is_pod<ValueType>::value,
799 Kokkos::LayoutLeft, // for POD types, use LayoutLeft
800 Kokkos::LayoutNatural<Kokkos::LayoutLeft> >::type; // For FAD types, use LayoutNatural
801 };
802#else
803 template <typename ValueType>
805 using layout = Kokkos::LayoutLeft;
806 };
807#endif
808
809 // define vector sizes for hierarchical parallelism
810 const int VECTOR_SIZE = 1;
811#if defined(SACADO_VIEW_CUDA_HIERARCHICAL_DFAD) && defined(INTREPID2_ENABLE_DEVICE)
812 const int FAD_VECTOR_SIZE = 32;
813#else
814 const int FAD_VECTOR_SIZE = 1;
815#endif
816
820 template<typename Scalar>
822 {
823 return std::is_pod<Scalar>::value ? VECTOR_SIZE : FAD_VECTOR_SIZE;
824 }
825
831 template<typename ViewType>
832 KOKKOS_INLINE_FUNCTION
833 constexpr unsigned getScalarDimensionForView(const ViewType &view)
834 {
835 return (std::is_pod<typename ViewType::value_type>::value) ? 0 : get_dimension_scalar(view);
836 }
837} // end namespace Intrepid2
838
839#endif
Implementation of an assert that can safely be called from device code.
Contains definitions of custom data types in Intrepid2.
enable_if_t< has_rank_method< Functor >::value, unsigned > KOKKOS_INLINE_FUNCTION getFunctorRank(const Functor &functor)
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...
constexpr int getVectorSizeForHierarchicalParallelism()
Returns a vector size to be used for the provided Scalar type in the context of hierarchically-parall...
constexpr enable_if_t< has_rank_member< Functor >::value, ordinal_type > getFixedRank()
KOKKOS_FORCEINLINE_FUNCTION constexpr std::enable_if<!std::is_pod< T >::value, typenameScalarTraits< T >::scalar_type >::type get_scalar_value(const T &obj)
functions returning the scalar value. for pod types, they return the input object itself....
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....
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.
small utility functions
Tests whether a class implements rank(). Used in getFunctorRank() method below; allows us to do one t...
SFINAE helper to detect whether a type supports a 1-integral-argument operator().
SFINAE helper to detect whether a type supports a 2-integral-argument operator().
SFINAE helper to detect whether a type supports a 3-integral-argument operator().
SFINAE helper to detect whether a type supports a 4-integral-argument operator().
SFINAE helper to detect whether a type supports a 5-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().
layout deduction (temporary meta-function)
Define layout that will allow us to wrap Sacado Scalar objects in Views without copying.
Helper to get Scalar[*+] where the number of *'s matches the given rank.
Tests whether a class has a member rank. Used in getFixedRank() method below, which in turn is used i...