Intrepid2
Intrepid2_ArgExtractor.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),
38// Mauro Perego (mperego@sandia.gov), or
39// Nate Roberts (nvrober@sandia.gov)
40//
41// ************************************************************************
42// @HEADER
43
49#ifndef __Intrepid2_ArgExtractor_HPP__
50#define __Intrepid2_ArgExtractor_HPP__
51
52#include "Intrepid2_ConfigDefs.hpp"
54#include "Intrepid2_Types.hpp"
55#include "Intrepid2_Utils.hpp"
56
57#include "Kokkos_Core.hpp"
58
59namespace Intrepid2 {
63 template<class reference_type>
65 {
66 template<class ViewType, class ...IntArgs>
67 static KOKKOS_INLINE_FUNCTION reference_type get(const ViewType &view, const IntArgs&... intArgs)
68 {
69 return view(0);
70 }
71 };
72
76 template<class reference_type>
78 {
79 template<class ViewType, class ...IntArgs>
80 static KOKKOS_INLINE_FUNCTION reference_type get(const ViewType &view, const IntArgs&... intArgs)
81 {
82 return view(intArgs...);
83 }
84 };
85
89 template<class reference_type, int whichArg>
91 {
92 template< bool B, class T = reference_type >
93 using enable_if_t = typename std::enable_if<B,T>::type;
94
95 template<class ViewType, class int_type, int M=whichArg>
96 static KOKKOS_INLINE_FUNCTION
97 enable_if_t<M == 0>
98 get(const ViewType &view, const int_type &i0)
99 {
100 return view(i0);
101 }
102
103 template<class ViewType, class int_type, class ...IntArgs, int M=whichArg>
104 static KOKKOS_INLINE_FUNCTION
105 enable_if_t<M == 0>
106 get(const ViewType &view, const int_type &i0, const IntArgs&... intArgs)
107 {
108 return view(i0);
109 }
110
111 template<class ViewType, class int_type, int M=whichArg>
112 static KOKKOS_INLINE_FUNCTION
113 enable_if_t<M == 1>
114 get(const ViewType &view, const int_type &i0, const int_type &i1)
115 {
116 return view(i1);
117 }
118
119 template<class ViewType, class int_type, class ...IntArgs, int M=whichArg>
120 static KOKKOS_INLINE_FUNCTION
121 enable_if_t<M == 1>
122 get(const ViewType &view, const int_type &i0, const int_type &i1, const IntArgs&... intArgs)
123 {
124 return view(i1);
125 }
126
127 template<class ViewType, class int_type, int M=whichArg>
128 static KOKKOS_INLINE_FUNCTION
129 enable_if_t<M == 2>
130 get(const ViewType &view, const int_type &i0, const int_type &i1, const int_type &i2)
131 {
132 return view(i2);
133 }
134
135 template<class ViewType, class int_type, class ...IntArgs, int M=whichArg>
136 static KOKKOS_INLINE_FUNCTION
137 enable_if_t<M == 2>
138 get(const ViewType &view, const int_type &i0, const int_type &i1, const int_type &i2, const IntArgs&... intArgs)
139 {
140 return view(i2);
141 }
142
143 template<class ViewType, class int_type, int M=whichArg>
144 static KOKKOS_INLINE_FUNCTION
145 enable_if_t<M == 3>
146 get(const ViewType &view, const int_type &i0, const int_type &i1, const int_type &i2, const int_type &i3)
147 {
148 return view(i3);
149 }
150
151 template<class ViewType, class int_type, class ...IntArgs, int M=whichArg>
152 static KOKKOS_INLINE_FUNCTION
153 enable_if_t<M == 3>
154 get(const ViewType &view, const int_type &i0, const int_type &i1, const int_type &i2, const int_type &i3, const IntArgs&... intArgs)
155 {
156 return view(i3);
157 }
158
159 template<class ViewType, class int_type, int M=whichArg>
160 static KOKKOS_INLINE_FUNCTION
161 enable_if_t<M == 4>
162 get(const ViewType &view, const int_type &i0, const int_type &i1, const int_type &i2, const int_type &i3, const int_type &i4)
163 {
164 return view(i4);
165 }
166
167 template<class ViewType, class int_type, class ...IntArgs, int M=whichArg>
168 static KOKKOS_INLINE_FUNCTION
169 enable_if_t<M == 4>
170 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)
171 {
172 return view(i4);
173 }
174
175 template<class ViewType, class int_type, int M=whichArg>
176 static KOKKOS_INLINE_FUNCTION
177 enable_if_t<M == 5>
178 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)
179 {
180 return view(i5);
181 }
182
183 template<class ViewType, class int_type, class ...IntArgs, int M=whichArg>
184 static KOKKOS_INLINE_FUNCTION
185 enable_if_t<M == 5>
186 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)
187 {
188 return view(i5);
189 }
190
191 // 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
192 /*
193 template<class ViewType, class ...IntArgs>
194 static KOKKOS_INLINE_FUNCTION
195 enable_if_t<whichArg < sizeof...(IntArgs), reference_type>
196 get(const ViewType &view, const IntArgs&... intArgs)
197 {
198 const auto & arg = std::get<whichArg>(std::tuple<IntArgs...>(intArgs...));
199 return view(arg);
200 }
201 */
202
203 template<class ViewType, class ...IntArgs>
204 static KOKKOS_INLINE_FUNCTION
205 enable_if_t<whichArg >= sizeof...(IntArgs), reference_type>
206 get(const ViewType &view, const IntArgs&... intArgs)
207 {
208 INTREPID2_TEST_FOR_EXCEPTION_DEVICE_SAFE(true,std::invalid_argument,"calling SingleArgExtractor with out-of-bounds argument");
209 Kokkos::abort("Intrepid2::SingleArgExtractor: calling SingleArgExtractor with out-of-bounds argument\n");
210 return view(0); // this line added to avoid missing return statement warning under nvcc
211 }
212 };
213}
214#endif
Implementation of an assert that can safely be called from device code.
Contains definitions of custom data types in Intrepid2.
Header function for Intrepid2::Util class and other utility functions.
#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...
Argument extractor class which passes all arguments to the provided container.
Argument extractor class which passes a single argument, indicated by the template parameter whichArg...