16 static const bool value =
false;
24 template <
typename FadType1,
typename FadType2>
37 for (
int i=0;
i<x.size(); ++
i)
43 template <
typename fadtype,
typename ordinal>
46 const ordinal num_cols,
47 const ordinal fad_size,
51 typedef typename fadtype::value_type scalar;
52 fadtype
x(fad_size, scalar(0.0));
54 const scalar x_row = 100.0 + scalar(num_rows) / scalar(row+1);
55 const scalar x_col = 10.0 + scalar(num_cols) / scalar(col+1);
56 x.val() = x_row + x_col;
57 for (ordinal
i=0;
i<fad_size; ++
i) {
58 const scalar x_fad = 1.0 + scalar(fad_size) / scalar(
i+1);
59 x.fastAccessDx(
i) = x_row + x_col + x_fad;
64 #ifndef GLOBAL_FAD_SIZE
65 #define GLOBAL_FAD_SIZE 5
72 static double init() {
return 0.0; }
73 template <
typename T1,
typename T2>
80 static double init() {
return 0.0; }
81 template <
typename T1,
typename T2>
88 static double init() {
return 1.0; }
89 template <
typename T1,
typename T2>
96 static double init() {
return 1.0; }
97 template <
typename T1,
typename T2>
104 static double init() {
return 1.0; }
105 template <
typename T1,
typename T2>
112 static double init() {
return 1.0; }
113 template <
typename T1,
typename T2>
121 template <
typename ViewType,
typename ScalarViewType,
bool OperFetch>
125 typedef typename Kokkos::TeamPolicy< execution_space>::member_type
team_handle;
135 KOKKOS_INLINE_FUNCTION
139 Kokkos::atomic_add_fetch(&(
m_s()), x);
141 Kokkos::atomic_fetch_add(&(
m_s()), x);
144 KOKKOS_INLINE_FUNCTION
148 Kokkos::atomic_sub_fetch(&(
m_s()), x);
150 Kokkos::atomic_fetch_sub(&(
m_s()), x);
153 KOKKOS_INLINE_FUNCTION
157 Kokkos::atomic_mul_fetch(&(
m_s()), x);
159 Kokkos::atomic_fetch_mul(&(
m_s()), x);
162 KOKKOS_INLINE_FUNCTION
166 Kokkos::atomic_div_fetch(&(
m_s()), x);
168 Kokkos::atomic_fetch_div(&(
m_s()), x);
171 KOKKOS_INLINE_FUNCTION
175 Kokkos::atomic_max_fetch(&(
m_s()), x);
177 Kokkos::atomic_fetch_max(&(
m_s()), x);
180 KOKKOS_INLINE_FUNCTION
184 Kokkos::atomic_min_fetch(&(
m_s()), x);
186 Kokkos::atomic_fetch_min(&(
m_s()), x);
189 template <
typename Tag>
190 KOKKOS_INLINE_FUNCTION
193 const size_type i = team.league_rank()*team.team_size() + team.team_rank();
194 if (i <
m_v.extent(0))
199 template <
typename Tag>
200 static void apply(Tag tag,
const ViewType& v,
const ScalarViewType& s) {
203 #if defined (KOKKOS_ENABLE_CUDA) && defined (SACADO_VIEW_CUDA_HIERARCHICAL)
204 const bool use_team =
208 #elif defined (KOKKOS_ENABLE_CUDA) && defined (SACADO_VIEW_CUDA_HIERARCHICAL_DFAD)
209 const bool use_team =
213 #elif defined (KOKKOS_ENABLE_HIP) && defined (SACADO_VIEW_CUDA_HIERARCHICAL)
214 const bool use_team =
218 #elif defined (KOKKOS_ENABLE_HIP) && defined (SACADO_VIEW_CUDA_HIERARCHICAL_DFAD)
219 const bool use_team =
222 is_dfad<typename ViewType::non_const_value_type>::value;
224 const bool use_team =
false;
229 Kokkos::TeamPolicy<execution_space, Tag> policy(
230 (nrow+team_size-1)/team_size, team_size,
stride );
234 Kokkos::RangePolicy<execution_space, Tag> policy( 0, nrow );
240 template <
typename FadType,
typename Layout,
typename Device,
bool OperFetch,
244 typedef Kokkos::View<FadType*,Layout,Device> ViewType;
245 typedef Kokkos::View<FadType,Layout,Device> ScalarViewType;
246 typedef typename ViewType::size_type size_type;
247 typedef typename ViewType::HostMirror host_view_type;
248 typedef typename ScalarViewType::HostMirror host_scalar_view_type;
256 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
257 v = ViewType (
"view", num_rows);
258 s0 = ScalarViewType (
"");
260 v = ViewType (
"view", num_rows, fad_size+1);
261 s0 = ScalarViewType (
"", fad_size+1);
263 host_view_type h_v = Kokkos::create_mirror_view(v);
264 for (size_type
i=0;
i<num_rows; ++
i)
266 generate_fad<FadType>(num_rows, size_type(1), fad_size,
i, size_type(0));
267 Kokkos::deep_copy(v, h_v);
269 Kokkos::deep_copy(s0, tag.init());
273 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
274 s = ScalarViewType (
"scalar view");
276 s = ScalarViewType (
"scalar view", fad_size+1);
278 Kokkos::deep_copy( s, tag.init() );
284 host_scalar_view_type hs = Kokkos::create_mirror_view(s);
285 Kokkos::deep_copy(hs, s);
288 auto b = Kokkos::create_mirror_view(s0);
289 Kokkos::deep_copy(b, s0);
291 for (size_type i=0; i<num_rows; ++
i)
292 b() = tag.apply(b(), h_v(i));
295 bool success =
checkFads(b(), hs(), out);
303 Kokkos_View_Fad, AtomicAddFetch,
FadType, Layout, Device )
305 success = testAtomic<FadType, Layout, Device, true>(
AddTag(), out);
309 Kokkos_View_Fad, AtomicSubFetch,
FadType, Layout, Device )
311 success = testAtomic<FadType, Layout, Device, true>(
SubTag(), out);
315 Kokkos_View_Fad, AtomicMulFetch,
FadType, Layout, Device )
317 success = testAtomic<FadType, Layout, Device, true>(
MulTag(), out);
321 Kokkos_View_Fad, AtomicDivFetch,
FadType, Layout, Device )
323 success = testAtomic<FadType, Layout, Device, true>(
DivTag(), out);
327 Kokkos_View_Fad, AtomicMaxFetch,
FadType, Layout, Device )
329 success = testAtomic<FadType, Layout, Device, true>(
MaxTag(), out);
333 Kokkos_View_Fad, AtomicMinFetch,
FadType, Layout, Device )
335 success = testAtomic<FadType, Layout, Device, true>(
MinTag(), out);
341 Kokkos_View_Fad, AtomicFetchAdd,
FadType, Layout, Device )
343 success = testAtomic<FadType, Layout, Device, false>(
AddTag(), out);
347 Kokkos_View_Fad, AtomicFetchSub,
FadType, Layout, Device )
349 success = testAtomic<FadType, Layout, Device, false>(
SubTag(), out);
353 Kokkos_View_Fad, AtomicFetchMul,
FadType, Layout, Device )
355 success = testAtomic<FadType, Layout, Device, false>(
MulTag(), out);
359 Kokkos_View_Fad, AtomicFetchDiv,
FadType, Layout, Device )
361 success = testAtomic<FadType, Layout, Device, false>(
DivTag(), out);
365 Kokkos_View_Fad, AtomicFetchMax,
FadType, Layout, Device )
367 success = testAtomic<FadType, Layout, Device, false>(
MaxTag(), out);
371 Kokkos_View_Fad, AtomicFetchMin,
FadType, Layout, Device )
373 success = testAtomic<FadType, Layout, Device, false>(
MinTag(), out);
376 #define VIEW_FAD_TESTS_FLD( F, L, D ) \
377 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, AtomicAddFetch, F, L, D ) \
378 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, AtomicSubFetch, F, L, D ) \
379 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, AtomicMulFetch, F, L, D ) \
380 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, AtomicDivFetch, F, L, D ) \
381 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, AtomicMaxFetch, F, L, D ) \
382 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, AtomicMinFetch, F, L, D ) \
383 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, AtomicFetchAdd, F, L, D ) \
384 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, AtomicFetchSub, F, L, D ) \
385 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, AtomicFetchMul, F, L, D ) \
386 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, AtomicFetchDiv, F, L, D ) \
387 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, AtomicFetchMax, F, L, D ) \
388 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, AtomicFetchMin, F, L, D )
390 using Kokkos::LayoutLeft;
391 using Kokkos::LayoutRight;
395 #define VIEW_FAD_TESTS_FD( F, D ) \
396 VIEW_FAD_TESTS_FLD( F, LayoutLeft, D ) \
397 VIEW_FAD_TESTS_FLD( F, LayoutRight, D ) \
398 VIEW_FAD_TESTS_FLD( F, LeftContiguous, D ) \
399 VIEW_FAD_TESTS_FLD( F, RightContiguous, D )
402 #if SACADO_ENABLE_NEW_DESIGN
408 #define VIEW_FAD_TESTS_D( D ) \
409 VIEW_FAD_TESTS_FD( SFadType, D ) \
410 VIEW_FAD_TESTS_FD( SLFadType, D ) \
411 VIEW_FAD_TESTS_FD( DFadType, D )
413 #define VIEW_FAD_TESTS_D( D ) \
414 VIEW_FAD_TESTS_FD( SFadType, D ) \
415 VIEW_FAD_TESTS_FD( SLFadType, D )
420 #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))