Mila 0.13.48
Deep Neural Network Library
Loading...
Searching...
No Matches
Mila::Dnn::Compute::TrackedMemoryResource Class Referenceexport

A memory resource wrapper that tracks allocation and deallocation statistics. More...

Inheritance diagram for Mila::Dnn::Compute::TrackedMemoryResource:
Collaboration diagram for Mila::Dnn::Compute::TrackedMemoryResource:

Public Member Functions

 TrackedMemoryResource (MemoryResource *underlying, std::string_view name="")
 Constructs a new tracked memory resource.
 ~TrackedMemoryResource ()
 Destructor that properly cleans up the underlying resource.
const MemoryResourcegetUnderlying () const
 Gets access to the underlying memory resource.
std::string_view name () const
 Copies memory between potentially different memory spaces, delegating to underlying resource.
Public Member Functions inherited from Mila::Dnn::Compute::MemoryResource
virtual ~MemoryResource ()=default
 Virtual destructor for proper cleanup of derived classes.

Protected Member Functions

void * do_allocate (std::size_t bytes, std::size_t alignment) override
 Allocates memory and updates tracking statistics.
void do_deallocate (void *p, std::size_t bytes, std::size_t alignment) override
 Deallocates memory and updates tracking statistics.
bool do_is_equal (const std::pmr::memory_resource &other) const noexcept override
 Checks if this memory resource is equal to another.

Private Attributes

std::string name_
 Optional name for debugging/logging.
MemoryResourceunderlying_
 The wrapped memory resource (owned).

Additional Inherited Members

Static Public Attributes inherited from Mila::Dnn::Compute::MemoryResource
static constexpr bool is_device_accessible = false
 Checks if the memory is accessible from device code.
static constexpr bool is_host_accessible = true
 Checks if the memory is accessible from host code.

Detailed Description

A memory resource wrapper that tracks allocation and deallocation statistics.

This class wraps another memory resource and intercepts all allocation, deallocation, memcpy, and memset calls to maintain global memory usage statistics.

Constructor & Destructor Documentation

◆ TrackedMemoryResource()

Mila::Dnn::Compute::TrackedMemoryResource::TrackedMemoryResource ( MemoryResource * underlying,
std::string_view name = "" )
inlineexplicit

Constructs a new tracked memory resource.

Parameters
underlyingThe memory resource to track (takes ownership).
nameOptional name for this memory resource for logging purposes.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ~TrackedMemoryResource()

Mila::Dnn::Compute::TrackedMemoryResource::~TrackedMemoryResource ( )
inline

Destructor that properly cleans up the underlying resource.

Member Function Documentation

◆ do_allocate()

void * Mila::Dnn::Compute::TrackedMemoryResource::do_allocate ( std::size_t bytes,
std::size_t alignment )
inlineoverrideprotectedvirtual

Allocates memory and updates tracking statistics.

Parameters
bytesNumber of bytes to allocate
alignmentMemory alignment requirement
Returns
Pointer to allocated memory

Implements Mila::Dnn::Compute::MemoryResource.

◆ do_deallocate()

void Mila::Dnn::Compute::TrackedMemoryResource::do_deallocate ( void * p,
std::size_t bytes,
std::size_t alignment )
inlineoverrideprotectedvirtual

Deallocates memory and updates tracking statistics.

Parameters
pPointer to memory to deallocate
bytesSize of memory block
alignmentAlignment used during allocation

Implements Mila::Dnn::Compute::MemoryResource.

◆ do_is_equal()

bool Mila::Dnn::Compute::TrackedMemoryResource::do_is_equal ( const std::pmr::memory_resource & other) const
inlineoverrideprotectedvirtualnoexcept

Checks if this memory resource is equal to another.

Parameters
otherThe other memory resource to compare with
Returns
true if the underlying resources are equal

Implements Mila::Dnn::Compute::MemoryResource.

Here is the call graph for this function:

◆ getUnderlying()

const MemoryResource * Mila::Dnn::Compute::TrackedMemoryResource::getUnderlying ( ) const
inline

Gets access to the underlying memory resource.

◆ name()

std::string_view Mila::Dnn::Compute::TrackedMemoryResource::name ( ) const
inline

Copies memory between potentially different memory spaces, delegating to underlying resource.

Parameters
dstDestination pointer
srcSource pointer
size_bytesNumber of bytes to copy

Sets memory to a specific byte value, delegating to underlying resource.

Parameters
ptrPointer to the memory block to fill
valueByte value to set (0-255)
size_bytesNumber of bytes to set

Gets the name of this tracked memory resource.

Here is the caller graph for this function:

Member Data Documentation

◆ name_

std::string Mila::Dnn::Compute::TrackedMemoryResource::name_
private

Optional name for debugging/logging.

◆ underlying_

MemoryResource* Mila::Dnn::Compute::TrackedMemoryResource::underlying_
private

The wrapped memory resource (owned).


The documentation for this class was generated from the following file: