2#if defined(DEEPITY_USE_CUDA)
51 size_t capacity_bytes;
73 capacity_bytes = (total_floats *
sizeof(float) + 63) & ~(size_t)63;
75 base_ptr = backend->Allocate(capacity_bytes /
sizeof(
float));
78 throw std::bad_alloc();
89 backend->Free(base_ptr);
119 size_t allocation_size = (num_floats *
sizeof(float) + 63) & ~(
size_t)63;
121 if (offset_bytes + allocation_size > capacity_bytes)
123 throw std::runtime_error(
"Fatal: DeviceMemoryArena capacity exceeded during allocation.");
126 float *chunk =
reinterpret_cast<float *
>(
127 reinterpret_cast<char *
>(base_ptr) + offset_bytes);
129 offset_bytes += allocation_size;
size_t GetUsedBytes() const
Returns how many bytes have been allocated from the arena so far.
Definition DeviceMemoryArena.h:135
DeviceMemoryArena(IComputeBackend *backend, size_t total_floats)
Allocates a single 64-byte-aligned device buffer large enough to hold total_floats floats,...
Definition DeviceMemoryArena.h:70
~DeviceMemoryArena()
Frees the underlying device buffer via the same backend it was allocated from.
Definition DeviceMemoryArena.h:85
float * AllocateFloats(size_t num_floats)
Allocates a 64-byte aligned chunk of floats from the arena.
Definition DeviceMemoryArena.h:117
DeviceMemoryArena & operator=(const DeviceMemoryArena &)=delete
Deleted: DeviceMemoryArena owns a single device allocation, so copy-assignment would risk a double-fr...
size_t GetCapacityBytes() const
Returns the arena's total capacity.
Definition DeviceMemoryArena.h:137
DeviceMemoryArena(const DeviceMemoryArena &)=delete
Deleted: DeviceMemoryArena owns a single device allocation, so copying would risk a double-free.
Device-agnostic compute backend interface: every numerical primitive a layer/network needs,...
Definition IComputeBackend.h:14
This file exists to provide both Tensor.h and IComputeBackend.h with device types without introducing...
Definition Backend.cpp:10