1#include <kernel/util/memory_arbiter.hpp>
2#include <kernel/util/cuda_util.hpp>
4#include <kernel/util/os_windows.hpp>
8#include <unordered_set>
25 static std::mutex manager_mutex;
27 static constexpr std::size_t arbiter_mutex_shift = 6;
30 static constexpr std::size_t arbiter_mutex_mask = 0x7;
35 static std::mutex arbiter_mutex[arbiter_mutex_mask + 1u];
37 typedef std::unique_lock<std::mutex> Lock;
42 static std::unordered_set<Block*> manager_block_set;
64 static constexpr std::size_t
full_size = ~std::size_t(0);
143 Block(Block&& other) =
delete;
145 Block& operator=(Block&& other) =
delete;
154 return Lock(arbiter_mutex[(
reinterpret_cast<std::size_t
>(
this) >> arbiter_mutex_shift) & arbiter_mutex_mask]);
161 ((
reinterpret_cast<std::size_t
>(
this) >> arbiter_mutex_shift) & arbiter_mutex_mask) ==
162 ((
reinterpret_cast<std::size_t
>(&other) >> arbiter_mutex_shift) & arbiter_mutex_mask);
165 void create(std::size_t bytes_,
Location loc_,
Init all_)
167 std::unique_lock<std::mutex> lock(
lock_mutex());
171 throw MemoryException(
"Memory::Block::create: memory block is already allocated");
174 this->bytes = bytes_;
176 this->_alloc(loc_, all_);
181 Lock manager_lock(manager_mutex);
182 manager_block_set.insert(
this);
186 static Block* attach(Block* block)
191 Lock lock(block->lock_mutex());
197 static bool detach(Block* block)
202 Lock lock(block->lock_mutex());
205 if(block->ref_count == 0u)
206 throw MemoryException(
"Memory::Block::detach: reference count is already zero");
213 Lock manager_lock(manager_mutex);
214 manager_block_set.erase(block);
229 std::unique_lock<std::mutex> lock(
lock_mutex());
230 _alloc(mem_loc, mem_ini);
235 std::unique_lock<std::mutex> lock(
lock_mutex());
242 void free_unmapped(
Location mem_loc)
244 std::unique_lock<std::mutex> lock(
lock_mutex());
251 _copy_main_from_uptodate();
258 void copy_from(
const Block& source,
Location mem_loc, std::size_t this_offset, std::size_t src_offset, std::size_t size)
261 std::unique_lock<std::mutex> lock(
lock_mutex());
264 if(this->_is_mapped_any())
265 throw AccessException(
"Memory::Block::copy_from: cannot copy to mapped memory block");
268 std::unique_lock<std::mutex> source_lock;
270 source_lock = source.lock_mutex();
273 if(source._is_mapped_any_write())
274 throw AccessException(
"Memory::Block::copy_from: cannot copy from write-mapped memory block");
278 mem_loc = source.valid_locations;
282 throw RangeException(
"Memory::Block::copy_from: memory size must be given explicitly");
283 if(this->bytes < this_offset + size)
284 throw RangeException(
"Memory::Block::copy_from: invalid destination memory range");
285 if(source.bytes < src_offset + size)
286 throw RangeException(
"Memory::Block::copy_from: invalid source memory range");
289 if(size > std::size_t(0))
291 this->_copy_from(source, mem_loc, this_offset, src_offset, size);
295 this->valid_locations = mem_loc;
298 void copy_from(
const void* src_ptr,
Location src_loc,
Location mem_loc, std::size_t this_offset, std::size_t size)
301 std::unique_lock<std::mutex> lock(
lock_mutex());
304 if(this->_is_mapped_any())
305 throw AccessException(
"Memory::Block::copy_from: cannot copy to mapped memory block");
312 if(this->bytes < this_offset)
313 throw RangeException(
"Memory::Block::copy_from: invalid destination memory offset");
315 size = this->bytes - this_offset;
316 if(this->bytes < this_offset + size)
317 throw RangeException(
"Memory::Block::copy_from: invalid destination memory range");
320 if(size > std::size_t(0))
322 this->_copy_from(src_ptr, src_loc, mem_loc, this_offset, size);
326 this->valid_locations = mem_loc;
329 void copy_to(
void* dst_ptr,
Location dst_loc, std::size_t this_offset, std::size_t size)
const
332 std::unique_lock<std::mutex> lock(
lock_mutex());
335 if(this->_is_mapped_any_write())
336 throw AccessException(
"Memory::Block::copy_to: cannot copy to mapped memory block");
339 if(this->bytes < this_offset)
340 throw RangeException(
"Memory::Block::copy_from: invalid destination memory offset");
342 size = this->bytes - this_offset;
343 if(this->bytes < this_offset + size)
344 throw RangeException(
"Memory::Block::copy_from: invalid destination memory range");
347 if(size > std::size_t(0))
349 this->_copy_to(dst_ptr, dst_loc, this_offset, size);
353 void format(
Location mem_loc, std::size_t this_offset, std::size_t size)
355 std::unique_lock<std::mutex> lock(
lock_mutex());
356 if(this->_is_mapped_any())
357 throw AccessException(
"Memory::Block::format: cannot format mapped memory block");
360 if(this->bytes < this_offset)
361 throw RangeException(
"Memory::Block::format: invalid destination memory offset");
363 size = this->bytes - this_offset;
364 if(this->bytes < this_offset + size)
365 throw RangeException(
"Memory::Block::format: invalid destination memory range");
381 if(this->mem_cuda !=
nullptr)
391 if(this->mem_main !=
nullptr)
400 void format_random(
Location mem_loc, std::size_t this_offset, std::size_t size)
402 std::unique_lock<std::mutex> lock(
lock_mutex());
403 if(this->_is_mapped_any())
404 throw AccessException(
"Memory::Block::format_random: cannot format mapped memory block");
407 if(this->bytes < this_offset)
408 throw RangeException(
"Memory::Block::format_random: invalid destination memory offset");
410 size = this->bytes - this_offset;
411 if(this->bytes < this_offset + size)
412 throw RangeException(
"Memory::Block::format: invalid destination memory range");
427 _copy_cuda_from_main(
reinterpret_cast<const char*
>(this->mem_main) + this_offset, this_offset, size);
431 View map_view(
Location mem_loc,
Access access, std::size_t offset, std::size_t size)
433 std::unique_lock<std::mutex> lock(
lock_mutex());
449 if(this->bytes < offset)
450 throw RangeException(
"Memory::Block::map_view: memory offset is out of bounds");
454 size = this->bytes - offset;
455 else if(this->bytes < offset + size)
456 throw RangeException(
"Memory::Block::map_view: memory range is out of bounds");
465 if(this->_is_mapped_any_write())
469 if(!this->write_overlap)
470 throw AccessException(
"Memory::Block::map_view: cannot map exclusively write-mapped memory block for overlapping write access");
471 if(this->write_location != mem_loc)
472 throw AccessException(
"Memory::Block::map_view: memory block is write-mapped onto a different memory location");
477 else if(this->_is_mapped_any_read())
479 throw AccessException(
"Memory::Block::map_view: cannot map read-mapped memory block for overlapping write access");
482 else if(this->_is_mapped_any())
485 throw AccessException(
"Memory::Block::map_view: cannot map locked memory block for exclusive write access");
492 if(this->_is_mapped_any_write())
493 throw AccessException(
"Memory::Block::map_view: cannot map write-locked memory block for read access");
497 if(size == std::size_t(0))
498 return View(
this, mem_loc, access, size,
nullptr);
511 throw AccessException(
"Memory::Block::map_view: trying to map uninitialized memory for reading");
518 else if(!*(this->valid_locations & mem_loc))
522 _copy_main_from_uptodate();
523 _copy_main_to(mem_loc);
536 if(this->write_views == std::size_t(0))
542 this->write_location = mem_loc;
552 return View(
this,
Location::main, access, size,
reinterpret_cast<char*
>(this->mem_main) + offset);
556 return View(
this,
Location::cuda, access, size,
reinterpret_cast<char*
>(this->mem_cuda) + offset);
560 XABORTM(
"Memory::Block::map_view: invalid memory location");
563 void release_view(
const View& view)
565 std::unique_lock<std::mutex> lock(
lock_mutex());
570 if(--this->write_views == std::size_t(0))
575 this->write_overlap =
false;
584 XASSERT(this->read_views_main > 0u);
589 XASSERT(this->read_views_cuda > 0u);
601 this->ref_count = 0u;
602 this->mem_main =
nullptr;
603 this->mem_cuda =
nullptr;
606 this->write_views = 0u;
607 this->read_views_main = 0u;
608 this->read_views_cuda = 0u;
609 this->write_overlap =
false;
612 bool _is_mapped_any()
const
614 return _is_mapped_any_read() || _is_mapped_any_write();
617 bool _is_mapped_any_read()
const
619 return this->read_views_main + this->read_views_cuda > 0u;
622 bool _is_mapped_any_write()
const
624 return this->write_views > 0u;
627 bool _is_mapped_cuda()
const
629 return _is_mapped_cuda_read() || _is_mapped_cuda_write();
632 bool _is_mapped_cuda_read()
const
637 bool _is_mapped_cuda_write()
const
642 bool _is_mapped_main()
const
644 return _is_mapped_main_read() || _is_mapped_main_write();
647 bool _is_mapped_main_read()
const
652 bool _is_mapped_main_write()
const
657 bool _is_write_overlapped()
const
663 void _alloc_main(
Init mem_ini)
667 throw AllocException(this->bytes,
"main");
695 void _alloc_cuda(
Init mem_ini)
698 throw AllocException(this->bytes,
"cuda");
729 if(this->bytes <= 0u)
734 this->_alloc_main(mem_ini);
738 this->_alloc_cuda(mem_ini);
746 XASSERTM(this->read_views_main == std::size_t(0),
"Memory::Block::_free_main: Cannot free main memory block that has a read view attached!");
747 XASSERTM(this->write_location !=
Memory::Location::main,
"Memory::Block::_free_main: Cannot free main memory block that has a write view attached!");
749 this->mem_main =
nullptr;
759 XASSERTM(this->read_views_cuda == std::size_t(0),
"Memory::Block::_free_cuda: Cannot free cuda memory block that has a read view attached!");
760 XASSERTM(this->write_location !=
Memory::Location::cuda,
"Memory::Block::_free_cuda: Cannot free cuda memory block that has a write view attached!");
762 this->mem_cuda =
nullptr;
768 void _copy_main_from_main(
const void* mem_main_src, std::size_t this_offset, std::size_t size)
771 XASSERT(mem_main_src !=
nullptr);
773 if(this->mem_main ==
nullptr)
775 Memory::memcopy_main(
reinterpret_cast<char*
>(this->mem_main) + this_offset, mem_main_src, size);
782 void _copy_cuda_from_main(
const void* mem_main_src, std::size_t this_offset, std::size_t size)
785 XASSERT(mem_main_src !=
nullptr);
787 if(this->mem_cuda ==
nullptr)
796 void _copy_main_from_cuda(
const void* mem_cuda_src, std::size_t this_offset, std::size_t size)
800 XASSERT(mem_cuda_src !=
nullptr);
802 if(this->mem_main ==
nullptr)
811 void _copy_cuda_from_cuda(
const void* mem_cuda_src, std::size_t this_offset, std::size_t size)
814 XASSERT(mem_cuda_src !=
nullptr);
816 if(this->mem_cuda ==
nullptr)
818 Memory::memcopy_cuda(
reinterpret_cast<char*
>(this->mem_cuda) + this_offset, mem_cuda_src, size);
825 void _copy_main_from_uptodate()
838 XASSERT(!_is_mapped_cuda_write());
839 _copy_main_from_cuda(this->mem_cuda, std::size_t(0), this->bytes);
847 void _copy_main_to(
Location mem_loc)
851 XASSERT(!_is_mapped_main_write());
852 _copy_cuda_from_main(this->mem_main, std::size_t(0), this->bytes);
857 void _copy_from(
const Block& source,
Location mem_loc, std::size_t this_offset, std::size_t src_offset, std::size_t size)
863 XASSERT(!source._is_mapped_cuda_write());
864 _copy_cuda_from_cuda(
reinterpret_cast<char*
>(source.mem_cuda) + src_offset, this_offset, size);
868 XASSERT(!source._is_mapped_main_write());
869 _copy_cuda_from_main(
reinterpret_cast<char*
>(source.mem_main) + src_offset, this_offset, size);
877 XASSERT(!source._is_mapped_main_write());
878 _copy_main_from_main(
reinterpret_cast<char*
>(source.mem_main) + src_offset, this_offset, size);
882 XASSERT(!source._is_mapped_cuda_write());
883 _copy_main_from_cuda(
reinterpret_cast<char*
>(source.mem_cuda) + src_offset, this_offset, size);
889 void _copy_from(
const void* src_ptr,
Location src_loc,
Location mem_loc, std::size_t this_offset, std::size_t size)
896 _copy_main_from_main(src_ptr, this_offset, size);
900 _copy_main_from_cuda(src_ptr, this_offset, size);
904 XABORTM(
"Memory::Block::_copy_from: invalid source memory location");
914 _copy_cuda_from_cuda(src_ptr, this_offset, size);
918 _copy_cuda_from_main(src_ptr, this_offset, size);
922 XABORTM(
"Memory::Block::_copy_from: invalid source memory location");
929 void _copy_main_to_main(
void* mem_main_dst, std::size_t this_offset, std::size_t size)
const
931 XASSERT(!this->_is_mapped_main_write());
932 XASSERT(mem_main_dst !=
nullptr);
933 XASSERT(this->mem_main !=
nullptr);
935 Memory::memcopy_main(mem_main_dst,
reinterpret_cast<char*
>(this->mem_main) + this_offset, size);
939 void _copy_cuda_to_main(
void* mem_main_dst, std::size_t this_offset, std::size_t size)
const
941 XASSERT(!this->_is_mapped_cuda_write());
942 XASSERT(mem_main_dst !=
nullptr);
943 XASSERT(this->mem_cuda !=
nullptr);
949 void _copy_main_to_cuda(
void* mem_cuda_dst, std::size_t this_offset, std::size_t size)
const
951 XASSERT(!this->_is_mapped_cuda_write());
952 XASSERT(mem_cuda_dst !=
nullptr);
953 XASSERT(this->mem_main !=
nullptr);
959 void _copy_cuda_to_cuda(
void* mem_cuda_dst, std::size_t this_offset, std::size_t size)
const
961 XASSERT(!this->_is_mapped_cuda_write());
962 XASSERT(mem_cuda_dst !=
nullptr);
963 XASSERT(this->mem_cuda !=
nullptr);
965 Memory::memcopy_cuda(mem_cuda_dst,
reinterpret_cast<char*
>(this->mem_cuda) + this_offset, size);
968 void _copy_to(
void* dst_ptr,
Location dst_loc, std::size_t this_offset, std::size_t size)
const
974 _copy_main_to_main(dst_ptr, this_offset, size);
976 _copy_cuda_to_main(dst_ptr, this_offset, size);
978 XABORTM(
"Memory::Block::_copy_to: invalid destination memory location");
983 _copy_cuda_to_cuda(dst_ptr, this_offset, size);
985 _copy_cuda_to_main(dst_ptr, this_offset, size);
987 XABORTM(
"Memory::Block::_copy_to: invalid destination memory location");
991 XABORTM(
"Memory::Block::_copy_to: no up-to-date source memory location");
1023 if((this->
_block !=
nullptr) && (this->
_ptr !=
nullptr))
1025 this->
_block->release_view(*
this);
1031 _block(other._block),
1032 _location(other._location),
1033 _access(other._access),
1034 _bytes(other._bytes),
1046 this->
_block = other._block;
1048 this->
_access = other._access;
1049 this->
_bytes = other._bytes;
1050 this->
_ptr = other._ptr;
1059 this->
_block->release_view(*
this);
1069 this->
_ptr =
nullptr;
1075 throw AccessException(
"Memory::View::format_to_zero(): write access required for format");
1081 else if(this->
_location == Location::cuda)
1088 throw AccessException(
"Memory::View::format_to_zero(): write access required for format");
1094 else if(this->
_location == Location::cuda)
1102 throw AccessException(
"Memory::View::format_to_zero(): write access required for copy");
1119 XABORTM(
"Memory::View::copy_raw_from: unknown source memory view location");
1136 XABORTM(
"Memory::View::copy_raw_from: unknown source memory view location");
1142 XABORTM(
"Memory::View::copy_raw_from: unknown destination memory view location");
1158 if(block !=
nullptr)
1160 if(block->
bytes < offset)
1161 throw RangeException(
"Memory::Arbiter: invalid block memory offset");
1164 if(block->
bytes < offset + size)
1165 throw RangeException(
"Memory::Arbiter: invalid block memory range");
1170 XASSERT(offset == std::size_t(0));
1171 XASSERT(size == std::size_t(0));
1176 _block(new
Block()),
1186 this->
_move(std::forward<Arbiter>(other));
1191 if(this->
_block != other._block)
1193 Block::detach(this->
_block);
1195 this->
_move(std::forward<Arbiter>(other));
1202 Block::detach(this->
_block);
1208 this->
_block = other._block;
1209 this->
_offset = other._offset;
1210 this->
_size = other._size;
1211 other._block =
nullptr;
1218 if(this->
_block ==
nullptr)
1220 if(offset != std::size_t(0))
1221 throw RangeException(
"Memory::Arbiter::attach(): invalid block memory offset");
1222 if((size !=
full_size) && (size != std::size_t(0)))
1223 throw RangeException(
"Memory::Arbiter::attach(): invalid block memory size");
1227 if(this->
_size != full_size)
1229 if(this->_size < this->
_offset + offset)
1230 throw RangeException(
"Memory::Arbiter::attach(): invalid block memory offset");
1233 if(this->
_size < size)
1234 throw RangeException(
"Memory::Arbiter::attach(): invalid block memory range");
1240 throw RangeException(
"Memory::Arbiter::attach(): invalid block memory offset");
1243 if(this->
_block->
bytes < this->_offset + offset + size)
1244 throw RangeException(
"Memory::Arbiter::attach(): invalid block memory range");
1254 if(this->
_size != full_size)
1256 if(this->_size < this->
_offset + offset)
1257 throw RangeException(
"Memory::Arbiter::attach(): invalid block memory offset");
1260 if(this->
_size < size)
1261 throw RangeException(
"Memory::Arbiter::attach(): invalid block memory range");
1268 throw RangeException(
"Memory::Arbiter::attach(): invalid block memory offset");
1271 if(this->
_block->
bytes < this->_offset + offset + size)
1272 throw RangeException(
"Memory::Arbiter::attach(): invalid block memory range");
1281 Block::detach(this->
_block);
1290 if(this->
_block ==
nullptr)
1292 XASSERTM(offset == std::size_t(0),
"arbiter clone range offset is out-of-bounds");
1293 XASSERTM((size == std::size_t(0)) || (size ==
full_size),
"arbiter clone range size is out-of-bounds");
1299 throw RangeException(
"Memory::Arbiter::clone(): invalid block memory offset");
1301 throw RangeException(
"Memory::Arbiter::clone(): invalid block memory range");
1318 if(this->
_size == full_size)
1321 size = this->
_size - offset;
1335 if(this->
_size != full_size)
1337 if(this->_size < this->
_offset + offset)
1338 throw RangeException(
"Memory::Arbiter::attach(): invalid block memory offset");
1341 if(this->
_size < size)
1342 throw RangeException(
"Memory::Arbiter::attach(): invalid block memory range");
1349 throw RangeException(
"Memory::Arbiter::attach(): invalid block memory offset");
1352 if(this->
_block->
bytes < this->_offset + offset + size)
1353 throw RangeException(
"Memory::Arbiter::attach(): invalid block memory range");
1363 Block::detach(this->
_block);
1365 this->
_move(std::move(temp));
1370 Block::detach(this->
_block);
1377 return std::size_t(0u);
1378 else if(this->
_size == full_size)
1397 this->
_block->alloc(mem_loc, mem_ini);
1403 this->
_block->free(mem_loc);
1416 XASSERTM(dst_size == src_size,
"source and destination arbiters have different size");
1418 this->
_block->copy_from(*source.
_block, mem_loc, this->_offset, source.
_offset, dst_size);
1472 if(manager_block_set.empty())
1476 std::cout <<
"\nWARNING: Memory::Manager: " << manager_block_set.size()
1477 <<
" memory arbiter blocks are still allocated upon program termination\n\n";
1482 std::unique_lock<std::mutex> lock(manager_mutex);
1484 for(
auto& mbi : manager_block_set)
1486 mbi->free_unmapped(mem_loc);
1492 std::unique_lock<std::mutex> lock(manager_mutex);
1495 for(
const auto& mbi : manager_block_set)
1505 std::unique_lock<std::mutex> lock(manager_mutex);
1508 for(
const auto& mbi : manager_block_set)
1510 if(mbi->mem_main !=
nullptr)
1519 std::unique_lock<std::mutex> lock(manager_mutex);
1522 for(
const auto& mbi : manager_block_set)
1524 if(mbi->mem_cuda !=
nullptr)
#define XABORTM(msg)
Abortion macro definition with custom message.
#define XASSERT(expr)
Assertion macro definition.
#define XASSERTM(expr, msg)
Assertion macro definition with custom message.
void copy(const Arbiter &source, Location mem_loc=Location::none)
Copies of the contents of one memory block into another one.
Arbiter attach(std::size_t offset=0u, std::size_t size=full_size) const
Creates a new arbiter that is attached to the same memory block as this arbiter.
void _move(Arbiter &&other)
moves another arbiter into this one
void release()
Releases this arbiter from its associated memory block and frees it if necessary.
void free(Location mem_loc)
Frees memory for a given memory block.
void alloc(Location mem_loc, Init mem_ini=Init::dont_care)
Allocates memory for a given memory block.
Arbiter()
standard constructor
static constexpr std::size_t full_size
full size constant for size parameters
std::size_t bytes() const
Returns the size of the arbiter's range in the attached memory block in bytes.
void copy_to(void *dst_ptr, Location dst_loc) const
Copies the contents of this memory block into a raw memory region.
Location location() const
Returns a combination of all up-to-date memory locations.
std::size_t _offset
the offset of this arbiter's memory region within the block
Block * _block
a pointer to the memory block associated with this arbiter
Arbiter clone(std::size_t offset=0u, std::size_t size=full_size, bool clone_block=false) const
Creates a new arbiter that contains a deep copy to (a sub-region of) this arbiters memory block.
View view(Location mem_loc, Access access)
Maps a raw view to a memory block.
std::size_t _size
size of this arbiter's memory region within the block
Arbiter & operator=(const Arbiter &other)=delete
deleted copy-assign operator
void format_random(Location mem_loc=Location::none)
Formats the memory block to random values.
void format(Location mem_loc=Location::none)
Formats the memory block to zero.
std::size_t block_bytes() const
Returns the size of the entire attached memory block in bytes.
Memory Arbiter memory block class.
void * mem_main
memory block pointer to main (host) memory
std::size_t read_views_cuda
number of currently active cuda memory views with read access
std::size_t read_views_main
number of currently active main memory views with read access
Block(const Block &)=delete
no copy constructor
Block & operator=(const Block &)=delete
no copy-assign operator
Lock lock_mutex() const
locks the arbiter mutex assigned to this memory block
Location write_location
location of current write view
Location valid_locations
combination of all currently up-to-date memory locations
void * mem_cuda
memory block pointer to cuda device memory
bool uses_same_lock(const Block &other) const
checks wether another block is assigned to the same mutex as this block
bool write_overlap
specifies whether the write view(s) can be overlapped
static constexpr std::size_t full_size
full size
std::size_t write_views
number of currently active write views
std::size_t ref_count
total number of references to this memory block
std::size_t bytes
total size of memory block in bytes
static void initialize(int argc, char **argv)
Initializes FEAT's memory management.
static std::size_t bytes_reserved()
Returns the total number of bytes reserved over all memory blocks.
static std::size_t bytes_allocated_main()
Returns the total number of bytes currently allocated in main memory over all blocks.
static void finalize()
Finalizes FEAT's memory management.
static std::size_t bytes_allocated_cuda()
Returns the total number of bytes currently allocated in cuda memory over all blocks.
static void free_all_unmapped(Location mem_loc)
Frees all memory blocks for a given set of memory location that are currently not mapped to a view.
Memory related exception base class.
void format_to_one()
Formats all bits of the memory view to one (yields NaN for floating point types)
void * _ptr
the actual memory pointer (may be a main or cuda or whatever pointer)
void format_to_zero()
Formats all bits of the memory view to zero.
void release() const
Releases this view.
Block * _block
the block that this view belongs to
void copy_raw_from(const void *src_ptr, Location src_loc)
Copies the contents of a given memory region into the memory of this memory view.
View()
default constructor
View & operator=(const View &)=delete
no copy-assign allowed
std::size_t _bytes
the size of the memory block in bytes
Access _access
the granted memory access
void _reset()
reset all attributes to null
virtual ~View()
virtual destructor
bool empty() const
Checks whether the memory view has a size of 0 bytes.
Location _location
the current memory location
void memcopy_main(void *dst, const void *src, std::size_t bytes)
Copies a region of a main memory block into another main memory block.
void memcopy_main_to_cuda(void *dst, const void *src, std::size_t bytes, const Util::StreamWrapper &stream=Util::StreamWrapper{})
Copies a region of a main memory block into a cuda memory block.
void memcopy_cuda_to_main(void *dst, const void *src, std::size_t bytes)
Copies a region of a cuda memory block into a main memory block.
Access
Memory access enumeration.
@ overlap
explicitly allow overlapping writes (see Overlapping Memory Views)
@ write
write-only access (see attention note above)
void memset_main(void *ptr, int value, std::size_t bytes)
Formats all bytes of a memory block in main memory to a given value.
Location
Memory location enumeration.
@ none
no or unknown or unspecified location
void * alloc_cuda(std::size_t bytes)
Allocate a memory block in cuda heap memory.
void memcopy_cuda(void *dst, const void *src, std::size_t bytes, const Util::StreamWrapper &stream=Util::StreamWrapper{})
Copies a region of a cuda memory block into another cuda memory block.
void memset_cuda(void *ptr, int value, std::size_t bytes, const Util::StreamWrapper &stream=Util::StreamWrapper{})
Formats all bytes of a memory block in cuda memory to a given value.
void free_main(void *ptr)
Frees a memory block in main heap memory allocated by alloc_main.
void free_cuda(void *ptr)
Frees a memory block in cuda heap memory allocated by alloc_cuda.
void memset_random_main(void *ptr, std::size_t bytes, std::uint64_t seed=0u)
Formats all bytes of a memory block in main memory to random values.
void * alloc_main(std::size_t bytes)
Allocate a memory block in main heap memory.
Init
Memory initialization enumeration.
@ uninitialized
leave memory uninitialized
@ format_to_zero
allocate and format all bits to zero
@ format_to_one
allocate and format all bits to one
void dump_call_stack_to_stderr()
Dumps the call-stack to stderr.