35 static const bool value =
false;
43 template <
typename FadType1,
typename FadType2>
56 for (
int i=0;
i<x.size(); ++
i)
62 template <
typename fadtype,
typename ordinal>
65 const ordinal num_cols,
66 const ordinal fad_size,
70 typedef typename fadtype::value_type scalar;
71 fadtype
x(fad_size, scalar(0.0));
73 const scalar x_row = 100.0 + scalar(num_rows) / scalar(row+1);
74 const scalar x_col = 10.0 + scalar(num_cols) / scalar(col+1);
75 x.val() = x_row + x_col;
76 for (ordinal
i=0;
i<fad_size; ++
i) {
77 const scalar x_fad = 1.0 + scalar(fad_size) / scalar(
i+1);
78 x.fastAccessDx(
i) = x_row + x_col + x_fad;
83 #ifndef GLOBAL_FAD_SIZE
84 #define GLOBAL_FAD_SIZE 5
91 static double init() {
return 0.0; }
92 template <
typename T1,
typename T2>
99 static double init() {
return 0.0; }
100 template <
typename T1,
typename T2>
107 static double init() {
return 1.0; }
108 template <
typename T1,
typename T2>
115 static double init() {
return 1.0; }
116 template <
typename T1,
typename T2>
123 static double init() {
return 1.0; }
124 template <
typename T1,
typename T2>
131 static double init() {
return 1.0; }
132 template <
typename T1,
typename T2>
140 template <
typename ViewType,
typename ScalarViewType,
bool OperFetch>
144 typedef typename Kokkos::TeamPolicy< execution_space>::member_type
team_handle;
154 KOKKOS_INLINE_FUNCTION
158 Kokkos::atomic_add_fetch(&(
m_s()), x);
160 Kokkos::atomic_fetch_add(&(
m_s()), x);
163 KOKKOS_INLINE_FUNCTION
167 Kokkos::atomic_sub_fetch(&(
m_s()), x);
169 Kokkos::atomic_fetch_sub(&(
m_s()), x);
172 KOKKOS_INLINE_FUNCTION
176 Kokkos::atomic_mul_fetch(&(
m_s()), x);
178 Kokkos::atomic_fetch_mul(&(
m_s()), x);
181 KOKKOS_INLINE_FUNCTION
185 Kokkos::atomic_div_fetch(&(
m_s()), x);
187 Kokkos::atomic_fetch_div(&(
m_s()), x);
190 KOKKOS_INLINE_FUNCTION
194 Kokkos::atomic_max_fetch(&(
m_s()), x);
196 Kokkos::atomic_fetch_max(&(
m_s()), x);
199 KOKKOS_INLINE_FUNCTION
203 Kokkos::atomic_min_fetch(&(
m_s()), x);
205 Kokkos::atomic_fetch_min(&(
m_s()), x);
208 template <
typename Tag>
209 KOKKOS_INLINE_FUNCTION
212 const size_type i = team.league_rank()*team.team_size() + team.team_rank();
213 if (i <
m_v.extent(0))
218 template <
typename Tag>
219 static void apply(Tag tag,
const ViewType& v,
const ScalarViewType& s) {
222 #if defined (KOKKOS_ENABLE_CUDA) && defined (SACADO_VIEW_CUDA_HIERARCHICAL)
223 const bool use_team =
227 #elif defined (KOKKOS_ENABLE_CUDA) && defined (SACADO_VIEW_CUDA_HIERARCHICAL_DFAD)
228 const bool use_team =
232 #elif defined (KOKKOS_ENABLE_HIP) && defined (SACADO_VIEW_CUDA_HIERARCHICAL)
233 const bool use_team =
237 #elif defined (KOKKOS_ENABLE_HIP) && defined (SACADO_VIEW_CUDA_HIERARCHICAL_DFAD)
238 const bool use_team =
241 is_dfad<typename ViewType::non_const_value_type>::value;
243 const bool use_team =
false;
248 Kokkos::TeamPolicy<execution_space, Tag> policy(
249 (nrow+team_size-1)/team_size, team_size,
stride );
253 Kokkos::RangePolicy<execution_space, Tag> policy( 0, nrow );
259 template <
typename FadType,
typename Layout,
typename Device,
bool OperFetch,
263 typedef Kokkos::View<FadType*,Layout,Device> ViewType;
264 typedef Kokkos::View<FadType,Layout,Device> ScalarViewType;
265 typedef typename ViewType::size_type size_type;
266 typedef typename ViewType::HostMirror host_view_type;
267 typedef typename ScalarViewType::HostMirror host_scalar_view_type;
275 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
276 v = ViewType (
"view", num_rows);
277 s0 = ScalarViewType (
"");
279 v = ViewType (
"view", num_rows, fad_size+1);
280 s0 = ScalarViewType (
"", fad_size+1);
282 host_view_type h_v = Kokkos::create_mirror_view(v);
283 for (size_type
i=0;
i<num_rows; ++
i)
285 generate_fad<FadType>(num_rows, size_type(1), fad_size,
i, size_type(0));
286 Kokkos::deep_copy(v, h_v);
288 Kokkos::deep_copy(s0, tag.init());
292 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
293 s = ScalarViewType (
"scalar view");
295 s = ScalarViewType (
"scalar view", fad_size+1);
297 Kokkos::deep_copy( s, tag.init() );
303 host_scalar_view_type hs = Kokkos::create_mirror_view(s);
304 Kokkos::deep_copy(hs, s);
307 auto b = Kokkos::create_mirror_view(s0);
308 Kokkos::deep_copy(b, s0);
310 for (size_type i=0; i<num_rows; ++
i)
311 b() = tag.apply(b(), h_v(i));
314 bool success =
checkFads(b(), hs(), out);
322 Kokkos_View_Fad, AtomicAddFetch,
FadType, Layout, Device )
324 success = testAtomic<FadType, Layout, Device, true>(
AddTag(), out);
328 Kokkos_View_Fad, AtomicSubFetch,
FadType, Layout, Device )
330 success = testAtomic<FadType, Layout, Device, true>(
SubTag(), out);
334 Kokkos_View_Fad, AtomicMulFetch,
FadType, Layout, Device )
336 success = testAtomic<FadType, Layout, Device, true>(
MulTag(), out);
340 Kokkos_View_Fad, AtomicDivFetch,
FadType, Layout, Device )
342 success = testAtomic<FadType, Layout, Device, true>(
DivTag(), out);
346 Kokkos_View_Fad, AtomicMaxFetch,
FadType, Layout, Device )
348 success = testAtomic<FadType, Layout, Device, true>(
MaxTag(), out);
352 Kokkos_View_Fad, AtomicMinFetch,
FadType, Layout, Device )
354 success = testAtomic<FadType, Layout, Device, true>(
MinTag(), out);
360 Kokkos_View_Fad, AtomicFetchAdd,
FadType, Layout, Device )
362 success = testAtomic<FadType, Layout, Device, false>(
AddTag(), out);
366 Kokkos_View_Fad, AtomicFetchSub,
FadType, Layout, Device )
368 success = testAtomic<FadType, Layout, Device, false>(
SubTag(), out);
372 Kokkos_View_Fad, AtomicFetchMul,
FadType, Layout, Device )
374 success = testAtomic<FadType, Layout, Device, false>(
MulTag(), out);
378 Kokkos_View_Fad, AtomicFetchDiv,
FadType, Layout, Device )
380 success = testAtomic<FadType, Layout, Device, false>(
DivTag(), out);
384 Kokkos_View_Fad, AtomicFetchMax,
FadType, Layout, Device )
386 success = testAtomic<FadType, Layout, Device, false>(
MaxTag(), out);
390 Kokkos_View_Fad, AtomicFetchMin,
FadType, Layout, Device )
392 success = testAtomic<FadType, Layout, Device, false>(
MinTag(), out);
395 #define VIEW_FAD_TESTS_FLD( F, L, D ) \
396 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, AtomicAddFetch, F, L, D ) \
397 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, AtomicSubFetch, F, L, D ) \
398 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, AtomicMulFetch, F, L, D ) \
399 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, AtomicDivFetch, F, L, D ) \
400 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, AtomicMaxFetch, F, L, D ) \
401 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, AtomicMinFetch, F, L, D ) \
402 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, AtomicFetchAdd, F, L, D ) \
403 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, AtomicFetchSub, F, L, D ) \
404 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, AtomicFetchMul, F, L, D ) \
405 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, AtomicFetchDiv, F, L, D ) \
406 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, AtomicFetchMax, F, L, D ) \
407 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, AtomicFetchMin, F, L, D )
409 using Kokkos::LayoutLeft;
410 using Kokkos::LayoutRight;
414 #define VIEW_FAD_TESTS_FD( F, D ) \
415 VIEW_FAD_TESTS_FLD( F, LayoutLeft, D ) \
416 VIEW_FAD_TESTS_FLD( F, LayoutRight, D ) \
417 VIEW_FAD_TESTS_FLD( F, LeftContiguous, D ) \
418 VIEW_FAD_TESTS_FLD( F, RightContiguous, D )
421 #if SACADO_ENABLE_NEW_DESIGN
427 #define VIEW_FAD_TESTS_D( D ) \
428 VIEW_FAD_TESTS_FD( SFadType, D ) \
429 VIEW_FAD_TESTS_FD( SLFadType, D ) \
430 VIEW_FAD_TESTS_FD( DFadType, D )
432 #define VIEW_FAD_TESTS_D( D ) \
433 VIEW_FAD_TESTS_FD( SFadType, D ) \
434 VIEW_FAD_TESTS_FD( SLFadType, D )
439 #define VIEW_FAD_TESTS_D( D )
KOKKOS_INLINE_FUNCTION void operator()(Tag tag, const team_handle &team) const
static auto apply(const T1 &a, const T2 &b) -> decltype(a/b)
Kokkos::LayoutContiguous< Kokkos::LayoutRight > RightContiguous
Kokkos::LayoutContiguous< Kokkos::LayoutLeft > LeftContiguous
#define TEUCHOS_TEST_FLOATING_EQUALITY(v1, v2, tol, out, success)
Kokkos::ThreadLocalScalarType< ViewType >::type local_scalar_type
const int global_fad_size
Sacado::Fad::DFad< double > FadType
ViewType::size_type size_type
bool checkFads(const FadType1 &x, const FadType2 &x2, Teuchos::FancyOStream &out, double tol=1.0e-15)
const int global_num_rows
AtomicKernel(const ViewType &v, const ScalarViewType &s)
scalar generate_fad(const size_t n0, const size_t n1, const size_t n2, const size_t n3, const int fad_size, const size_t i0, const size_t i1, const size_t i2, const size_t i3, const int i_fad)
Sacado::Fad::SFad< double, fad_dim > SFadType
static const size_type stride
static auto apply(const T1 &a, const T2 &b) -> decltype(a-b)
TEUCHOS_UNIT_TEST_TEMPLATE_3_DECL(Kokkos_View_FadFad, DeepCopy, FadFadType, Layout, Device)
const int global_num_cols
GeneralFad< DynamicStorage< T > > DFad
SimpleFad< ValueT > min(const SimpleFad< ValueT > &a, const SimpleFad< ValueT > &b)
Forward-mode AD class templated on the storage for the derivative array.
static auto apply(const T1 &a, const T2 &b) -> decltype(a+b)
Sacado::Fad::SLFad< double, fad_dim > SLFadType
Sacado::Fad::DFad< double > DFadType
static auto apply(const T1 &a, const T2 &b) -> decltype(min(a, b))
static void apply(Tag tag, const ViewType &v, const ScalarViewType &s)
KOKKOS_INLINE_FUNCTION void operator()(AddTag tag, const size_type i) const
#define TEUCHOS_TEST_EQUALITY(v1, v2, out, success)
Kokkos::TeamPolicy< execution_space >::member_type team_handle
SimpleFad< ValueT > max(const SimpleFad< ValueT > &a, const SimpleFad< ValueT > &b)
ViewType::execution_space execution_space
bool testAtomic(const TagType &tag, Teuchos::FancyOStream &out)
static auto apply(const T1 &a, const T2 &b) -> decltype(a *b)
static auto apply(const T1 &a, const T2 &b) -> decltype(max(a, b))