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