Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
f772bb1
Begin refactor
adayton1 Mar 18, 2025
716ab2e
Merge branch 'develop' into feature/dayton8/strategy_pattern
adayton1 Mar 21, 2025
c91d68a
Set up skeleton of ManagedArray
adayton1 Mar 21, 2025
570d799
Add an ArrayManager class
adayton1 Mar 21, 2025
c02e4c1
Clean up
adayton1 Mar 21, 2025
8372534
Add CopyHidingManager
adayton1 Mar 21, 2025
7fc63b2
Add PinnedManager
adayton1 Mar 21, 2025
123a437
Update method to include touch argument
adayton1 Mar 21, 2025
6d7abd6
Add PageableManager
adayton1 Mar 21, 2025
283fbf8
Add new files to build system
adayton1 Mar 21, 2025
7262fe0
Get HostManager tests functioning
adayton1 Mar 31, 2025
5ae9eff
Refactor HostManager tests
adayton1 Mar 31, 2025
844d886
Update CopyHidingManager and tests
adayton1 Mar 31, 2025
4676ed2
Add more test cases
adayton1 Mar 31, 2025
d72a12c
Update tests
adayton1 May 20, 2025
c056495
Merge branch 'develop' into feature/dayton8/strategy_pattern
adayton1 May 23, 2025
99aa352
More updates
adayton1 May 29, 2025
ef548c5
Updates
adayton1 Jun 23, 2025
3edb839
Merge branch 'develop' into feature/dayton8/strategy_pattern
adayton1 Aug 4, 2025
5a4d58f
Updates to CopyHidingManager
adayton1 Aug 11, 2025
e9aa9eb
Rename CopyHidingManager to CopyHidingArrayManager
adayton1 Aug 11, 2025
c2f2806
Update Array implementation
adayton1 Aug 11, 2025
7cd54a3
Simplify Manager interface
adayton1 Aug 11, 2025
829fbb8
Clean up CopyHidingArrayManager
adayton1 Aug 12, 2025
46d7f40
Add test file for CopyHidingArrayManager
adayton1 Aug 12, 2025
1f89b4c
Add more functionality to Array
adayton1 Aug 15, 2025
5233f7b
Add host device implementation of std::span
adayton1 Aug 15, 2025
e133d05
Rename Manager to ArrayManager
adayton1 Aug 15, 2025
88b2c95
Add Context enum
adayton1 Aug 15, 2025
7e10182
Add ContextManager class
adayton1 Aug 15, 2025
cbd69e2
Update ArrayManager interface
adayton1 Aug 15, 2025
d438e7d
Inline CopyHidingArrayManager implementation
adayton1 Aug 16, 2025
eaf272a
Rename Array to ManagedArray
adayton1 Aug 16, 2025
f6e6d35
Add get and set methods
adayton1 Aug 16, 2025
2d1981b
Remove CopyHidingArrayManager.cpp
adayton1 Aug 16, 2025
7dfa1fe
Some clean up
adayton1 Aug 16, 2025
f3ec2bf
Clean up ManagedArray
adayton1 Aug 18, 2025
2c1def2
Rename to ExecutionContext and ExecutionContextManager
adayton1 Aug 18, 2025
4e3eb54
Add ExecutionContextManager tests
adayton1 Aug 18, 2025
fdd7482
Clean up
adayton1 Aug 18, 2025
671615d
Clean up cmake
adayton1 Aug 18, 2025
d6109b2
Get ExecutionContextManager tests to build
adayton1 Aug 18, 2025
7f09c14
Add testing
adayton1 Aug 19, 2025
4de1366
Clean up PinnedArrayContainer class
adayton1 Aug 29, 2025
2fb4b4b
Add UnifiedMemoryArray
adayton1 Aug 29, 2025
5387d31
Rename types
adayton1 Aug 30, 2025
f7c6391
Update UnifiedMemoryPointer
adayton1 Sep 2, 2025
aa06e0d
Add UnifiedMemoryManager
adayton1 Sep 3, 2025
3de1ea7
Add NullArrayManager
adayton1 Sep 8, 2025
4f795fd
Clean up ManagedArray
adayton1 Sep 8, 2025
9241899
Add converting constructor to ManagedArray
adayton1 Sep 9, 2025
099070b
More changes
adayton1 Sep 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmake/SetupChaiOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ option(CHAI_ENABLE_MANAGED_PTR "Enable managed_ptr" On)
option(CHAI_DEBUG "Enable Debug Logging." Off)
option(CHAI_ENABLE_RAJA_NESTED_TEST "Enable raja-chai-nested-tests, which fails to build on Debug CUDA builds." On)
option(CHAI_ENABLE_MANAGED_PTR_ON_GPU "Enable managed_ptr on GPU" On)
option(CHAI_ENABLE_EXPERIMENTAL "Enable experimental features" On)

option(CHAI_ENABLE_TESTS "Enable CHAI tests" On)
option(CHAI_ENABLE_BENCHMARKS "Enable benchmarks" Off)
Expand Down
2 changes: 2 additions & 0 deletions host-configs/lc/blueos_3_ppc64le_ib_p9/nvcc_clang.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ set(CMAKE_CUDA_COMPILER "${CUDA_TOOLKIT_ROOT_DIR}/bin/nvcc" CACHE PATH "")
set(CMAKE_CUDA_HOST_COMPILER "${CMAKE_CXX_COMPILER}" CACHE PATH "")
set(CMAKE_CUDA_ARCHITECTURES "70" CACHE STRING "")
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcompiler=--gcc-toolchain=${GCC_HOME}" CACHE STRING "")

set(UMPIRE_FMT_TARGET "fmt::fmt" CACHE STRING "")
4 changes: 2 additions & 2 deletions host-configs/lc/toss_4_x86_64_ib_cray/amdclang.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
##############################################################################

# Set up software versions
set(ROCM_VERSION "6.2.0" CACHE PATH "")
set(GCC_VERSION "12.2.1" CACHE PATH "")
set(ROCM_VERSION "6.4.1" CACHE PATH "")
set(GCC_VERSION "13.3.1" CACHE PATH "")

# Set up compilers
set(COMPILER_BASE "/usr/tce/packages/rocmcc/rocmcc-${ROCM_VERSION}-magic" CACHE PATH "")
Expand Down
7 changes: 7 additions & 0 deletions src/chai/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ set (chai_headers
PointerRecord.hpp
Types.hpp)

if(CHAI_ENABLE_EXPERIMENTAL)
set(chai_headers
${chai_headers}
expt/ExecutionContext.hpp
expt/ExecutionContextManager.hpp)
endif()

if(CHAI_DISABLE_RM)
set(chai_headers
${chai_headers}
Expand Down
77 changes: 77 additions & 0 deletions src/chai/expt/Allocator.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#ifndef CHAI_ALLOCATOR_HPP
#define CHAI_ALLOCATOR_HPP

namespace chai::expt {
class Allocator {
private:
class AllocatorConcept
{
public:
virtual ~AllocatorConcept() = default;
virtual void* do_allocate(std::size_t bytes) = 0;
virtual void do_deallocate(void* ptr) = 0;
virtual std::unique_ptr<AllocatorConcept> clone() const = 0;
}; // class AllocatorConcept

template <typename AllocatorType>
class AllocatorModel : public AllocatorConcept
{
public:
AllocatorModel(AllocatorType allocator)
: m_allocator{std::move(allocator)}
{
}

virtual void* allocate(std::size_t bytes) override
{
return allocate(m_allocator, bytes);
}

virtual void do_deallocate(void* ptr) override
{
deallocate(m_allocator, ptr);
}

virtual std::unique_ptr<AllocatorConcept> clone() const override
{
return std::make_unique<AllocatorModel>(*this);
}

private:
AllocatorType m_allocator;
}; // class AllocatorModel

friend void* allocate(const Allocator& allocator, std::size_t bytes)
{
return allocator.m_pimpl->do_allocate(bytes);
}

friend void deallocate(const Allocator& allocator, void* ptr)
{
allocator.m_pimple->do_deallocate(ptr);
}

std::unique_ptr<AllocatorConcept> m_pimpl;

public:
template <typename AllocatorType>
Allocator(AllocatorType allocator)
: m_pimpl{std::make_unique<AllocatorModel<AllocatorType>>(std::move(allocator))}
{
}

Allocator(const Allocator& other)
: m_pimple{other.m_pimpl->clone()}
{
}

Allocator& operator=(const Allocator& other)
{
Allocator temp(other);
std::swap(m_pimpl, temp.m_pimpl);
return *this;
}
}; // class Allocator
}

#endif // CHAI_ALLOCATOR_HPP
275 changes: 275 additions & 0 deletions src/chai/expt/Array.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,275 @@
#ifndef CHAI_MANAGED_ARRAY_HPP
#define CHAI_MANAGED_ARRAY_HPP

#include "chai/expt/ArrayManager.hpp"
#include "chai/expt/ExecutionContextManager.hpp"
#include <cstddef>

namespace chai {
namespace expt {
/*!
* \class ManagedArray
*
* \brief An array class that manages coherency across the CPU and GPU.
* How the coherence is obtained is controlled by the array manager.
*
* \tparam ElementType The type of element in the array.
*/
template <typename ElementType>
class ManagedArray {
public:
/*!
* \brief Constructs an empty array without an array manager.
*/
ManagedArray() = default;

/*!
* \brief Constructs an array from a manager.
*
* \param manager The array manager controls the coherence of the array.
*
* \note The array takes ownership of the manager.
*/
explicit ManagedArray(ArrayManager<ElementType>* manager)
: m_manager{manager}
{
if (m_manager)
{
m_size = m_manager->size();
}
}

/*!
* \brief Constructs a shallow copy of an array from another and makes
* the data coherent in the current execution space.
*
* \param other The other array.
*
* \note This is a shallow copy.
*/
CHAI_HOST_DEVICE ManagedArray(const ManagedArray& other) :
m_data{other.m_data},
m_size{other.m_size},
m_manager{other.m_manager}
{
#if !defined(CHAI_DEVICE_COMPILE)
if (m_manager) {
m_data = m_manager->data(!std::is_const<ElementType>::value));
}
#endif
}

/*!
* \brief Constructs a ManagedArray<const T> from a ManagedArray<T>.
*
* \param other The non-const array to convert from.
*
* \note This is a converting constructor that enables implicit conversion
* from ManagedArray<T> to ManagedArray<const T>.
*/
template <typename OtherElementType,
std::enable_if_t<std::is_convertible_v<OtherElementType (*)[], ElementType (*)[]>* = nullptr>
CHAI_HOST_DEVICE ManagedArray(const ManagedArray<OtherElementType>& other)
: m_data{other.m_data},
m_size{other.m_size},
m_manager{other.m_manager}
{
}

/*!
* \brief Sets the array manager for this ManagedArray.
*
* \param manager The new array manager to be set.
*
* \post The ManagedArray takes ownership of the new manager objet.
*/
void setManager(ArrayManager<ElementType>* manager)
{
delete m_manager;
m_manager = manager;
}

/*!
* \brief Get the array manager associated with this ManagedArray.
*
* \return A pointer to the array manager.
*/
ArrayManager<ElementType>* getManager() const {
return m_manager;
}

/*!
* \brief Resizes the array to the specified new size.
*
* \param newSize The new size to resize the array to.
*
* \note This method updates the size of the array and triggers a resize operation in the array manager if it exists.
* If no array manager is associated, an exception is thrown.
*/
void resize(std::size_t newSize) {
if (m_manager) {
m_size = newSize;
m_manager->resize(newSize);
}
else {
throw std::runtime_exception("Unable to resize");
}
}

/*!
* \brief Frees the resources associated with this array.
*
* \note Once free has been called, it is invalid to use any other copies
* of this array (since copies are shallow).
*/
void free() {
m_data = nullptr;
m_size = 0;
delete m_manager;
m_manager = nullptr;
}

/*!
* \brief Get the number of elements in the array.
*
* \pre The copy constructor has been called with the execution space
* set to CPU or GPU (e.g. by the RAJA plugin).
*/
CHAI_HOST_DEVICE std::size_t size() const {
return m_size;
}

/*!
* \brief Get a pointer to the element data in the specified context.
*
* \param context The context in which to retrieve the element data.
*
* \return A pointer to the element data in the specified context.
*/
ElementType* data(ExecutionContext context) const {
if (m_manager) {
m_data = m_manager->data(context, !std::is_const<ElementType>::value);
}

return m_data;
}

/*!
* \brief Get a const pointer to the element data in the specified context.
*
* \param context The context in which to retrieve the const element data.
*
* \return A const pointer to the element data in the specified context.
*/
const ElementType* cdata(ExecutionContext context) const {
if (m_manager) {
m_data = m_manager->data(context, false);
}

return m_data;
}

/*!
* \brief Get a pointer to the element data in the current execution space.
*
* \return A pointer to the element data in the current execution space.
*/
CHAI_HOST_DEVICE ElementType* data() const {
#if !defined(CHAI_DEVICE_COMPILE)
return data(HOST);
#endif
return m_data;
}

/*!
* \brief Get a const pointer to the element data in the current execution space.
*
* \return A const pointer to the element data in the current execution space.
*/
CHAI_HOST_DEVICE const ElementType* cdata() const {
#if !defined(CHAI_DEVICE_COMPILE)
return cdata(HOST);
#endif
return m_data;
}

/*!
* \brief Get the ith element in the array.
*
* \param i The index of the element to retrieve.
*
* \pre The copy constructor has been called with the execution space
* set to CPU or GPU (e.g. by the RAJA plugin).
*/
CHAI_HOST_DEVICE ElementType& operator[](std::size_t i) const {
return m_data[i];
}

/*!
* \brief Get the value of the element at the specified index.
*
* \param i The index of the element to retrieve.
*
* \return The value of the element at the specified index.
*
* \throw std::runtime_exception if unable to retrieve the element.
*/
ElementType get(std::size_t i) const {
if (m_manager) {
return m_manager->get(i);
}
else {
throw std::runtime_exception("Unable to get element");
}
}

/*!
* \brief Set a value at a specified index in the array.
*
* \param i The index where the value is to be set.
* \param value The value to set at the specified index.
*
* \throw std::runtime_exception if the array manager is not associated with the ManagedArray.
*/
void set(std::size_t i, const ElementType& value) {
if (m_manager) {
m_manager->set(i, value);
}
else {
throw std::runtime_exception("Unable to set element");
}
}

private:
/*!
* The array that is coherent in the current execution space.
*/
ElementType* m_data = nullptr;

/*!
* The number of elements in the array.
*/
std::size_t m_size = 0;

/*!
* The array manager controls the coherence of the array.
*/
ArrayManager<ElementType>* m_manager = nullptr;
}; // class ManagedArray

/*!
* \brief Constructs an array by creating a new manager object.
*
* \tparam ArrayManager<ElementType> The type of array manager.
* \tparam Args The type of the arguments used to construct the array manager.
*
* \param args The arguments to construct an array manager.
*/
template <typename ElementType, typename ArrayManager<ElementType>, typename... Args>
ManagedArray<ElementType> makeArray(Args&&... args) {
return ManagedArray<ElementType>(new ArrayManager<ElementType>(std::forward<Args>(args)...));
}
} // namespace expt
} // namespace chai

#endif // CHAI_MANAGED_ARRAY_HPP
Loading
Loading