Mila
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 (std::pmr::memory_resource *underlying, std::string_view name="")
 Constructs a new tracked memory resource.
 
std::string_view name () const
 Gets the name of this tracked memory resource.
 

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_
 
std::pmr::memory_resource * underlying_
 

Detailed Description

A memory resource wrapper that tracks allocation and deallocation statistics.

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

Constructor & Destructor Documentation

◆ TrackedMemoryResource()

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

Constructs a new tracked memory resource.

Parameters
underlyingThe memory resource to track.
nameOptional name for this memory resource for logging purposes.

Member Function Documentation

◆ do_allocate()

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

Allocates memory and updates tracking statistics.

◆ do_deallocate()

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

Deallocates memory and updates tracking statistics.

◆ do_is_equal()

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

Checks if this memory resource is equal to another.

◆ name()

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

Gets the name of this tracked memory resource.

Member Data Documentation

◆ name_

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

◆ underlying_

std::pmr::memory_resource* Mila::Dnn::Compute::TrackedMemoryResource::underlying_
private

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