Skip to content

Commit

Permalink
1) Pass a config argument from Field down to Array (defaulted to util…
Browse files Browse the repository at this point in the history
…::Config()); 2) Implement the optional host memory pinning and the optional mapping of this pinned memory for faster device memory access
  • Loading branch information
sbrdar authored and wdeconinck committed Apr 29, 2024
1 parent d74086e commit e41689b
Show file tree
Hide file tree
Showing 10 changed files with 360 additions and 206 deletions.
65 changes: 42 additions & 23 deletions src/atlas/array/Array.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,21 @@
#include <memory>
#include <vector>

#include "eckit/config/Parametrisation.h"

#include "atlas/library/config.h"
#include "atlas/util/Config.h"

#include "atlas/util/Object.h"

#include "atlas/array/ArrayDataStore.h"
#include "atlas/array/DataType.h"
#include "atlas/array_fwd.h"

namespace eckit {
class Parametrisation;
}

namespace atlas {
namespace array {

Expand All @@ -40,38 +47,48 @@ class Array : public util::Object {
Array() = default;
virtual ~Array();

static Array* create(array::DataType, const ArrayShape&);
static Array* create(array::DataType, const ArrayShape&, const eckit::Parametrisation& param
= util::Config());

static Array* create(array::DataType, const ArrayShape&, const ArrayLayout&);
static Array* create(array::DataType, const ArrayShape&, const ArrayLayout&,
const eckit::Parametrisation& param = util::Config());

static Array* create(array::DataType, ArraySpec&&);
static Array* create(array::DataType, ArraySpec&&,
const eckit::Parametrisation& param = util::Config());

static Array* create(ArraySpec&&);
static Array* create(ArraySpec&&,
const eckit::Parametrisation& param = util::Config());

virtual size_t footprint() const = 0;

template <typename Value>
static Array* create(idx_t size0);
static Array* create(idx_t size0, const eckit::Parametrisation& param = util::Config());
template <typename Value>
static Array* create(idx_t size0, idx_t size1);
static Array* create(idx_t size0, idx_t size1, const eckit::Parametrisation& param = util::Config());
template <typename Value>
static Array* create(idx_t size0, idx_t size1, idx_t size2);
static Array* create(idx_t size0, idx_t size1, idx_t size2,
const eckit::Parametrisation& param = util::Config());
template <typename Value>
static Array* create(idx_t size0, idx_t size1, idx_t size2, idx_t size3);
static Array* create(idx_t size0, idx_t size1, idx_t size2, idx_t size3,
const eckit::Parametrisation& param = util::Config());
template <typename Value>
static Array* create(idx_t size0, idx_t size1, idx_t size2, idx_t size3, idx_t size4);
static Array* create(idx_t size0, idx_t size1, idx_t size2, idx_t size3, idx_t size4,
const eckit::Parametrisation& param = util::Config());

template <typename Value>
static Array* create(const ArrayShape& shape);
static Array* create(const ArrayShape& shape, const eckit::Parametrisation& param = util::Config());

template <typename Value>
static Array* create(const ArrayShape& shape, const ArrayLayout& layout);
static Array* create(const ArrayShape& shape, const ArrayLayout& layout,
const eckit::Parametrisation& param = util::Config());

template <typename Value>
static Array* wrap(Value* data, const ArrayShape& shape);
static Array* wrap(Value* data, const ArrayShape& shape, const eckit::Parametrisation& param
= util::Config());

template <typename Value>
static Array* wrap(Value* data, const ArraySpec& spec);
static Array* wrap(Value* data, const ArraySpec& spec, const eckit::Parametrisation& param
= util::Config());

idx_t bytes() const { return datatype().size() * spec().allocatedSize(); }

Expand Down Expand Up @@ -202,19 +219,21 @@ class Array : public util::Object {
template <typename Value>
class ArrayT : public Array {
public:
ArrayT(idx_t size0);
ArrayT(idx_t size0, idx_t size1);
ArrayT(idx_t size0, idx_t size1, idx_t size2);
ArrayT(idx_t size0, idx_t size1, idx_t size2, idx_t size3);
ArrayT(idx_t size0, idx_t size1, idx_t size2, idx_t size3, idx_t size4);
ArrayT(idx_t size0, const eckit::Parametrisation& param = util::Config());
ArrayT(idx_t size0, idx_t size1, const eckit::Parametrisation& param = util::Config());
ArrayT(idx_t size0, idx_t size1, idx_t size2, const eckit::Parametrisation& param = util::Config());
ArrayT(idx_t size0, idx_t size1, idx_t size2, idx_t size3,
const eckit::Parametrisation& param = util::Config());
ArrayT(idx_t size0, idx_t size1, idx_t size2, idx_t size3, idx_t size4,
const eckit::Parametrisation& param = util::Config());

ArrayT(ArraySpec&&);
ArrayT(ArraySpec&&, const eckit::Parametrisation& param = util::Config());

ArrayT(const ArrayShape&);
ArrayT(const ArrayShape&, const eckit::Parametrisation& param = util::Config());

ArrayT(const ArrayShape&, const ArrayAlignment&);
ArrayT(const ArrayShape&, const ArrayAlignment&, const eckit::Parametrisation& param = util::Config());

ArrayT(const ArrayShape&, const ArrayLayout&);
ArrayT(const ArrayShape&, const ArrayLayout&, const eckit::Parametrisation& param = util::Config());

virtual void insert(idx_t idx1, idx_t size1);

Expand All @@ -234,7 +253,7 @@ class ArrayT : public Array {

// This constructor is used through the Array::create() or the Array::wrap()
// methods
ArrayT(ArrayDataStore*, const ArraySpec&);
ArrayT(ArrayDataStore*, const ArraySpec&, const eckit::Parametrisation& param = util::Config());

virtual size_t footprint() const;

Expand Down
3 changes: 3 additions & 0 deletions src/atlas/array/ArrayDataStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ class ArrayDataStore {
Value* deviceData() {
return static_cast<Value*>(voidDeviceData());
}
private:
bool device_memory_pinned_ = false;
bool device_memory_mapped_ = false;
};

#ifndef DOXYGEN_SHOULD_SKIP_THIS
Expand Down
Loading

0 comments on commit e41689b

Please sign in to comment.