Skip to content

Commit 100b018

Browse files
committed
Managed Vector Unit tests running on AMD GPUs
1 parent 9e57838 commit 100b018

File tree

10 files changed

+27
-62
lines changed

10 files changed

+27
-62
lines changed

cmake/SetupSpheral.cmake

+2
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ endif()
180180
# Build C++ tests and install tests to install directory
181181
#-------------------------------------------------------------------------------
182182
if (ENABLE_TESTS)
183+
add_subdirectory(${SPHERAL_ROOT_DIR}/tests)
184+
183185
spheral_install_python_tests(${SPHERAL_ROOT_DIR}/tests/ ${SPHERAL_TEST_INSTALL_PREFIX})
184186
# Always install performance.py in the top of the testing script
185187
install(FILES ${SPHERAL_ROOT_DIR}/tests/performance.py

extern/chai

Submodule chai updated 113 files

scripts/spack/packages/spheral/package.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ class Spheral(CachedCMakePackage, CudaPackage, ROCmPackage):
5656
depends_on('[email protected] +shared +hdf5~hdf5_compat -test ~parmetis', type='build')
5757

5858
depends_on('[email protected] +hdf5 -lua -examples -python -fortran', type='build')
59-
depends_on('axom +shared', when='~cuda', type='build')
6059
depends_on('axom ~shared', when='+cuda', type='build')
60+
depends_on('axom ~shared', when='+rocm', type='build')
6161

6262
depends_on('[email protected] ~shared +adiak +gotcha ~libdw ~papi ~libunwind +pic', type='build')
6363

src/Utilities/ManagedVector.hh

+6-58
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ namespace Spheral {
3232
#endif
3333

3434

35-
36-
//#define MV_VALUE_SEMANTICS
37-
3835
template<typename DataType>
3936
class ManagedVector;
4037

@@ -72,94 +69,52 @@ public:
7269
{
7370
#if !defined(SPHERAL_GPU_ACTIVE)
7471
setCallback();
75-
7672
#endif // SPHERAL_GPU_ACTIVE
7773
}
7874

79-
SPHERAL_HOST_DEVICE ManagedVector(size_t elems) :
75+
SPHERAL_HOST ManagedVector(size_t elems) :
8076
MA(),
8177
m_size(elems)
8278
{
83-
#if !defined(SPHERAL_GPU_ACTIVE)
8479
MA::allocate(m_size < initial_capacity ? initial_capacity: pow2_ceil(m_size), chai::CPU, getCallback());
8580
for (size_t i = 0; i < m_size; i++) new (&MA::operator[](i)) DataType();
8681
MA::registerTouch(chai::CPU);
87-
#endif // SPHERAL_GPU_ACTIVE
8882
}
8983

9084
SPHERAL_HOST ManagedVector(size_t elems, DataType identity) :
9185
MA(),
9286
m_size(elems)
9387
{
94-
#if !defined(SPHERAL_GPU_ACTIVE)
9588
MA::allocate(m_size < initial_capacity ? initial_capacity: pow2_ceil(m_size), chai::CPU, getCallback());
9689
for (size_t i = 0; i < m_size; i++) new (&MA::operator[](i)) DataType(identity);
9790
MA::registerTouch(chai::CPU);
98-
#endif // SPHERAL_GPU_ACTIVE
9991
}
10092

101-
#ifdef MV_VALUE_SEMANTICS
102-
// ---------------------
103-
// Destructor
104-
// ---------------------
105-
SPHERAL_HOST ~ManagedVector()
106-
{
107-
MA::free();
108-
}
109-
#endif
11093
using MA::move;
11194
using MA::free;
11295

11396
// ---------------------
11497
// Copy Constructor
11598
// ---------------------
116-
#ifdef MV_VALUE_SEMANTICS
117-
SPHERAL_HOST_DEVICE constexpr inline ManagedVector(ManagedVector const& rhs) noexcept :
118-
ManagedVector(rhs.m_size)
119-
{printf("MV Copy w/ Value Semantics.\n");
120-
for (size_t i = 0; i < m_size; i++) new (&MA::operator[](i)) DataType(rhs[i]);
121-
}
122-
#else
12399
SPHERAL_HOST_DEVICE constexpr inline ManagedVector(ManagedVector const& rhs) noexcept : MA(rhs), m_size(rhs.m_size) {}
124-
#endif
125100

126101
// ---------------------
127102
// Assignment
128103
// ---------------------
129-
#ifdef MV_VALUE_SEMANTICS
130-
SPHERAL_HOST_DEVICE ManagedVector<DataType>& operator=(ManagedVector const& rhs) {
131-
if (capacity() != rhs.capacity()) MA::reallocate(rhs.capacity());
132-
m_size = rhs.m_size;
133-
for (size_t i = 0; i < m_size; i++) new (&MA::operator[](i)) DataType(rhs[i]);
134-
return *this;
135-
}
136-
#else
137104
SPHERAL_HOST_DEVICE ManagedVector<DataType>& operator=(ManagedVector const& rhs) {
138105
MA::operator=(rhs);
139106
m_size = rhs.m_size;
140107
return *this;
141108
}
142-
#endif
143109

144110
// ---------------------
145111
// Equivalence
146112
// ---------------------
147-
#ifdef MV_VALUE_SEMANTICS
148-
SPHERAL_HOST bool operator==(ManagedVector const& rhs) const {
149-
if (m_size != rhs.m_size) return false;
150-
for (size_t i = 0; i < m_size; i++) {
151-
if (MA::operator[](i) != rhs[i]) {
152-
return false;
153-
}
154-
}
155-
return true;
156-
}
157-
#else
158113
SPHERAL_HOST_DEVICE bool operator==(ManagedVector const& rhs) const {
159114
if (m_size != rhs.m_size) return false;
160115
return MA::operator==(rhs);
161116
}
162-
#endif
117+
163118
SPHERAL_HOST_DEVICE bool operator!=(ManagedVector const& rhs) const {
164119
return !(*this == rhs);
165120
}
@@ -174,10 +129,10 @@ public:
174129
SPHERAL_HOST void push_back(DataType&& value) {
175130
if (capacity() == 0) MA::allocate(initial_capacity, chai::CPU, getCallback());
176131
if (m_size >= capacity()) MA::reallocate(pow2_ceil(m_size + 1));
177-
//MA::operator[](m_size) = std::move(value);
178132
new(&MA::operator[](m_size)) DataType(value);
179133
m_size++;
180134
}
135+
181136
template<typename... Args>
182137
SPHERAL_HOST
183138
DataType& emplace_back(Args&&... args) {
@@ -330,21 +285,14 @@ inline
330285
ManagedVector<U> deepCopy(ManagedVector<U> const& array)
331286
{
332287
ManagedVector<U> copy(array.size());
333-
for (size_t i = 0; i < array.size(); i++) new (&copy[i]) U(array[i]);
288+
for (size_t i = 0; i < array.size(); i++) {
289+
new (&copy[i]) U(array[i]);
290+
}
334291
return copy;
335292
}
336293

337294
} // namespace Spheral
338295

339-
//#include "SphArrayInline.hh"
340-
341-
#else
342-
343-
//// Forward declare the SphArrayIterator class.
344-
//namespace Spheral {
345-
// template<typename sph_array_t> class SphArrayIterator ;
346-
//} // namespace Spheral
347-
348296
#endif // __Spheral_lvarray_hh__
349297

350298

src/config.hh.in

+5
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,13 @@
88
#cmakedefine SPHERAL_ENABLE_OPENMP
99

1010
#cmakedefine SPHERAL_ENABLE_CUDA
11+
#cmakedefine SPHERAL_ENABLE_HIP
1112
#cmakedefine SPHERAL_ENABLE_VVI
1213

14+
#if defined(SPHERAL_ENABLE_HIP) && defined(__HIPCC__)
15+
#define SPHERAL_GPU_ACTIVE
16+
#endif // SPHERAL_ENABLE_CUDA && __CUDACC__
17+
1318
#if defined(SPHERAL_ENABLE_CUDA) && defined(__CUDA_ARCH__)
1419
#define SPHERAL_GPU_ACTIVE
1520
#endif // SPHERAL_ENABLE_CUDA && __CUDACC__

tests/CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
add_subdirectory(cpp/Field)
22
add_subdirectory(cpp/Utilities)
3-
add_subdirectory(unit)

tests/cpp/Utilities/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ spheral_add_test(
88
spheral_add_test(
99
NAME managed_vector_tests
1010
SOURCES managed_vector_tests.cc
11+
DEBUG_LINKER
1112
)
1213

1314

tests/cpp/Utilities/managed_vector_tests.cc

+7-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ template<typename T>
1414
class ManagedVectorTypedTest : public::testing::Test {};
1515

1616
// All ManagedVectorTets cases will run over each type in EXEC_TYPES.
17-
TYPED_TEST_SUITE(ManagedVectorTypedTest, EXEC_TYPES,);
17+
TYPED_TEST_CASE(ManagedVectorTypedTest, EXEC_TYPES);
1818

1919

2020
GPU_TYPED_TEST(ManagedVectorTypedTest, DefaultConstructor)
@@ -43,6 +43,9 @@ TEST(ManagedVectorTest, SizeConstructor)
4343
MVDouble array2(MVDouble::initial_capacity + 1);
4444
SPHERAL_ASSERT_EQ(array2.size(), MVDouble::initial_capacity + 1);
4545
SPHERAL_ASSERT_EQ(array2.capacity(), MVDouble::initial_capacity * 2);
46+
47+
array.free();
48+
array2.free();
4649
}
4750

4851

@@ -56,6 +59,7 @@ TEST(ManagedVectorTest, IdentityConstructor)
5659
for(auto& elem: array){
5760
SPHERAL_ASSERT_EQ(elem, 5);
5861
}
62+
array.free();
5963
}
6064

6165

@@ -80,6 +84,8 @@ GPU_TYPED_TEST(ManagedVectorTypedTest, IdentityConstructor)
8084
}
8185
);
8286

87+
array.free();
88+
array2.free();
8389
}
8490

8591

tests/cpp/include/test-basic-exec-policies.hh

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ using EXEC_TYPES = ::testing::Types<
1010
#ifdef SPHERAL_ENABLE_CUDA
1111
,RAJA::cuda_exec<512>
1212
#endif
13+
,RAJA::hip_exec<512>
1314
>;
1415

1516

tests/cpp/include/test-utilities.hh

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ using LOOP_EXEC_POLICY = RAJA::seq_exec;
1616
#define EXEC_IN_SPACE_END() \
1717
});
1818

19+
//#if defined(SPHERAL_ENABLE_HIP) && defined(__HIPCC__)
20+
#define SPHERAL_GPU_ACTIVE
21+
//#endif // SPHERAL_ENABLE_CUDA && __CUDACC__
1922

2023
template<typename T, typename U>
2124
inline

0 commit comments

Comments
 (0)