HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
onnxruntime::IAllocator Class Referenceabstract

#include <allocator.h>

+ Inheritance diagram for onnxruntime::IAllocator:

Public Member Functions

 IAllocator (const OrtMemoryInfo &info)
 
virtual ~IAllocator ()=default
 
virtual voidAlloc (size_t size)=0
 
virtual void Free (void *p)=0
 
virtual voidReserve (size_t size)
 
const OrtMemoryInfoInfo () const
 
virtual void GetStats (AllocatorStats *)
 
voidAllocArray (size_t nmemb, size_t size)
 
template<size_t alignment>
voidAllocArrayWithAlignment (size_t nmemb, size_t size)
 

Static Public Member Functions

static bool CalcMemSizeForArray (size_t nmemb, size_t size, size_t *out) noexcept
 
static bool CalcMemSizeForArrayWithAlignment (size_t nmemb, size_t size, size_t alignment, size_t *out) noexcept
 
template<size_t alignment>
static bool CalcMemSizeForArrayWithAlignment (size_t nmemb, size_t size, size_t *out) noexcept
 
template<typename T >
static IAllocatorUniquePtr< T > MakeUniquePtr (std::shared_ptr< IAllocator > allocator, size_t count_or_bytes, bool use_reserve=false, Stream *stream=nullptr, WaitNotificationFn wait_fn=nullptr)
 

Detailed Description

Definition at line 60 of file allocator.h.

Constructor & Destructor Documentation

onnxruntime::IAllocator::IAllocator ( const OrtMemoryInfo info)
inline

Definition at line 62 of file allocator.h.

virtual onnxruntime::IAllocator::~IAllocator ( )
virtualdefault

Member Function Documentation

virtual void* onnxruntime::IAllocator::Alloc ( size_t  size)
pure virtual
Remarks
Use SafeInt when calculating the size of memory to allocate using Alloc.

Implemented in onnxruntime::CPUAllocator.

void* onnxruntime::IAllocator::AllocArray ( size_t  nmemb,
size_t  size 
)
inline

allocate memory for an array which has nmemb items of data, each size bytes long

Definition at line 115 of file allocator.h.

template<size_t alignment>
void* onnxruntime::IAllocator::AllocArrayWithAlignment ( size_t  nmemb,
size_t  size 
)
inline

allocate memory for an array which has nmemb items of data, each size bytes long

Definition at line 126 of file allocator.h.

static bool onnxruntime::IAllocator::CalcMemSizeForArray ( size_t  nmemb,
size_t  size,
size_t *  out 
)
inlinestaticnoexcept

Definition at line 85 of file allocator.h.

static bool onnxruntime::IAllocator::CalcMemSizeForArrayWithAlignment ( size_t  nmemb,
size_t  size,
size_t  alignment,
size_t *  out 
)
staticnoexcept

Calculate the memory size for an array. The size is bounds checked using SafeInt.

Template Parameters
alignmentmust be power of 2
Parameters
nmembNumber of members or elements in the array
sizeSize of each element
outTotal size required after any alignment is applied
Returns
true, successful. false, overflow
template<size_t alignment>
bool onnxruntime::IAllocator::CalcMemSizeForArrayWithAlignment ( size_t  nmemb,
size_t  size,
size_t *  out 
)
staticnoexcept

https://cwe.mitre.org/data/definitions/190.html

Parameters
alignmentmust be power of 2
nmembNumber of members or elements in the array
sizeSize of each element
outTotal size required after any alignment is applied
Returns
true, successful. false, overflow
Remarks
This was the original API and was implemented in the header. Replaced with the above version implemented in the .cc file so that the SafeInt dependency is internal.

Definition at line 176 of file allocator.h.

virtual void onnxruntime::IAllocator::Free ( void p)
pure virtual

Implemented in onnxruntime::CPUAllocator.

virtual void onnxruntime::IAllocator::GetStats ( AllocatorStats *  )
inlinevirtual

Definition at line 83 of file allocator.h.

const OrtMemoryInfo& onnxruntime::IAllocator::Info ( ) const
inline

Definition at line 80 of file allocator.h.

template<typename T >
static IAllocatorUniquePtr<T> onnxruntime::IAllocator::MakeUniquePtr ( std::shared_ptr< IAllocator allocator,
size_t  count_or_bytes,
bool  use_reserve = false,
Stream stream = nullptr,
WaitNotificationFn  wait_fn = nullptr 
)
inlinestatic

Create a std::unique_ptr that is allocated and freed by the provided IAllocator.

Parameters
allocatorThe allocator.
count_or_bytesThe exact bytes to allocate if T is void, otherwise the number of elements to allocate.
use_reserveIf true, call Reserve() instead of Alloc() to allocate memory.
streamWhich stream instance allocated chunk will be used with.
wait_fnIf the allocator want to dynamic reuse a chunk from another stream, use this wait_fn to sync on the target stream to make the reuse safe.
Returns
std::unique_ptr with allocated memory and deleter.

Definition at line 144 of file allocator.h.

virtual void* onnxruntime::IAllocator::Reserve ( size_t  size)
inlinevirtual

Definition at line 78 of file allocator.h.


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