Skip to content

Commit

Permalink
Introduce atlas_acc_unmap_data and use at Array destruction
Browse files Browse the repository at this point in the history
  • Loading branch information
wdeconinck committed Sep 12, 2023
1 parent 1b5b17c commit 8cc8e86
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/atlas/array/Array.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ class ArrayT : public Array {

ArrayT(const ArrayShape&, const ArrayLayout&);

virtual ~ArrayT();

virtual void insert(idx_t idx1, idx_t size1);

virtual void resize(const ArrayShape&);
Expand All @@ -233,6 +235,7 @@ class ArrayT : public Array {
virtual size_t footprint() const;

virtual bool accMap() const;
virtual bool accUnmap() const;

private:
template <typename T>
Expand Down
19 changes: 19 additions & 0 deletions src/atlas/array/gridtools/GridToolsArray.cc
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,12 @@ Array::~Array() = default;

//------------------------------------------------------------------------------


template <typename Value>
ArrayT<Value>::~ArrayT() {
accUnmap();
}

template <typename Value>
size_t ArrayT<Value>::footprint() const {
size_t size = sizeof(*this);
Expand All @@ -442,6 +448,19 @@ bool ArrayT<Value>::accMap() const {

//------------------------------------------------------------------------------

template <typename Value>
bool ArrayT<Value>::accUnmap() const {
if (acc_map_) {
#if ATLAS_GRIDTOOLS_STORAGE_BACKEND_CUDA && ATLAS_HAVE_ACC
atlas_acc_unmap_data((void*)host_data<Value>());
acc_map_ = false;
#endif
}
return acc_map_;
}

//------------------------------------------------------------------------------

template <typename Value>
void ArrayT<Value>::insert(idx_t idx1, idx_t size1) {
// if( hostNeedsUpdate() ) {
Expand Down
9 changes: 9 additions & 0 deletions src/atlas/array/native/NativeArray.cc
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ ArrayT<Value>::ArrayT(ArraySpec&& spec): Array(std::move(spec)) {
data_store_ = std::make_unique<native::DataStore<Value>>(spec_.allocatedSize());
}

template <typename Value>
ArrayT<Value>::~ArrayT() {
}

template <typename Value>
void ArrayT<Value>::resize(const ArrayShape& _shape) {
if (rank() != static_cast<idx_t>(_shape.size())) {
Expand Down Expand Up @@ -284,6 +288,11 @@ bool ArrayT<Value>::accMap() const {
return false;
}

template <typename Value>
bool ArrayT<Value>::accUnmap() const {
return false;
}

//------------------------------------------------------------------------------

template Array* Array::create<int>(idx_t);
Expand Down
10 changes: 8 additions & 2 deletions src/atlas_acc_support/atlas_acc_map_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@
#endif

#include <openacc.h>
void atlas_acc_map_data(void* cpu_ptr, void* gpu_ptr, unsigned long size)
{

void atlas_acc_map_data(void* cpu_ptr, void* gpu_ptr, unsigned long size) {
acc_map_data(cpu_ptr, gpu_ptr, size);
}


void atlas_acc_unmap_data(void* cpu_ptr) {
acc_unmap_data(cpu_ptr);
}

1 change: 1 addition & 0 deletions src/atlas_acc_support/atlas_acc_map_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ extern "C" {
#endif

void atlas_acc_map_data(void* cpu_ptr, void* gpu_ptr, unsigned long size);
void atlas_acc_unmap_data(void* cpu_ptr);

#ifdef __cplusplus
}
Expand Down

0 comments on commit 8cc8e86

Please sign in to comment.