Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions src/TiledArray/external/umpire.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,26 +68,31 @@ class umpire_allocator_impl {
umpire_allocator_impl(const umpire_allocator_impl<U>& rhs) noexcept
: umpalloc_(rhs.umpalloc_) {}

/// allocates um memory using umpire dynamic pool
/// allocates memory using umpire dynamic pool
pointer allocate(size_t n) {
pointer result = nullptr;

TA_ASSERT(umpalloc_);

size_t nbytes = n * sizeof(T);

// this, instead of umpalloc_->allocate(n*sizeof(T)), profiles memory use
// even if introspection is off
pointer result = nullptr;
result = static_cast<pointer>(
umpalloc_->getAllocationStrategy()->allocate_internal(n * sizeof(T)));
umpalloc_->getAllocationStrategy()->allocate_internal(nbytes));

return result;
}

/// deallocate um memory using umpire dynamic pool
void deallocate(pointer ptr, size_t size) {
/// deallocate memory using umpire dynamic pool
void deallocate(pointer ptr, size_t n) {
TA_ASSERT(umpalloc_);
// this, instead of umpalloc_->deallocate(ptr, size), profiles mmeory use
const auto nbytes = n * sizeof(T);
// this, instead of umpalloc_->deallocate(ptr, nbytes), profiles memory use
// even if introspection is off
umpalloc_->getAllocationStrategy()->deallocate_internal(ptr, size);
// N.B. with multiple threads would have to do this test in
// the critical section of Umpire's ThreadSafeAllocator::deallocate
// TA_ASSERT(nbytes <= umpalloc_->getCurrentSize());
umpalloc_->getAllocationStrategy()->deallocate_internal(ptr, nbytes);
}

const umpire::Allocator* umpire_allocator() const { return umpalloc_; }
Expand Down
6 changes: 3 additions & 3 deletions src/TiledArray/tensor/tensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class Tensor {
std::uninitialized_default_construct_n(ptr, size);
// std::uninitialized_value_construct_n(ptr, size);
}
auto deleter = [this, allocator = std::move(allocator),
auto deleter = [allocator = std::move(allocator),
size](auto&& ptr) mutable {
std::destroy_n(ptr, size);
allocator.deallocate(ptr, size);
Expand All @@ -124,10 +124,10 @@ class Tensor {
std::uninitialized_default_construct_n(ptr, size);
// std::uninitialized_value_construct_n(ptr, size);
}
auto deleter = [this, allocator = std::move(allocator),
auto deleter = [allocator = std::move(allocator),
size](auto&& ptr) mutable {
std::destroy_n(ptr, size);
allocator.deallocate(ptr, size * sizeof(T));
allocator.deallocate(ptr, size);
};
this->data_ = std::shared_ptr<value_type>(ptr, std::move(deleter));
}
Expand Down