1 #ifndef OMEGA_H_SHARED_ALLOC_HPP
2 #define OMEGA_H_SHARED_ALLOC_HPP
4 #include <Omega_h_macros.h>
15 OMEGA_H_DLL
extern bool entering_parallel;
16 extern Allocs* global_allocs;
18 void start_tracking_allocations();
19 void stop_tracking_allocations(Library* lib);
28 Alloc(std::size_t size_in, std::string
const& name_in);
29 Alloc(std::size_t size_in, std::string&& name_in);
46 std::size_t total_bytes;
47 std::size_t high_water_bytes;
48 std::vector<HighWaterRecord> high_water_records;
54 OMEGA_H_INLINE
SharedAlloc() noexcept : alloc(
nullptr), direct_ptr(
nullptr) {}
55 SharedAlloc(std::size_t size_in, std::string
const& name_in);
56 SharedAlloc(std::size_t size_in, std::string&& name_in);
58 enum : std::uintptr_t {
63 IN_PARALLEL = FREE_BIT1,
64 IS_IDENTITY = FREE_BIT2,
74 OMEGA_H_INLINE
void copy(
SharedAlloc const& other) noexcept {
77 if (alloc && (!(
reinterpret_cast<std::uintptr_t
>(alloc) & FREE_MASK))) {
79 if (entering_parallel) {
80 alloc =
reinterpret_cast<Alloc*
>(
81 (std::uintptr_t(alloc->size) << 3) | IN_PARALLEL);
87 direct_ptr = other.direct_ptr;
90 OMEGA_H_INLINE
void move(
SharedAlloc&& other) noexcept {
92 direct_ptr = other.direct_ptr;
94 if (alloc && (!(
reinterpret_cast<std::uintptr_t
>(alloc) & FREE_MASK))) {
96 if (entering_parallel) {
98 alloc =
reinterpret_cast<Alloc*
>(
99 (std::uintptr_t(alloc->size) << 3) | IN_PARALLEL);
103 other.alloc =
nullptr;
104 other.direct_ptr =
nullptr;
114 move(std::move(other));
119 #pragma omp declare target
123 #pragma omp end declare target
125 OMEGA_H_INLINE
void clear() {
126 #ifndef __CUDA_ARCH__
127 if (alloc && (!(
reinterpret_cast<std::uintptr_t
>(alloc) & FREE_MASK))) {
129 --(alloc->use_count);
130 if (alloc->use_count == 0)
delete alloc;
134 OMEGA_H_INLINE std::size_t size()
const noexcept {
135 #ifndef __CUDA_ARCH__
136 if (!(
reinterpret_cast<std::uintptr_t
>(alloc) & IN_PARALLEL)) {
137 #if defined(__GNUC__) && (__GNUC__ >= 7) && (!defined(__clang__))
138 #pragma GCC diagnostic push
139 #pragma GCC diagnostic ignored "-Wnull-dereference"
142 #if defined(__GNUC__) && (__GNUC__ >= 7) && (!defined(__clang__))
143 #pragma GCC diagnostic pop
147 return reinterpret_cast<std::uintptr_t
>(alloc) >> 3;
149 OMEGA_H_INLINE
int maybe_identity_index(
int i)
const noexcept {
150 if (
reinterpret_cast<std::uintptr_t
>(alloc) == IS_IDENTITY) {
153 return static_cast<int*
>(direct_ptr)[i];
155 OMEGA_H_INLINE
void* data()
const noexcept {
return direct_ptr; }
Definition: amr_mpi_test.cpp:6
Definition: Omega_h_shared_alloc.hpp:21
Definition: Omega_h_shared_alloc.hpp:43
Definition: Omega_h_shared_alloc.hpp:38
Definition: Omega_h_shared_alloc.hpp:51
Definition: Omega_h_scalar.hpp:327