Sacado Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Fad_KokkosTests_HIP.cpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Sacado Package
4 //
5 // Copyright 2006 NTESS and the Sacado contributors.
6 // SPDX-License-Identifier: LGPL-2.1-or-later
7 // *****************************************************************************
8 // @HEADER
9 
13 
14 #include "Kokkos_Macros.hpp"
15 
16 // Temporarily disable DFad testing on HIP. HIP does not support "new"
17 // on device so temporary allocations don't work.
18 #ifdef KOKKOS_ENABLE_HIP
19 #define SACADO_TEST_DFAD 0
20 #else
21 #define SACADO_TEST_DFAD 1
22 #endif
23 
24 #include "Fad_KokkosTests.hpp"
25 
26 // Instantiate tests for HIP device. DFAD is disabled since HIP doesn't support UVM.
27 using Kokkos::HIP;
28 VIEW_FAD_TESTS_D( HIP )
29 
30 // Tests special size alignment for SFad on HIP is correct
31 TEUCHOS_UNIT_TEST(Kokkos_View_Fad, SFadHipAligned)
32 {
33  const int StaticDim = 64;
34  const int Stride = 32;
35  const int LocalDim = 2;
38  typedef Kokkos::HIP Device;
39  typedef Kokkos::View<FadType*,Layout,Device> ViewType;
40 
41  #ifndef SACADO_HAS_NEW_KOKKOS_VIEW_IMPL
42  typedef typename ViewType::traits TraitsType;
43  typedef Kokkos::Impl::ViewMapping< TraitsType , typename TraitsType::specialize > MappingType;
44  const int view_static_dim = MappingType::FadStaticDimension;
45  TEUCHOS_TEST_EQUALITY(view_static_dim, StaticDim, out, success);
46  #endif
47 
48  typedef typename Kokkos::ThreadLocalScalarType<ViewType>::type local_fad_type;
49  const bool issfd = is_sfad<local_fad_type>::value;
50  const int static_dim = Sacado::StaticSize<local_fad_type>::value;
51  TEUCHOS_TEST_EQUALITY(issfd, true, out, success);
52  TEUCHOS_TEST_EQUALITY(static_dim, LocalDim, out, success);
53 
54  const size_t num_rows = 11;
55  const size_t fad_size = StaticDim;
56 
57  ViewType v("v", num_rows, fad_size+1);
58  const size_t span = v.span();
59  // This doesn't make sense really - span is number of elements not subelements
60  #ifndef SACADO_HAS_NEW_KOKKOS_VIEW_IMPL
61  TEUCHOS_TEST_EQUALITY(span, num_rows*(StaticDim+1), out, success);
62  #else
63  TEUCHOS_TEST_EQUALITY(span, num_rows, out, success);
64  #endif
65 }
66 
67 TEUCHOS_UNIT_TEST(Kokkos_View_Fad, SFadHipNotAligned)
68 {
69  const int StaticDim = 50;
70  const int Stride = 32;
71  const int LocalDim = 0;
74  typedef Kokkos::HIP Device;
75  typedef Kokkos::View<FadType*,Layout,Device> ViewType;
76 
77  #ifndef SACADO_HAS_NEW_KOKKOS_VIEW_IMPL
78  typedef typename ViewType::traits TraitsType;
79  typedef Kokkos::Impl::ViewMapping< TraitsType , typename TraitsType::specialize > MappingType;
80  const int view_static_dim = MappingType::FadStaticDimension;
81  TEUCHOS_TEST_EQUALITY(view_static_dim, StaticDim, out, success);
82  #endif
83 
84  typedef typename Kokkos::ThreadLocalScalarType<ViewType>::type local_fad_type;
85  const bool issfd = is_sfad<local_fad_type>::value;
86  const int static_dim = Sacado::StaticSize<local_fad_type>::value;
87  TEUCHOS_TEST_EQUALITY(issfd, false, out, success);
88  TEUCHOS_TEST_EQUALITY(static_dim, LocalDim, out, success);
89 
90  const size_t num_rows = 11;
91  const size_t fad_size = StaticDim;
92 
93  ViewType v("v", num_rows, fad_size+1);
94  const size_t span = v.span();
95  // This doesn't make sense really - span is number of elements not subelements
96  #ifndef SACADO_HAS_NEW_KOKKOS_VIEW_IMPL
97  TEUCHOS_TEST_EQUALITY(span, num_rows*(StaticDim+1), out, success);
98  #else
99  TEUCHOS_TEST_EQUALITY(span, num_rows, out, success);
100  #endif
101 }
102 
103 int main( int argc, char* argv[] ) {
104  Teuchos::GlobalMPISession mpiSession(&argc, &argv);
105 
106  // Initialize HIP
107  Kokkos::InitializationSettings init_args;
108  init_args.set_device_id(0);
109  Kokkos::initialize( init_args );
110  Kokkos::print_configuration(std::cout);
111 
113 
114  // Finalize HIP
115  Kokkos::finalize();
116 
117  return res;
118 }
Sacado::Fad::DFad< double > FadType
Base template specification for static size.
TEUCHOS_UNIT_TEST(Conversion, IsConvertible)
static int runUnitTestsFromMain(int argc, char *argv[])
int main()
Definition: ad_example.cpp:171
#define TEUCHOS_TEST_EQUALITY(v1, v2, out, success)
#define VIEW_FAD_TESTS_D(D)