Skip to content

Add experimental HostArrayManager#351

Merged
adayton1 merged 11 commits into
developfrom
expt/host_array_manager
Jan 23, 2026
Merged

Add experimental HostArrayManager#351
adayton1 merged 11 commits into
developfrom
expt/host_array_manager

Conversation

@adayton1
Copy link
Copy Markdown
Member

@adayton1 adayton1 commented Jan 23, 2026

This class is the experimental replacement for the thin host only logic contained in ManagedArray.

This class manages a host array. It is designed for use with ManagedArrayPointer.

HostArrayManager performs value initialization of each array element. That is to say, numeric types will be initialized to zero and nontrivial types will be default constructed. In the future, this behavior may change to default initialization for performance reasons, such that numeric types will be left in an indeterminate state and nontrivial types will be default constructed.

HostArrayManager does not rely on ContextManager, so it will behave differently than other array managers. The major difference is that when used with ManagedArrayPointer, the ManagedArrayPointer does not need the update method called or to be copy constructed before it can be used on the host. Since it will not respect the current Context, be extra careful to avoid using it on the device.

#include "chai/expt/HostArrayManager.hpp"
#include "chai/expt/ManagedArrayPointer.hpp"

// It's recommended to use an alias so that it is easy to swap out the array manager.
template <typename T>
using HostArrayManager = ::chai::expt::HostArrayManager<T>;

template <typename T>
using ManagedArrayPointer = ::chai::expt::ManagedArrayPointer<T, HostArrayManager<T>>;

const std::size_t N = 1000000;
ManagedArrayPointer<int> a{HostArrayManager<int>(N)};

for (std::size_t i = 0; i < N; ++i)
{
  a[i] = i;
}

Also note that the implementation of ManagedArrayPointer changed slightly since it was determined that the managers need to be templated on ElementType (for correct initialization of the underlying arrays).

Another slight change is that one of the ManagedArrayPointer constructors changed from taking a pointer to taking the Manager by value. If used with temporaries, no deep copies will be performed.

Also adds a factory function called make to ManagedArrayPointer.

Comment thread src/chai/expt/HostArrayManager.hpp
@adayton1 adayton1 merged commit f7b9d24 into develop Jan 23, 2026
7 of 9 checks passed
@adayton1 adayton1 deleted the expt/host_array_manager branch January 23, 2026 21:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants