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  typedef typename ViewType::traits TraitsType;
42  typedef Kokkos::Impl::ViewMapping< TraitsType , typename TraitsType::specialize > MappingType;
43  const int view_static_dim = MappingType::FadStaticDimension;
44  TEUCHOS_TEST_EQUALITY(view_static_dim, StaticDim, out, success);
45 
46  typedef typename Kokkos::ThreadLocalScalarType<ViewType>::type local_fad_type;
47  const bool issfd = is_sfad<local_fad_type>::value;
48  const int static_dim = Sacado::StaticSize<local_fad_type>::value;
49  TEUCHOS_TEST_EQUALITY(issfd, true, out, success);
50  TEUCHOS_TEST_EQUALITY(static_dim, LocalDim, out, success);
51 
52  const size_t num_rows = 11;
53  const size_t fad_size = StaticDim;
54 
55  ViewType v("v", num_rows, fad_size+1);
56  const size_t span = v.span();
57  TEUCHOS_TEST_EQUALITY(span, num_rows*(StaticDim+1), out, success);
58 }
59 
60 TEUCHOS_UNIT_TEST(Kokkos_View_Fad, SFadHipNotAligned)
61 {
62  const int StaticDim = 50;
63  const int Stride = 32;
64  const int LocalDim = 0;
67  typedef Kokkos::HIP Device;
68  typedef Kokkos::View<FadType*,Layout,Device> ViewType;
69 
70  typedef typename ViewType::traits TraitsType;
71  typedef Kokkos::Impl::ViewMapping< TraitsType , typename TraitsType::specialize > MappingType;
72  const int view_static_dim = MappingType::FadStaticDimension;
73  TEUCHOS_TEST_EQUALITY(view_static_dim, StaticDim, out, success);
74 
75  typedef typename Kokkos::ThreadLocalScalarType<ViewType>::type local_fad_type;
76  const bool issfd = is_sfad<local_fad_type>::value;
77  const int static_dim = Sacado::StaticSize<local_fad_type>::value;
78  TEUCHOS_TEST_EQUALITY(issfd, false, out, success);
79  TEUCHOS_TEST_EQUALITY(static_dim, LocalDim, out, success);
80 
81  const size_t num_rows = 11;
82  const size_t fad_size = StaticDim;
83 
84  ViewType v("v", num_rows, fad_size+1);
85  const size_t span = v.span();
86  TEUCHOS_TEST_EQUALITY(span, num_rows*(StaticDim+1), out, success);
87 }
88 
89 int main( int argc, char* argv[] ) {
90  Teuchos::GlobalMPISession mpiSession(&argc, &argv);
91 
92  // Initialize HIP
93  Kokkos::InitializationSettings init_args;
94  init_args.set_device_id(0);
95  Kokkos::initialize( init_args );
96  Kokkos::print_configuration(std::cout);
97 
99 
100  // Finalize HIP
101  Kokkos::finalize();
102 
103  return res;
104 }
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)