HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
onnxruntime::Int4x2Base< Signed > Struct Template Reference

Stores 2 packed 4-bit elements in 1 byte. More...

#include <int4.h>

Public Types

using UnpackedType = typename Int4Traits< Signed >::UnpackedType
 

Public Member Functions

 Int4x2Base ()=default
 
 Int4x2Base (std::byte bits)
 
 Int4x2Base (UnpackedType val0, UnpackedType val1)
 
UnpackedType GetElem (size_t index) const
 
void SetElem (size_t index, UnpackedType val)
 
std::byte ToBits () const
 

Static Public Member Functions

static int8_t SignExtendLower4Bits (std::byte bits)
 
static size_t CalcNumInt4Pairs (size_t num_int4_elems)
 
static bool Unpack (gsl::span< UnpackedType > dst, gsl::span< const Int4x2Base< Signed >> src)
 Copy a source buffer of 4-bit elements (packed) into a destination buffer of 8-bit elements (unpacked). More...
 
static bool Pack (gsl::span< Int4x2Base< Signed >> dst, gsl::span< const UnpackedType > src)
 Copy a source buffer of 8-bit elements (unpacked) into a destination buffer of 4-bit elements (packed). More...
 
static std::pair< size_t, size_t > GetTensorElemIndices (size_t index)
 Returns hierarchical indices for a packed int4 element from the given element index. More...
 

Public Attributes

std::byte bits_ {}
 

Static Public Attributes

static constexpr UnpackedType min_val = Int4Traits<Signed>::min_val
 
static constexpr UnpackedType max_val = Int4Traits<Signed>::max_val
 

Detailed Description

template<bool Signed>
struct onnxruntime::Int4x2Base< Signed >

Stores 2 packed 4-bit elements in 1 byte.

Template Parameters
SignedSet to true if signed int4, or false if unsigned uint4.

Definition at line 35 of file int4.h.

Member Typedef Documentation

template<bool Signed>
using onnxruntime::Int4x2Base< Signed >::UnpackedType = typename Int4Traits<Signed>::UnpackedType

Definition at line 36 of file int4.h.

Constructor & Destructor Documentation

template<bool Signed>
onnxruntime::Int4x2Base< Signed >::Int4x2Base ( )
default
template<bool Signed>
onnxruntime::Int4x2Base< Signed >::Int4x2Base ( std::byte  bits)
inlineexplicit

Definition at line 44 of file int4.h.

template<bool Signed>
onnxruntime::Int4x2Base< Signed >::Int4x2Base ( UnpackedType  val0,
UnpackedType  val1 
)
inline

Definition at line 48 of file int4.h.

Member Function Documentation

template<bool Signed>
static size_t onnxruntime::Int4x2Base< Signed >::CalcNumInt4Pairs ( size_t  num_int4_elems)
inlinestatic

Definition at line 83 of file int4.h.

template<bool Signed>
UnpackedType onnxruntime::Int4x2Base< Signed >::GetElem ( size_t  index) const
inline

Definition at line 58 of file int4.h.

template<bool Signed>
static std::pair<size_t, size_t> onnxruntime::Int4x2Base< Signed >::GetTensorElemIndices ( size_t  index)
inlinestatic

Returns hierarchical indices for a packed int4 element from the given element index.

Usage: Int4x2* data = ...; auto indices = GetTensorElemIndices(3); // 4th int4 element int8_t elem = data[indices.first].GetElem(indices.second);

Parameters
indexIndex of 4-bit element
Returns
Unpacked element

Definition at line 150 of file int4.h.

template<bool Signed>
static bool onnxruntime::Int4x2Base< Signed >::Pack ( gsl::span< Int4x2Base< Signed >>  dst,
gsl::span< const UnpackedType src 
)
inlinestatic

Copy a source buffer of 8-bit elements (unpacked) into a destination buffer of 4-bit elements (packed).

Parameters
dstDestination buffer to store packed 4-bit elements
srcSource buffer with 8-bit elements
Returns
True on success

Definition at line 117 of file int4.h.

template<bool Signed>
void onnxruntime::Int4x2Base< Signed >::SetElem ( size_t  index,
UnpackedType  val 
)
inline

Definition at line 70 of file int4.h.

template<bool Signed>
static int8_t onnxruntime::Int4x2Base< Signed >::SignExtendLower4Bits ( std::byte  bits)
inlinestatic

Definition at line 52 of file int4.h.

template<bool Signed>
std::byte onnxruntime::Int4x2Base< Signed >::ToBits ( ) const
inline

Definition at line 79 of file int4.h.

template<bool Signed>
static bool onnxruntime::Int4x2Base< Signed >::Unpack ( gsl::span< UnpackedType dst,
gsl::span< const Int4x2Base< Signed >>  src 
)
inlinestatic

Copy a source buffer of 4-bit elements (packed) into a destination buffer of 8-bit elements (unpacked).

Parameters
dstDestination buffer to store unpacked 8-bit elements
srcSource buffer with 4-bit elements
Returns
True on success

Definition at line 93 of file int4.h.

Member Data Documentation

template<bool Signed>
std::byte onnxruntime::Int4x2Base< Signed >::bits_ {}

Definition at line 40 of file int4.h.

template<bool Signed>
constexpr UnpackedType onnxruntime::Int4x2Base< Signed >::max_val = Int4Traits<Signed>::max_val
static

Definition at line 38 of file int4.h.

template<bool Signed>
constexpr UnpackedType onnxruntime::Int4x2Base< Signed >::min_val = Int4Traits<Signed>::min_val
static

Definition at line 37 of file int4.h.


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