Intrepid2
Intrepid2_ArgExtractor.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Intrepid2 Package
4 //
5 // Copyright 2007 NTESS and the Intrepid2 contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
15 #ifndef __Intrepid2_ArgExtractor_HPP__
16 #define __Intrepid2_ArgExtractor_HPP__
17 
18 #include "Intrepid2_ConfigDefs.hpp"
20 #include "Intrepid2_Types.hpp"
21 #include "Intrepid2_Utils.hpp"
22 
23 #include "Kokkos_Core.hpp"
24 
25 namespace Intrepid2 {
29  template<class reference_type>
31  {
32  template<class ViewType, class ...IntArgs>
33  static KOKKOS_INLINE_FUNCTION reference_type get(const ViewType &view, const IntArgs&... intArgs)
34  {
35  return view(0);
36  }
37  };
38 
42  template<class reference_type>
44  {
45  template<class ViewType, class ...IntArgs>
46  static KOKKOS_INLINE_FUNCTION reference_type get(const ViewType &view, const IntArgs&... intArgs)
47  {
48  return view(intArgs...);
49  }
50  };
51 
55  template<class reference_type, int whichArg>
57  {
58  template< bool B, class T = reference_type >
59  using enable_if_t = typename std::enable_if<B,T>::type;
60 
61  template<class ViewType, class int_type, int M=whichArg>
62  static KOKKOS_INLINE_FUNCTION
63  enable_if_t<M == 0>
64  get(const ViewType &view, const int_type &i0)
65  {
66  return view(i0);
67  }
68 
69  template<class ViewType, class int_type, class ...IntArgs, int M=whichArg>
70  static KOKKOS_INLINE_FUNCTION
71  enable_if_t<M == 0>
72  get(const ViewType &view, const int_type &i0, const IntArgs&... intArgs)
73  {
74  return view(i0);
75  }
76 
77  template<class ViewType, class int_type, int M=whichArg>
78  static KOKKOS_INLINE_FUNCTION
79  enable_if_t<M == 1>
80  get(const ViewType &view, const int_type &i0, const int_type &i1)
81  {
82  return view(i1);
83  }
84 
85  template<class ViewType, class int_type, class ...IntArgs, int M=whichArg>
86  static KOKKOS_INLINE_FUNCTION
87  enable_if_t<M == 1>
88  get(const ViewType &view, const int_type &i0, const int_type &i1, const IntArgs&... intArgs)
89  {
90  return view(i1);
91  }
92 
93  template<class ViewType, class int_type, int M=whichArg>
94  static KOKKOS_INLINE_FUNCTION
95  enable_if_t<M == 2>
96  get(const ViewType &view, const int_type &i0, const int_type &i1, const int_type &i2)
97  {
98  return view(i2);
99  }
100 
101  template<class ViewType, class int_type, class ...IntArgs, int M=whichArg>
102  static KOKKOS_INLINE_FUNCTION
103  enable_if_t<M == 2>
104  get(const ViewType &view, const int_type &i0, const int_type &i1, const int_type &i2, const IntArgs&... intArgs)
105  {
106  return view(i2);
107  }
108 
109  template<class ViewType, class int_type, int M=whichArg>
110  static KOKKOS_INLINE_FUNCTION
111  enable_if_t<M == 3>
112  get(const ViewType &view, const int_type &i0, const int_type &i1, const int_type &i2, const int_type &i3)
113  {
114  return view(i3);
115  }
116 
117  template<class ViewType, class int_type, class ...IntArgs, int M=whichArg>
118  static KOKKOS_INLINE_FUNCTION
119  enable_if_t<M == 3>
120  get(const ViewType &view, const int_type &i0, const int_type &i1, const int_type &i2, const int_type &i3, const IntArgs&... intArgs)
121  {
122  return view(i3);
123  }
124 
125  template<class ViewType, class int_type, int M=whichArg>
126  static KOKKOS_INLINE_FUNCTION
127  enable_if_t<M == 4>
128  get(const ViewType &view, const int_type &i0, const int_type &i1, const int_type &i2, const int_type &i3, const int_type &i4)
129  {
130  return view(i4);
131  }
132 
133  template<class ViewType, class int_type, class ...IntArgs, int M=whichArg>
134  static KOKKOS_INLINE_FUNCTION
135  enable_if_t<M == 4>
136  get(const ViewType &view, const int_type &i0, const int_type &i1, const int_type &i2, const int_type &i3, const int_type &i4, const IntArgs&... intArgs)
137  {
138  return view(i4);
139  }
140 
141  template<class ViewType, class int_type, int M=whichArg>
142  static KOKKOS_INLINE_FUNCTION
143  enable_if_t<M == 5>
144  get(const ViewType &view, const int_type &i0, const int_type &i1, const int_type &i2, const int_type &i3, const int_type &i4, const int_type &i5)
145  {
146  return view(i5);
147  }
148 
149  template<class ViewType, class int_type, class ...IntArgs, int M=whichArg>
150  static KOKKOS_INLINE_FUNCTION
151  enable_if_t<M == 5>
152  get(const ViewType &view, const int_type &i0, const int_type &i1, const int_type &i2, const int_type &i3, const int_type &i4, const int_type &i5, const IntArgs&... intArgs)
153  {
154  return view(i5);
155  }
156 
157  // the commented-out code below is a cleaner way to implement the above, but we can't support this on CUDA until we can require KOKKOS_ENABLE_CUDA_CONSTEXPR
158  /*
159  template<class ViewType, class ...IntArgs>
160  static KOKKOS_INLINE_FUNCTION
161  enable_if_t<whichArg < sizeof...(IntArgs), reference_type>
162  get(const ViewType &view, const IntArgs&... intArgs)
163  {
164  const auto & arg = std::get<whichArg>(std::tuple<IntArgs...>(intArgs...));
165  return view(arg);
166  }
167  */
168 
169  template<class ViewType, class ...IntArgs>
170  static KOKKOS_INLINE_FUNCTION
171  enable_if_t<whichArg >= sizeof...(IntArgs), reference_type>
172  get(const ViewType &view, const IntArgs&... intArgs)
173  {
174  INTREPID2_TEST_FOR_EXCEPTION_DEVICE_SAFE(true,std::invalid_argument,"calling SingleArgExtractor with out-of-bounds argument");
175  Kokkos::abort("Intrepid2::SingleArgExtractor: calling SingleArgExtractor with out-of-bounds argument\n");
176  return view(0); // this line added to avoid missing return statement warning under nvcc
177  }
178  };
179 }
180 #endif
Argument extractor class which passes all arguments to the provided container.
#define INTREPID2_TEST_FOR_EXCEPTION_DEVICE_SAFE(test, x, msg)
Argument extractor class which ignores the input arguments in favor of passing a single 0 argument to...
Header function for Intrepid2::Util class and other utility functions.
Implementation of an assert that can safely be called from device code.
Contains definitions of custom data types in Intrepid2.
Argument extractor class which passes a single argument, indicated by the template parameter whichArg...