| 1 |
/* |
| 2 |
* (C) Copyright 2013 ECMWF. |
| 3 |
* |
| 4 |
* This software is licensed under the terms of the Apache Licence Version 2.0 |
| 5 |
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. |
| 6 |
* In applying this licence, ECMWF does not waive the privileges and immunities |
| 7 |
* granted to it by virtue of its status as an intergovernmental organisation |
| 8 |
* nor does it submit to any jurisdiction. |
| 9 |
*/ |
| 10 |
|
| 11 |
#pragma once |
| 12 |
|
| 13 |
#include <string> |
| 14 |
|
| 15 |
#include "atlas/array/ArrayIdx.h" |
| 16 |
#include "atlas/array/ArrayLayout.h" |
| 17 |
#include "atlas/array/ArrayShape.h" |
| 18 |
#include "atlas/array/ArraySpec.h" |
| 19 |
#include "atlas/array/ArrayStrides.h" |
| 20 |
|
| 21 |
//------------------------------------------------------------------------------------------------------ |
| 22 |
|
| 23 |
namespace atlas { |
| 24 |
namespace array { |
| 25 |
|
| 26 |
#ifndef DOXYGEN_SHOULD_SKIP_THIS |
| 27 |
template <typename T> |
| 28 |
struct remove_const { |
| 29 |
typedef T type; |
| 30 |
}; |
| 31 |
template <typename T> |
| 32 |
struct remove_const<T const> { |
| 33 |
typedef T type; |
| 34 |
}; |
| 35 |
|
| 36 |
template <typename T> |
| 37 |
struct add_const { |
| 38 |
typedef const typename remove_const<T>::type type; |
| 39 |
}; |
| 40 |
template <typename T> |
| 41 |
struct add_const<T const> { |
| 42 |
typedef const T type; |
| 43 |
}; |
| 44 |
#endif |
| 45 |
|
| 46 |
class ArrayDataStore { |
| 47 |
public: |
| 48 |
virtual ~ArrayDataStore() {} |
| 49 |
virtual void updateDevice() const = 0; |
| 50 |
virtual void updateHost() const = 0; |
| 51 |
virtual bool valid() const = 0; |
| 52 |
virtual void syncHostDevice() const = 0; |
| 53 |
virtual void syncHost() const = 0; |
| 54 |
virtual void syncDevice() const = 0; |
| 55 |
virtual void allocateDevice() const = 0; |
| 56 |
virtual void deallocateDevice() const = 0; |
| 57 |
virtual bool deviceAllocated() const = 0; |
| 58 |
virtual bool hostNeedsUpdate() const = 0; |
| 59 |
virtual bool deviceNeedsUpdate() const = 0; |
| 60 |
virtual void setHostNeedsUpdate(bool) const = 0; |
| 61 |
virtual void setDeviceNeedsUpdate(bool) const = 0; |
| 62 |
virtual void reactivateDeviceWriteViews() const = 0; |
| 63 |
virtual void reactivateHostWriteViews() const = 0; |
| 64 |
virtual void* voidDataStore() = 0; |
| 65 |
virtual void* voidHostData() = 0; |
| 66 |
virtual void* voidDeviceData() = 0; |
| 67 |
virtual void accMap() const = 0; |
| 68 |
virtual void accUnmap() const = 0; |
| 69 |
virtual bool accMapped() const = 0; |
| 70 |
template <typename Value> |
| 71 |
Value* hostData() { |
| 72 |
return static_cast<Value*>(voidHostData()); |
| 73 |
} |
| 74 |
template <typename Value> |
| 75 |
Value* deviceData() { |
| 76 |
return static_cast<Value*>(voidDeviceData()); |
| 77 |
} |
| 78 |
}; |
| 79 |
|
| 80 |
#ifndef DOXYGEN_SHOULD_SKIP_THIS |
| 81 |
template <int Dim> |
| 82 |
static constexpr char array_dim() { |
| 83 |
return Dim == 0 ? 'i' : (Dim == 1 ? 'j' : (Dim == 2 ? 'k' : (Dim == 3 ? 'l' : (Dim == 4 ? 'm' : ('*'))))); |
| 84 |
} |
| 85 |
|
| 86 |
void throw_OutOfRange(const std::string& class_name, char idx_str, int idx, int max); |
| 87 |
#endif |
| 88 |
|
| 89 |
//------------------------------------------------------------------------------------------------------ |
| 90 |
|
| 91 |
} // namespace array |
| 92 |
} // namespace atlas |