-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into feature/gunney/marching-cubes-mask
- Loading branch information
Showing
22 changed files
with
906 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// Copyright (c) 2017-2024, Lawrence Livermore National Security, LLC and | ||
// other Axom Project Developers. See the top-level LICENSE file for details. | ||
// | ||
// SPDX-License-Identifier: (BSD-3-Clause) | ||
|
||
#ifndef AXOM_STATICARRAY_HPP_ | ||
#define AXOM_STATICARRAY_HPP_ | ||
|
||
#include "axom/config.hpp" // for compile-time defines | ||
#include "axom/core/Macros.hpp" // for axom macros | ||
#include "axom/core/StackArray.hpp" // for StackArray | ||
|
||
namespace axom | ||
{ | ||
/*! | ||
* \accelerated | ||
* \class StaticArray | ||
* | ||
* \brief Provides a wrapper for a StackArray with an additional size member. | ||
* | ||
* \tparam T the type of the values to hold. | ||
* \tparam N the number of values in the array. | ||
* | ||
* \note Type \a T must be default-constructible on device for device | ||
* execution. | ||
*/ | ||
template <typename T, int N> | ||
struct StaticArray : public StackArray<T, N> | ||
{ | ||
/*! | ||
* \brief Returns the size of the static array | ||
* | ||
* \return The size of the static array | ||
*/ | ||
AXOM_HOST_DEVICE int size() const { return m_size; } | ||
|
||
/*! | ||
* \brief Pushes an object to the back of the static array | ||
* | ||
* \param [in] obj the object to be added to the back. | ||
* | ||
* \note The number of push_backs must not exceed N, | ||
* the max number of values in the array. | ||
* | ||
* \note If the static array is full, push_back | ||
* will not modify the static array. | ||
*/ | ||
AXOM_HOST_DEVICE void push_back(const T& obj) | ||
{ | ||
assert(m_size < N); | ||
if(m_size < N) | ||
{ | ||
StackArray<T, N>::m_data[m_size++] = obj; | ||
} | ||
} | ||
|
||
/*! | ||
* \brief Clears the data from the static array | ||
*/ | ||
AXOM_HOST_DEVICE void clear() | ||
{ | ||
for(T& datum : StackArray<T, N>::m_data) | ||
{ | ||
datum = T(); | ||
} | ||
m_size = 0; | ||
} | ||
|
||
private: | ||
int m_size {0}; | ||
}; | ||
|
||
} /* namespace axom */ | ||
|
||
#endif /* AXOM_STATICARRAY_HPP_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// Copyright (c) 2017-2024, Lawrence Livermore National Security, LLC and | ||
// other Axom Project Developers. See the top-level LICENSE file for details. | ||
// | ||
// SPDX-License-Identifier: (BSD-3-Clause) | ||
|
||
#include "axom/config.hpp" // for compile time definitions | ||
|
||
#include "axom/core/StaticArray.hpp" | ||
|
||
// for gtest macros | ||
#include "gtest/gtest.h" | ||
|
||
//------------------------------------------------------------------------------ | ||
// HELPER METHOD | ||
//------------------------------------------------------------------------------ | ||
namespace | ||
{ | ||
template <typename ExecSpace> | ||
void check_static_array_policy() | ||
{ | ||
const int MAX_SIZE = 10; | ||
using StaticArrayType = axom::StaticArray<int, MAX_SIZE>; | ||
|
||
// Get ids of necessary allocators | ||
const int host_allocator = axom::execution_space<axom::SEQ_EXEC>::allocatorID(); | ||
const int kernel_allocator = axom::execution_space<ExecSpace>::allocatorID(); | ||
|
||
axom::Array<StaticArrayType> s_arrays_device(MAX_SIZE, | ||
MAX_SIZE, | ||
kernel_allocator); | ||
auto s_arrays_view = s_arrays_device.view(); | ||
|
||
axom::Array<StaticArrayType> sizes_device(1, 1, kernel_allocator); | ||
auto sizes_view = sizes_device.view(); | ||
|
||
axom::for_all<ExecSpace>( | ||
MAX_SIZE, | ||
AXOM_LAMBDA(int i) { | ||
// Sanity check - function is callable on device | ||
s_arrays_view[i].clear(); | ||
|
||
for(int idx = 0; idx <= i; idx++) | ||
{ | ||
s_arrays_view[i].push_back(idx); | ||
} | ||
|
||
sizes_view[0][i] = s_arrays_view[i].size(); | ||
}); | ||
|
||
// Copy static arrays and their sizes back to host | ||
axom::Array<StaticArrayType> s_arrays_host = | ||
axom::Array<StaticArrayType>(s_arrays_device, host_allocator); | ||
axom::Array<StaticArrayType> sizes_host = | ||
axom::Array<StaticArrayType>(sizes_device, host_allocator); | ||
|
||
// Verify values | ||
for(int i = 0; i < MAX_SIZE; i++) | ||
{ | ||
EXPECT_EQ(sizes_host[0][i], i + 1); | ||
for(int j = 0; j <= i; j++) | ||
{ | ||
EXPECT_EQ(s_arrays_host[i][j], j); | ||
} | ||
} | ||
} | ||
|
||
} /* end anonymous namespace */ | ||
|
||
//------------------------------------------------------------------------------ | ||
// UNIT TESTS | ||
//------------------------------------------------------------------------------ | ||
|
||
//------------------------------------------------------------------------------ | ||
TEST(core_static_array, check_static_array_seq) | ||
{ | ||
check_static_array_policy<axom::SEQ_EXEC>(); | ||
} | ||
|
||
#if defined(AXOM_USE_OPENMP) && defined(AXOM_USE_RAJA) | ||
TEST(core_static_array, check_static_array_omp) | ||
{ | ||
check_static_array_policy<axom::OMP_EXEC>(); | ||
} | ||
#endif | ||
|
||
#if defined(AXOM_USE_CUDA) && defined(AXOM_USE_RAJA) && defined(AXOM_USE_UMPIRE) | ||
TEST(core_static_array, check_static_array_cuda) | ||
{ | ||
check_static_array_policy<axom::CUDA_EXEC<256>>(); | ||
check_static_array_policy<axom::CUDA_EXEC<256, axom::ASYNC>>(); | ||
} | ||
#endif | ||
|
||
#if defined(AXOM_USE_HIP) && defined(AXOM_USE_RAJA) && defined(AXOM_USE_UMPIRE) | ||
TEST(core_static_array, check_static_array_hip) | ||
{ | ||
check_static_array_policy<axom::HIP_EXEC<256>>(); | ||
check_static_array_policy<axom::HIP_EXEC<256, axom::ASYNC>>(); | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.