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_Cuda.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 #define SACADO_TEST_DFAD 1
17 #include "Fad_KokkosTests.hpp"
18 
19 // Instantiate tests for Cuda device. We can only test DFad is UVM is enabled.
20 using Kokkos::Cuda;
21 VIEW_FAD_TESTS_D( Cuda )
22 
23 // Tests special size alignment for SFad on Cuda is correct
24 TEUCHOS_UNIT_TEST(Kokkos_View_Fad, SFadCudaAligned)
25 {
26  const int StaticDim = 64;
27  const int Stride = 32;
28  const int LocalDim = 2;
31  typedef Kokkos::Cuda Device;
32  typedef Kokkos::View<FadType*,Layout,Device> ViewType;
33 
34 #ifndef SACADO_HAS_NEW_KOKKOS_VIEW_IMPL
35  typedef typename ViewType::traits TraitsType;
36  typedef Kokkos::Impl::ViewMapping< TraitsType , typename TraitsType::specialize > MappingType;
37  const int view_static_dim = MappingType::FadStaticDimension;
38  TEUCHOS_TEST_EQUALITY(view_static_dim, StaticDim, out, success);
39 #endif
40 
41  typedef typename Kokkos::ThreadLocalScalarType<ViewType>::type local_fad_type;
42  const bool issfd = is_sfad<local_fad_type>::value;
43  const int static_dim = Sacado::StaticSize<local_fad_type>::value;
44  TEUCHOS_TEST_EQUALITY(issfd, true, out, success);
45  TEUCHOS_TEST_EQUALITY(static_dim, LocalDim, out, success);
46 
47  const size_t num_rows = 11;
48  const size_t fad_size = StaticDim;
49 
50  ViewType v("v", num_rows, fad_size+1);
51  const size_t span = v.span();
52  // This doesn't make sense really - span is number of elements not subelements
53  #ifdef KOKKOS_ENABLE_IMPL_VIEW_LEGACY
54  TEUCHOS_TEST_EQUALITY(span, num_rows*(StaticDim+1), out, success);
55  #else
56  TEUCHOS_TEST_EQUALITY(span, num_rows, out, success);
57  #endif
58 }
59 
60 TEUCHOS_UNIT_TEST(Kokkos_View_Fad, SFadCudaNotAligned)
61 {
62  const int StaticDim = 50;
63  const int Stride = 32;
64  const int LocalDim = 0;
67  typedef Kokkos::Cuda Device;
68  typedef Kokkos::View<FadType*,Layout,Device> ViewType;
69 
70 #ifndef SACADO_HAS_NEW_KOKKOS_VIEW_IMPL
71  typedef typename ViewType::traits TraitsType;
72  typedef Kokkos::Impl::ViewMapping< TraitsType , typename TraitsType::specialize > MappingType;
73  const int view_static_dim = MappingType::FadStaticDimension;
74  TEUCHOS_TEST_EQUALITY(view_static_dim, StaticDim, out, success);
75 #endif
76 
77  typedef typename Kokkos::ThreadLocalScalarType<ViewType>::type local_fad_type;
78  const bool issfd = is_sfad<local_fad_type>::value;
79  const int static_dim = Sacado::StaticSize<local_fad_type>::value;
80  TEUCHOS_TEST_EQUALITY(issfd, false, out, success);
81  TEUCHOS_TEST_EQUALITY(static_dim, LocalDim, out, success);
82 
83  const size_t num_rows = 11;
84  const size_t fad_size = StaticDim;
85 
86  ViewType v("v", num_rows, fad_size+1);
87  const size_t span = v.span();
88  // This doesn't make sense really - span is number of elements not subelements
89  #ifdef KOKKOS_ENABLE_IMPL_VIEW_LEGACY
90  TEUCHOS_TEST_EQUALITY(span, num_rows*(StaticDim+1), out, success);
91  #else
92  TEUCHOS_TEST_EQUALITY(span, num_rows, out, success);
93  #endif
94 }
95 
96 int main( int argc, char* argv[] ) {
97  Teuchos::GlobalMPISession mpiSession(&argc, &argv);
98 
99  // Initialize Cuda
100  Kokkos::InitializationSettings init_args;
101  init_args.set_device_id(0);
102  Kokkos::initialize( init_args );
103  Kokkos::print_configuration(std::cout);
104 
106 
107  // Finalize Cuda
108  Kokkos::finalize();
109 
110  return res;
111 }
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)