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 //
4 // Sacado Package
5 // Copyright (2006) Sandia Corporation
6 //
7 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8 // the U.S. Government retains certain rights in this software.
9 //
10 // This library is free software; you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as
12 // published by the Free Software Foundation; either version 2.1 of the
13 // License, or (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
23 // USA
24 // Questions? Contact David M. Gay (dmgay@sandia.gov) or Eric T. Phipps
25 // (etphipp@sandia.gov).
26 //
27 // ***********************************************************************
28 // @HEADER
32 
33 #include "Fad_KokkosTests.hpp"
34 
35 #include "Kokkos_Core.hpp"
36 
37 // Instantiate tests for Cuda device. We can only test DFad is UVM is enabled.
38 #if defined(KOKKOS_ENABLE_CUDA_UVM)
39 #define SACADO_TEST_DFAD 1
40 #else
41 #define SACADO_TEST_DFAD 0
42 #endif
43 using Kokkos::Cuda;
44 VIEW_FAD_TESTS_D( Cuda )
45 
46 // Tests special size alignment for SFad on Cuda is correct
47 TEUCHOS_UNIT_TEST(Kokkos_View_Fad, SFadCudaAligned)
48 {
49  const int StaticDim = 64;
50  const int Stride = 32;
51  const int LocalDim = 2;
54  typedef Kokkos::Cuda Device;
55  typedef Kokkos::View<FadType*,Layout,Device> ViewType;
56 
57  typedef typename ViewType::traits TraitsType;
58  typedef Kokkos::Impl::ViewMapping< TraitsType , typename TraitsType::specialize > MappingType;
59  const int view_static_dim = MappingType::FadStaticDimension;
60  TEUCHOS_TEST_EQUALITY(view_static_dim, StaticDim, out, success);
61 
62  typedef typename Kokkos::ThreadLocalScalarType<ViewType>::type local_fad_type;
63  const bool issfd = is_sfad<local_fad_type>::value;
64  const int static_dim = Sacado::StaticSize<local_fad_type>::value;
65  TEUCHOS_TEST_EQUALITY(issfd, true, out, success);
66  TEUCHOS_TEST_EQUALITY(static_dim, LocalDim, out, success);
67 
68  const size_t num_rows = 11;
69  const size_t fad_size = StaticDim;
70 
71  ViewType v("v", num_rows, fad_size+1);
72  const size_t span = v.span();
73  TEUCHOS_TEST_EQUALITY(span, num_rows*(StaticDim+1), out, success);
74 }
75 
76 TEUCHOS_UNIT_TEST(Kokkos_View_Fad, SFadCudaNotAligned)
77 {
78  const int StaticDim = 50;
79  const int Stride = 32;
80  const int LocalDim = 0;
83  typedef Kokkos::Cuda Device;
84  typedef Kokkos::View<FadType*,Layout,Device> ViewType;
85 
86  typedef typename ViewType::traits TraitsType;
87  typedef Kokkos::Impl::ViewMapping< TraitsType , typename TraitsType::specialize > MappingType;
88  const int view_static_dim = MappingType::FadStaticDimension;
89  TEUCHOS_TEST_EQUALITY(view_static_dim, StaticDim, out, success);
90 
91  typedef typename Kokkos::ThreadLocalScalarType<ViewType>::type local_fad_type;
92  const bool issfd = is_sfad<local_fad_type>::value;
93  const int static_dim = Sacado::StaticSize<local_fad_type>::value;
94  TEUCHOS_TEST_EQUALITY(issfd, false, out, success);
95  TEUCHOS_TEST_EQUALITY(static_dim, LocalDim, out, success);
96 
97  const size_t num_rows = 11;
98  const size_t fad_size = StaticDim;
99 
100  ViewType v("v", num_rows, fad_size+1);
101  const size_t span = v.span();
102  TEUCHOS_TEST_EQUALITY(span, num_rows*(StaticDim+1), out, success);
103 }
104 
105 int main( int argc, char* argv[] ) {
106  Teuchos::GlobalMPISession mpiSession(&argc, &argv);
107 
108  // Initialize Cuda
109  Kokkos::InitArguments init_args;
110  init_args.device_id = 0;
111  Kokkos::initialize( init_args );
112  Kokkos::print_configuration(std::cout);
113 
115 
116  // Finalize Cuda
117  Kokkos::finalize();
118 
119  return res;
120 }
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:191
#define TEUCHOS_TEST_EQUALITY(v1, v2, out, success)
#define VIEW_FAD_TESTS_D(D)