diff --git a/src/atlas/array/Array.h b/src/atlas/array/Array.h index b55ec8297..3d8348073 100644 --- a/src/atlas/array/Array.h +++ b/src/atlas/array/Array.h @@ -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&); @@ -233,6 +235,7 @@ class ArrayT : public Array { virtual size_t footprint() const; virtual bool accMap() const; + virtual bool accUnmap() const; private: template diff --git a/src/atlas/array/gridtools/GridToolsArray.cc b/src/atlas/array/gridtools/GridToolsArray.cc index 78f9b37f0..ce194f2f5 100644 --- a/src/atlas/array/gridtools/GridToolsArray.cc +++ b/src/atlas/array/gridtools/GridToolsArray.cc @@ -419,6 +419,12 @@ Array::~Array() = default; //------------------------------------------------------------------------------ + +template +ArrayT::~ArrayT() { + accUnmap(); +} + template size_t ArrayT::footprint() const { size_t size = sizeof(*this); @@ -442,6 +448,19 @@ bool ArrayT::accMap() const { //------------------------------------------------------------------------------ +template +bool ArrayT::accUnmap() const { + if (acc_map_) { +#if ATLAS_GRIDTOOLS_STORAGE_BACKEND_CUDA && ATLAS_HAVE_ACC + atlas_acc_unmap_data((void*)host_data()); + acc_map_ = false; +#endif + } + return acc_map_; +} + +//------------------------------------------------------------------------------ + template void ArrayT::insert(idx_t idx1, idx_t size1) { // if( hostNeedsUpdate() ) { diff --git a/src/atlas/array/native/NativeArray.cc b/src/atlas/array/native/NativeArray.cc index 479bf80a6..02d508c4b 100644 --- a/src/atlas/array/native/NativeArray.cc +++ b/src/atlas/array/native/NativeArray.cc @@ -170,6 +170,10 @@ ArrayT::ArrayT(ArraySpec&& spec): Array(std::move(spec)) { data_store_ = std::make_unique>(spec_.allocatedSize()); } +template +ArrayT::~ArrayT() { +} + template void ArrayT::resize(const ArrayShape& _shape) { if (rank() != static_cast(_shape.size())) { @@ -284,6 +288,11 @@ bool ArrayT::accMap() const { return false; } +template +bool ArrayT::accUnmap() const { + return false; +} + //------------------------------------------------------------------------------ template Array* Array::create(idx_t); diff --git a/src/atlas_acc_support/atlas_acc_map_data.c b/src/atlas_acc_support/atlas_acc_map_data.c index e9a8ac8b9..7c9d0d294 100644 --- a/src/atlas_acc_support/atlas_acc_map_data.c +++ b/src/atlas_acc_support/atlas_acc_map_data.c @@ -17,7 +17,13 @@ #endif #include -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); +} + diff --git a/src/atlas_acc_support/atlas_acc_map_data.h b/src/atlas_acc_support/atlas_acc_map_data.h index 835aba4a3..4fa1208c2 100644 --- a/src/atlas_acc_support/atlas_acc_map_data.h +++ b/src/atlas_acc_support/atlas_acc_map_data.h @@ -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 }