29 #include "Teuchos_TestingHelpers.hpp" 35 static const bool value =
false;
43 template <
typename FadType1,
typename FadType2>
45 Teuchos::FancyOStream& out,
double tol = 1.0e-15)
50 TEUCHOS_TEST_EQUALITY(
x.size(), x2.size(), out, success);
53 TEUCHOS_TEST_FLOATING_EQUALITY(
x.val(), x2.val(),
tol, out, success);
56 for (
int i=0;
i<
x.size(); ++
i)
57 TEUCHOS_TEST_FLOATING_EQUALITY(
x.dx(
i), x2.dx(
i),
tol, out, success);
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 =
233 const bool use_team =
false;
238 Kokkos::TeamPolicy<execution_space, Tag> policy(
239 (nrow+team_size-1)/team_size, team_size,
stride );
243 Kokkos::RangePolicy<execution_space, Tag> policy( 0, nrow );
249 template <
typename FadType,
typename Layout,
typename Device,
bool OperFetch,
251 bool testAtomic(
const TagType& tag, Teuchos::FancyOStream& out)
253 typedef Kokkos::View<FadType*,Layout,Device> ViewType;
254 typedef Kokkos::View<FadType,Layout,Device> ScalarViewType;
255 typedef typename ViewType::size_type size_type;
256 typedef typename ViewType::HostMirror host_view_type;
257 typedef typename ScalarViewType::HostMirror host_scalar_view_type;
264 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC) 265 v = ViewType (
"view", num_rows);
267 v = ViewType (
"view", num_rows, fad_size+1);
269 host_view_type h_v = Kokkos::create_mirror_view(v);
270 for (size_type
i=0;
i<num_rows; ++
i)
272 generate_fad<FadType>(num_rows, size_type(1), fad_size,
i, size_type(0));
273 Kokkos::deep_copy(v, h_v);
278 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC) 279 s = ScalarViewType (
"scalar view");
281 s = ScalarViewType (
"scalar view", fad_size+1);
283 Kokkos::deep_copy( s, s0 );
289 host_scalar_view_type hs = Kokkos::create_mirror_view(s);
290 Kokkos::deep_copy(hs, s);
294 for (size_type
i=0;
i<num_rows; ++
i)
295 b = tag.apply(b, h_v(
i));
306 Kokkos_View_Fad, AtomicAddFetch,
FadType, Layout, Device )
308 success = testAtomic<FadType, Layout, Device, true>(
AddTag(), out);
312 Kokkos_View_Fad, AtomicSubFetch,
FadType, Layout, Device )
314 success = testAtomic<FadType, Layout, Device, true>(
SubTag(), out);
318 Kokkos_View_Fad, AtomicMulFetch,
FadType, Layout, Device )
320 success = testAtomic<FadType, Layout, Device, true>(
MulTag(), out);
324 Kokkos_View_Fad, AtomicDivFetch,
FadType, Layout, Device )
326 success = testAtomic<FadType, Layout, Device, true>(
DivTag(), out);
330 Kokkos_View_Fad, AtomicMaxFetch,
FadType, Layout, Device )
332 success = testAtomic<FadType, Layout, Device, true>(
MaxTag(), out);
336 Kokkos_View_Fad, AtomicMinFetch,
FadType, Layout, Device )
338 success = testAtomic<FadType, Layout, Device, true>(
MinTag(), out);
344 Kokkos_View_Fad, AtomicFetchAdd,
FadType, Layout, Device )
346 success = testAtomic<FadType, Layout, Device, false>(
AddTag(), out);
350 Kokkos_View_Fad, AtomicFetchSub,
FadType, Layout, Device )
352 success = testAtomic<FadType, Layout, Device, false>(
SubTag(), out);
356 Kokkos_View_Fad, AtomicFetchMul,
FadType, Layout, Device )
358 success = testAtomic<FadType, Layout, Device, false>(
MulTag(), out);
362 Kokkos_View_Fad, AtomicFetchDiv,
FadType, Layout, Device )
364 success = testAtomic<FadType, Layout, Device, false>(
DivTag(), out);
368 Kokkos_View_Fad, AtomicFetchMax,
FadType, Layout, Device )
370 success = testAtomic<FadType, Layout, Device, false>(
MaxTag(), out);
374 Kokkos_View_Fad, AtomicFetchMin,
FadType, Layout, Device )
376 success = testAtomic<FadType, Layout, Device, false>(
MinTag(), out);
379 #define VIEW_FAD_TESTS_FLD( F, L, D ) \ 380 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, AtomicAddFetch, F, L, D ) \ 381 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, AtomicSubFetch, F, L, D ) \ 382 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, AtomicMulFetch, F, L, D ) \ 383 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, AtomicDivFetch, F, L, D ) \ 384 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, AtomicMaxFetch, F, L, D ) \ 385 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, AtomicMinFetch, F, L, D ) \ 386 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, AtomicFetchAdd, F, L, D ) \ 387 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, AtomicFetchSub, F, L, D ) \ 388 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, AtomicFetchMul, F, L, D ) \ 389 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, AtomicFetchDiv, F, L, D ) \ 390 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, AtomicFetchMax, F, L, D ) \ 391 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, AtomicFetchMin, F, L, D ) 393 using Kokkos::LayoutLeft;
394 using Kokkos::LayoutRight;
398 #define VIEW_FAD_TESTS_FD( F, D ) \ 399 VIEW_FAD_TESTS_FLD( F, LayoutLeft, D ) \ 400 VIEW_FAD_TESTS_FLD( F, LayoutRight, D ) \ 401 VIEW_FAD_TESTS_FLD( F, LeftContiguous, D ) \ 402 VIEW_FAD_TESTS_FLD( F, RightContiguous, D ) 405 #if SACADO_ENABLE_NEW_DESIGN 411 #define VIEW_FAD_TESTS_D( D ) \ 412 VIEW_FAD_TESTS_FD( SFadType, D ) \ 413 VIEW_FAD_TESTS_FD( SLFadType, D ) \ 414 VIEW_FAD_TESTS_FD( DFadType, D ) 416 #define VIEW_FAD_TESTS_D( D ) \ 417 VIEW_FAD_TESTS_FD( SFadType, D ) \ 418 VIEW_FAD_TESTS_FD( SLFadType, D ) 423 #define VIEW_FAD_TESTS_D( D ) const int global_num_cols
KOKKOS_INLINE_FUNCTION void operator()(AddTag tag, const size_type i) const
static auto apply(const T1 &a, const T2 &b) -> decltype(a/b)
Kokkos::LayoutContiguous< Kokkos::LayoutRight > RightContiguous
Kokkos::LayoutContiguous< Kokkos::LayoutLeft > LeftContiguous
Kokkos::ThreadLocalScalarType< ViewType >::type local_scalar_type
Sacado::Fad::DFad< double > FadType
ViewType::size_type size_type
const int global_fad_size
AtomicKernel(const ViewType &v, const ScalarViewType &s)
Sacado::Fad::SFad< double, fad_dim > SFadType
static const size_type stride
static auto apply(const T1 &a, const T2 &b) -> decltype(a-b)
const int global_num_rows
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
KOKKOS_INLINE_FUNCTION void operator()(Tag tag, const team_handle &team) const
bool checkFads(const FadType1 &x, const FadType2 &x2, Teuchos::FancyOStream &out, double tol=1.0e-15)
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::TeamPolicy< execution_space >::member_type team_handle
SimpleFad< ValueT > max(const SimpleFad< ValueT > &a, const SimpleFad< ValueT > &b)
ViewType::execution_space execution_space
fadtype generate_fad(const ordinal num_rows, const ordinal num_cols, const ordinal fad_size, const ordinal row, const ordinal col)
TEUCHOS_UNIT_TEST_TEMPLATE_3_DECL(Kokkos_View_Fad, AtomicAddFetch, FadType, Layout, Device)
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))