6#include <Kokkos_Core.hpp>
27template<
typename ValueType>
44 [&ptr,
size](
const auto& concreteExec)
45 { ptr = concreteExec.alloc(
static_cast<size_t>(
size) *
sizeof(ValueType)); },
48 data_ =
static_cast<ValueType*
>(ptr);
64 : size_(
size), data_(nullptr), exec_(
exec)
68 [&ptr,
size](
const auto& concreteExec)
69 { ptr = concreteExec.alloc(
static_cast<size_t>(
size) *
sizeof(ValueType)); },
72 data_ =
static_cast<ValueType*
>(ptr);
84 : size_(
size), data_(nullptr), exec_(
exec)
88 [&ptr,
size](
const auto& execu)
89 { ptr = execu.alloc(
static_cast<size_t>(
size) *
sizeof(ValueType)); },
92 data_ =
static_cast<ValueType*
>(ptr);
137 std::visit([
this](
const auto&
exec) {
exec.free(data_); }, exec_);
146 template<
typename func>
159 if (dstExec == exec_)
return *
this;
184 result.
size() == size_,
"Parsed Array size not the same as current field size"
213 NF_ASSERT(exec_ == rhs.exec_,
"Executors are not the same");
231 [
this, &ptr,
size](
const auto&
exec)
232 { ptr =
exec.realloc(this->data_,
static_cast<size_t>(
size) *
sizeof(ValueType)); },
240 { ptr =
exec.alloc(
static_cast<size_t>(
size) *
sizeof(ValueType)); },
244 data_ =
static_cast<ValueType*
>(ptr);
252 [[nodiscard]]
inline ValueType*
data() {
return data_; }
258 [[nodiscard]]
inline const ValueType*
data()
const {
return data_; }
282 [[nodiscard]]
inline bool empty()
const {
return size() == 0; }
340 [[nodiscard]]
inline std::pair<localIdx, localIdx>
range()
const {
return {0,
size()}; }
345 ValueType* data_ {
nullptr};
352 void validateOtherArray(
const Array<ValueType>& rhs)
const
A class to contain the data and executors for a field and define some basic operations.
Array(const Executor &exec, localIdx size, ValueType value)
Create a Array with a given size on an executor and uniform value.
const ValueType * data() const
Direct access to the underlying field data.
View< ValueType > view() &&=delete
Array< ValueType > copyToHost() const
Returns a copy of the field back to the host.
void copyToHost(Array< ValueType > &result)
Copies the data (from anywhere) to a parsed host field.
View< ValueType > view(std::pair< localIdx, localIdx > range) &
Gets a sub view of the field as a view.
std::pair< localIdx, localIdx > range() const
Gets the range of the field.
Array(Array< ValueType > &&rhs) noexcept
Move constructor, moves the data from the parsed field to the new field.
Array(const Executor &exec, localIdx size)
Create an uninitialized Array with a given size on an executor.
Array< ValueType > copyToExecutor(Executor dstExec) const
Copies the data to a new field on a specific executor.
View< const ValueType > view() const &
Gets the field as a view.
label ssize() const
Gets the size of the field.
void operator=(const ValueType &rhs)
Assignment operator, Sets the field values to that of the passed value.
const Array & operator[](const localIdx i) const =delete
View< const ValueType > view(std::pair< localIdx, localIdx > range) const &
Gets a sub view of the field as a view.
localIdx size() const
Gets the size of the field.
bool empty() const
Checks if the field is empty.
const Executor & exec() const
Gets the executor associated with the field.
View< const ValueType > view() const &&=delete
Array(const Executor &exec, std::vector< ValueType > in)
Create a Array from a given Array of values on an executor.
Array & operator[](const localIdx i)=delete
~Array()
Destroy the Array object.
Array(const Executor &exec, const Array< ValueType > &in)
Create a Array as a copy of a Array on a specified executor.
Array(const Array< ValueType > &rhs)
Copy constructor, creates a new field with the same size and data as the parsed field.
Array(const Executor &exec, const ValueType *in, localIdx size, Executor hostExec=SerialExecutor())
Create a Array with a given size from existing memory on an executor.
View< ValueType > view(std::pair< localIdx, localIdx > range) &&=delete
void operator=(const Array< ValueType > &rhs)
Assignment operator, Sets the field values to that of the parsed field.
View< const ValueType > view(std::pair< localIdx, localIdx > range) const &&=delete
void resize(const localIdx size)
Resizes the field to a new size.
void apply(func f)
applies a functor, transformation, to the field
ValueType * data()
Direct access to the underlying field data.
Reference executor for serial CPU execution.
#define NF_ERROR_EXIT(message)
Macro for printing an error message and aborting the program.
#define NF_ASSERT(condition, message)
Macro for asserting a condition and printing an error message if the condition is false.
#define NF_DEBUG_ASSERT(condition, message)
Macro for asserting a condition and printing an error message if the condition is false (only in debu...
auto deepCopyVisitor(localIdx ssize, const ValueType *srcPtr, ValueType *dstPtr)
A helper function to simplify the common pattern of copying between and to executor.
void map(ContType< ValueType > &cont, const Inner inner, std::pair< localIdx, localIdx > range={0, 0})
Map a field using a specific executor.
std::variant< SerialExecutor, CPUExecutor, GPUExecutor > Executor
void setContainer(ContType< ValueType > &cont, const View< const std::type_identity_t< ValueType > > view, std::pair< localIdx, localIdx > range={0, 0})
Set the container with a view of values using a specific executor.
void fill(ContType< ValueType > &cont, const std::type_identity_t< ValueType > value, std::pair< localIdx, localIdx > range={0, 0})
Fill the field with a vector value using a specific executor.