blace.ai
blace::RawMemoryObject Class Reference

#include <raw_memory_object.h>

Public Member Functions

 RawMemoryObject (void *data_ptr, ml_core::DataTypeEnum type, ml_core::ColorFormatEnum color_format, std::vector< int64_t > memory_sizes, ml_core::OrderEnum order, ml_core::ValueRangeEnum value_range, std::optional< blace::ml_core::BlaceHash > hash=std::nullopt, bool copy_memory=true)
 
 RawMemoryObject (void *data_ptr, blace::RawMemoryMetadata meta_data, bool copy_memory)
 
 RawMemoryObject (const RawMemoryObject &other)
 
RawMemoryObjectoperator= (const RawMemoryObject &other)
 
 RawMemoryObject (RawMemoryObject &&other)
 
RawMemoryObjectoperator= (RawMemoryObject &&other)
 
void * get_data_ptr () const
 
std::vector< int64_t > get_memory_sizes () const
 
int get_memory_size () const
 
ml_core::DataTypeEnum get_type ()
 
ml_core::ColorFormatEnum get_color_format ()
 
ml_core::ValueRangeEnum get_value_range ()
 
ml_core::OrderEnum get_order ()
 
ml_core::BlaceHash get_hash () const
 
bool has_ownership ()
 
RawMemoryMetadata get_meta_data () const
 
template<class Archive >
void serialize (Archive &ar, const unsigned int version)
 

Detailed Description

Object to handle graph i/o of custom memory. The class either holds a pointer to externally managed memory (not taking ownership) or it stores a copy of the given memory internally.

Constructor & Destructor Documentation

◆ RawMemoryObject() [1/4]

blace::RawMemoryObject::RawMemoryObject ( void *  data_ptr,
ml_core::DataTypeEnum  type,
ml_core::ColorFormatEnum  color_format,
std::vector< int64_t >  memory_sizes,
ml_core::OrderEnum  order,
ml_core::ValueRangeEnum  value_range,
std::optional< blace::ml_core::BlaceHash hash = std::nullopt,
bool  copy_memory = true 
)

Constructs a RawMemoryObject from a memory pointer and meta data.

Parameters
data_ptrThe pointer to memory on the cpu.
typeDatatype of the memory.
color_formatColor format of the memory.
memory_sizesA vector of the memory sizes. Total number of bytes is calculated from this.
orderThe memory order.
value_rangeThe value range of the passed in data. See the enum for options.
hashHash of the data stored in memory. Make sure that different data always has different hash values, otherwise caching will return old values. If std::nullopt is passed in, the hash will be computed based on the raw memory (safest, but also slowest option).
copy_memoryIf true, stores a copy of the passed memory. Otherwise the constructed object only keeps a reference and the original data_ptr memory has to be valid when accessed.

◆ RawMemoryObject() [2/4]

blace::RawMemoryObject::RawMemoryObject ( void *  data_ptr,
blace::RawMemoryMetadata  meta_data,
bool  copy_memory 
)

Constructs a RawMemoryObject from a memory pointer and meta data.

Parameters
data_ptrxxx
meta_datayyy
copy_memoryzzz

◆ RawMemoryObject() [3/4]

blace::RawMemoryObject::RawMemoryObject ( const RawMemoryObject other)

Copy constructor.

Parameters
otherThe other object.

◆ RawMemoryObject() [4/4]

blace::RawMemoryObject::RawMemoryObject ( RawMemoryObject &&  other)

Move constructor.

Parameters
otherThe other object.

Member Function Documentation

◆ get_color_format()

ml_core::ColorFormatEnum blace::RawMemoryObject::get_color_format ( )

Get the color format.

Returns

◆ get_data_ptr()

void * blace::RawMemoryObject::get_data_ptr ( ) const

Get the stored memory address.

Returns

◆ get_hash()

ml_core::BlaceHash blace::RawMemoryObject::get_hash ( ) const

Get the memory hash.

Returns

◆ get_memory_size()

int blace::RawMemoryObject::get_memory_size ( ) const

Get the memory size in bytes. Computed from the memory sizes and data type.

Returns

◆ get_memory_sizes()

std::vector< int64_t > blace::RawMemoryObject::get_memory_sizes ( ) const

Get the vector of memory sizes. E.g. a blace::ml_core::BCHW blace::ml_core::RGB tensor with sizes 512x512 will return {1,3,512,512}.

Returns

◆ get_meta_data()

RawMemoryMetadata blace::RawMemoryObject::get_meta_data ( ) const

Get meta data object.

Returns

◆ get_order()

ml_core::OrderEnum blace::RawMemoryObject::get_order ( )

Get the memory order.

Returns

◆ get_type()

ml_core::DataTypeEnum blace::RawMemoryObject::get_type ( )

Get the data type.

Returns

◆ get_value_range()

ml_core::ValueRangeEnum blace::RawMemoryObject::get_value_range ( )

Get the value range.

Returns

◆ has_ownership()

bool blace::RawMemoryObject::has_ownership ( )

Returns if the object has memory ownership or not.

Returns

◆ operator=() [1/2]

RawMemoryObject & blace::RawMemoryObject::operator= ( const RawMemoryObject other)

Copy assignment.

Parameters
otherThe other object.
Returns

◆ operator=() [2/2]

RawMemoryObject & blace::RawMemoryObject::operator= ( RawMemoryObject &&  other)

Move assignment.

Parameters
otherThe other object.
Returns

◆ serialize()

template<class Archive >
void blace::RawMemoryObject::serialize ( Archive &  ar,
const unsigned int  version 
)
inline

Serializes the object for boost serialization.