Sacado Package Browser (Single Doxygen Collection)
Version of the Day
Toggle main menu visibility
Loading...
Searching...
No Matches
test
UnitTests
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.
46
using
Kokkos::Experimental::HIP;
47
VIEW_FAD_TESTS_D
( HIP )
48
49
// Tests special size alignment for SFad on HIP is correct
50
TEUCHOS_UNIT_TEST
(Kokkos_View_Fad, SFadHipAligned)
51
{
52
const
int
StaticDim = 64;
53
const
int
Stride = 32;
54
const
int
LocalDim = 2;
55
typedef
Sacado::Fad::SFad<double,StaticDim>
FadType
;
56
typedef
Kokkos::LayoutContiguous<Kokkos::LayoutLeft,Stride>
Layout;
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
79
TEUCHOS_UNIT_TEST
(Kokkos_View_Fad, SFadHipNotAligned)
80
{
81
const
int
StaticDim = 50;
82
const
int
Stride = 32;
83
const
int
LocalDim = 0;
84
typedef
Sacado::Fad::SFad<double,StaticDim>
FadType
;
85
typedef
Kokkos::LayoutContiguous<Kokkos::LayoutLeft,Stride>
Layout;
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
108
int
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
}
TEUCHOS_UNIT_TEST
TEUCHOS_UNIT_TEST(Conversion, IsConvertible)
Definition
ConversionTests.cpp:54
VIEW_FAD_TESTS_D
#define VIEW_FAD_TESTS_D(D)
Definition
Fad_Fad_KokkosTests.hpp:366
Fad_KokkosTests.hpp
TEUCHOS_UNIT_TEST
TEUCHOS_UNIT_TEST(Kokkos_View_Fad, SFadHipAligned)
Definition
Fad_KokkosTests_HIP.cpp:50
main
int main()
Definition
ad_example.cpp:191
FadType
Sacado::Fad::DFad< double > FadType
Definition
blas_example.cpp:49
Sacado::Fad::SFad
Definition
Sacado_Fad_SFad.hpp:100
Kokkos::LayoutContiguous
Definition
Kokkos_LayoutContiguous.hpp:51
Sacado::StaticSize::value
static const unsigned value
Definition
Sacado_Traits.hpp:435
is_sfad::value
static const bool value
Definition
Fad_KokkosTests.hpp:36
Generated by
1.17.0