/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipcub/checkouts/docs-5.7.0/hipcub/include/hipcub/backend/rocprim/util_allocator.hpp Source File#
util_allocator.hpp
77 hipEvent_t ready_event; // Signal when associated stream has run to the point at which this block was freed
281 if (debug) _HipcubLog("Changing max_cached_bytes (%lld -> %lld)\n", (long long) this->max_cached_bytes, (long long) max_cached_bytes);
363 if (debug) _HipcubLog("\tDevice %d reused cached block at %p (%lld bytes) for stream %lld (previously associated with stream %lld).\n",
364 device, search_key.d_ptr, (long long) search_key.bytes, (long long) search_key.associated_stream, (long long) block_itr->associated_stream);
388 if (HipcubDebug(error = hipMalloc(&search_key.d_ptr, search_key.bytes)) == hipErrorMemoryAllocation)
391 if (debug) _HipcubLog("\tDevice %d failed to allocate %lld bytes for stream %lld, retrying after freeing cached allocations",
417 if (debug) _HipcubLog("\tDevice %d freed %lld bytes.\n\t\t %lld available blocks cached (%lld bytes), %lld live blocks (%lld bytes) outstanding.\n",
418 device, (long long) block_itr->bytes, (long long) cached_blocks.size(), (long long) cached_bytes[device].free, (long long) live_blocks.size(), (long long) cached_bytes[device].live);
436 if (HipcubDebug(error = hipEventCreateWithFlags(&search_key.ready_event, hipEventDisableTiming)))
445 if (debug) _HipcubLog("\tDevice %d allocated new device block at %p (%lld bytes associated with stream %lld).\n",
446 device, search_key.d_ptr, (long long) search_key.bytes, (long long) search_key.associated_stream);
458 if (debug) _HipcubLog("\t\t%lld available blocks cached (%lld bytes), %lld live blocks outstanding(%lld bytes).\n",
459 (long long) cached_blocks.size(), (long long) cached_bytes[device].free, (long long) live_blocks.size(), (long long) cached_bytes[device].live);
517 if ((search_key.bin != INVALID_BIN) && (cached_bytes[device].free + search_key.bytes <= max_cached_bytes))
524 if (debug) _HipcubLog("\tDevice %d returned %lld bytes from associated stream %lld.\n\t\t %lld available blocks cached (%lld bytes), %lld live blocks outstanding. (%lld bytes)\n",
525 device, (long long) search_key.bytes, (long long) search_key.associated_stream, (long long) cached_blocks.size(),
526 (long long) cached_bytes[device].free, (long long) live_blocks.size(), (long long) cached_bytes[device].live);
540 if (HipcubDebug(error = hipEventRecord(search_key.ready_event, search_key.associated_stream))) return error;
552 if (debug) _HipcubLog("\tDevice %d freed %lld bytes from associated stream %lld.\n\t\t %lld available blocks cached (%lld bytes), %lld live blocks (%lld bytes) outstanding.\n",
553 device, (long long) search_key.bytes, (long long) search_key.associated_stream, (long long) cached_blocks.size(), (long long) cached_bytes[device].free, (long long) live_blocks.size(), (long long) cached_bytes[device].live);
616 if (debug) _HipcubLog("\tDevice %d freed %lld bytes.\n\t\t %lld available blocks cached (%lld bytes), %lld live blocks (%lld bytes) outstanding.\n",
617 current_device, (long long) begin->bytes, (long long) cached_blocks.size(), (long long) cached_bytes[current_device].free, (long long) live_blocks.size(), (long long) cached_bytes[current_device].live);
Definition: util_allocator.hpp:121
Definition: util_allocator.hpp:71
void NearestPowerOf(unsigned int &power, size_t &rounded_bytes, unsigned int base, size_t value)
Definition: util_allocator.hpp:165
unsigned int min_bin
Geometric growth factor for bin-sizes.
Definition: util_allocator.hpp:197
hipError_t DeviceFree(int device, void *d_ptr)
Frees a live allocation of device memory on the specified device, returning it to the allocator.
Definition: util_allocator.hpp:488
std::multiset< BlockDescriptor, Compare > CachedBlocks
Set type for cached blocks (ordered by size)
Definition: util_allocator.hpp:129
unsigned int bin_growth
Mutex for thread-safety.
Definition: util_allocator.hpp:196
size_t max_bin_bytes
Minimum bin size.
Definition: util_allocator.hpp:201
CachedBlocks cached_blocks
Map of device ordinal to aggregate cached bytes on that device.
Definition: util_allocator.hpp:208
GpuCachedBytes cached_bytes
Whether or not to print (de)allocation events to stdout.
Definition: util_allocator.hpp:207
CachingDeviceAllocator(unsigned int bin_growth, unsigned int min_bin=1, unsigned int max_bin=INVALID_BIN, size_t max_cached_bytes=INVALID_SIZE, bool skip_cleanup=false, bool debug=false)
Set of live device allocations currently in use.
Definition: util_allocator.hpp:218
size_t min_bin_bytes
Maximum bin enumeration.
Definition: util_allocator.hpp:200
hipError_t DeviceFree(void *d_ptr)
Frees a live allocation of device memory on the current device, returning it to the allocator.
Definition: util_allocator.hpp:573
bool debug
Whether or not to skip a call to FreeAllCached() when destructor is called. (The CUDA runtime may hav...
Definition: util_allocator.hpp:205
unsigned int max_bin
Minimum bin enumeration.
Definition: util_allocator.hpp:198
std::map< int, TotalBytes > GpuCachedBytes
Map type of device ordinals to the number of cached bytes cached by each device.
Definition: util_allocator.hpp:135
std::multiset< BlockDescriptor, Compare > BusyBlocks
Set type for live blocks (ordered by ptr)
Definition: util_allocator.hpp:132
CachingDeviceAllocator(bool skip_cleanup=false, bool debug=false)
Default constructor.
Definition: util_allocator.hpp:252
hipError_t FreeAllCached()
Frees all cached device allocations on all devices.
Definition: util_allocator.hpp:583
static unsigned int IntPow(unsigned int base, unsigned int exp)
Definition: util_allocator.hpp:145
hipError_t SetMaxCachedBytes(size_t max_cached_bytes)
Sets the limit on the number bytes this allocator is allowed to cache per device.
Definition: util_allocator.hpp:275
virtual ~CachingDeviceAllocator()
Destructor.
Definition: util_allocator.hpp:637
BusyBlocks live_blocks
Set of cached device allocations available for reuse.
Definition: util_allocator.hpp:209
size_t max_cached_bytes
Maximum bin size.
Definition: util_allocator.hpp:202
hipError_t DeviceAllocate(int device, void **d_ptr, size_t bytes, hipStream_t active_stream=0)
Provides a suitable allocation of device memory for the given size on the specified device.
Definition: util_allocator.hpp:299
const bool skip_cleanup
Maximum aggregate cached bytes per device.
Definition: util_allocator.hpp:204
hipError_t DeviceAllocate(void **d_ptr, size_t bytes, hipStream_t active_stream=0)
Provides a suitable allocation of device memory for the given size on the current device.
Definition: util_allocator.hpp:472