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)
 
template<typename T >
static IAllocatorUniquePtr< T > MakeUniquePtrFromOrtAllocator (OrtAllocator *ort_allocator, size_t count_or_bytes)
 

Detailed Description

Definition at line 68 of file allocator.h.

Constructor & Destructor Documentation

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

Definition at line 70 of file allocator.h.

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

Member Function Documentation

virtual void* onnxruntime::IAllocator::Alloc ( size_t  size)
pure virtual

Allocate memory of the specified size. If size is 0, nullptr is returned. If allocation fails, an exception is thrown.

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 128 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 141 of file allocator.h.

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

Definition at line 97 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 247 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 95 of file allocator.h.

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

Definition at line 92 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. Throws if it cannot allocate memory.

Definition at line 161 of file allocator.h.

template<typename T >
static IAllocatorUniquePtr<T> onnxruntime::IAllocator::MakeUniquePtrFromOrtAllocator ( OrtAllocator *  ort_allocator,
size_t  count_or_bytes 
)
inlinestatic

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

Parameters
ort_allocatorThe allocator.
count_or_bytesThe exact bytes to allocate if T is void, otherwise the number of elements to allocate.
Returns
std::unique_ptr with allocated memory and deleter. Throws if it cannot allocate memory.

Definition at line 197 of file allocator.h.

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

Definition at line 90 of file allocator.h.


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