Sacado Package Browser (Single Doxygen Collection) Version of the Day
Loading...
Searching...
No Matches
Fad_KokkosTests_HIP.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
29#include "Teuchos_UnitTestHarness.hpp"
30#include "Teuchos_UnitTestRepository.hpp"
31#include "Teuchos_GlobalMPISession.hpp"
32
33#include "Kokkos_Macros.hpp"
34
35// Temporarily disable DFad testing on HIP. HIP does not support "new"
36// on device so temporary allocations don't work.
37#ifdef KOKKOS_ENABLE_HIP
38#define SACADO_TEST_DFAD 0
39#else
40#define SACADO_TEST_DFAD 1
41#endif
42
43#include "Fad_KokkosTests.hpp"
44
45// Instantiate tests for HIP device. DFAD is disabled since HIP doesn't support UVM.
46using Kokkos::Experimental::HIP;
48
49// Tests special size alignment for SFad on HIP is correct
50TEUCHOS_UNIT_TEST(Kokkos_View_Fad, SFadHipAligned)
51{
52 const int StaticDim = 64;
53 const int Stride = 32;
54 const int LocalDim = 2;
57 typedef Kokkos::Experimental::HIP Device;
58 typedef Kokkos::View<FadType*,Layout,Device> ViewType;
59
60 typedef typename ViewType::traits TraitsType;
61 typedef Kokkos::Impl::ViewMapping< TraitsType , typename TraitsType::specialize > MappingType;
62 const int view_static_dim = MappingType::FadStaticDimension;
63 TEUCHOS_TEST_EQUALITY(view_static_dim, StaticDim, out, success);
64
65 typedef typename Kokkos::ThreadLocalScalarType<ViewType>::type local_fad_type;
66 const bool issfd = is_sfad<local_fad_type>::value;
67 const int static_dim = Sacado::StaticSize<local_fad_type>::value;
68 TEUCHOS_TEST_EQUALITY(issfd, true, out, success);
69 TEUCHOS_TEST_EQUALITY(static_dim, LocalDim, out, success);
70
71 const size_t num_rows = 11;
72 const size_t fad_size = StaticDim;
73
74 ViewType v("v", num_rows, fad_size+1);
75 const size_t span = v.span();
76 TEUCHOS_TEST_EQUALITY(span, num_rows*(StaticDim+1), out, success);
77}
78
79TEUCHOS_UNIT_TEST(Kokkos_View_Fad, SFadHipNotAligned)
80{
81 const int StaticDim = 50;
82 const int Stride = 32;
83 const int LocalDim = 0;
86 typedef Kokkos::Experimental::HIP Device;
87 typedef Kokkos::View<FadType*,Layout,Device> ViewType;
88
89 typedef typename ViewType::traits TraitsType;
90 typedef Kokkos::Impl::ViewMapping< TraitsType , typename TraitsType::specialize > MappingType;
91 const int view_static_dim = MappingType::FadStaticDimension;
92 TEUCHOS_TEST_EQUALITY(view_static_dim, StaticDim, out, success);
93
94 typedef typename Kokkos::ThreadLocalScalarType<ViewType>::type local_fad_type;
95 const bool issfd = is_sfad<local_fad_type>::value;
96 const int static_dim = Sacado::StaticSize<local_fad_type>::value;
97 TEUCHOS_TEST_EQUALITY(issfd, false, out, success);
98 TEUCHOS_TEST_EQUALITY(static_dim, LocalDim, out, success);
99
100 const size_t num_rows = 11;
101 const size_t fad_size = StaticDim;
102
103 ViewType v("v", num_rows, fad_size+1);
104 const size_t span = v.span();
105 TEUCHOS_TEST_EQUALITY(span, num_rows*(StaticDim+1), out, success);
106}
107
108int main( int argc, char* argv[] ) {
109 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
110
111 // Initialize HIP
112 Kokkos::InitializationSettings init_args;
113 init_args.set_device_id(0);
114 Kokkos::initialize( init_args );
115 Kokkos::print_configuration(std::cout);
116
117 int res = Teuchos::UnitTestRepository::runUnitTestsFromMain(argc, argv);
118
119 // Finalize HIP
120 Kokkos::finalize();
121
122 return res;
123}
#define VIEW_FAD_TESTS_D(D)
TEUCHOS_UNIT_TEST(Kokkos_View_Fad, SFadHipAligned)
int main()
Sacado::Fad::DFad< double > FadType
Fad specializations for Teuchos::BLAS wrappers.
Base template specification for static size.