11 namespace onnxruntime {
13 template <
bool Signed>
19 static constexpr int8_t min_val = -8;
20 static constexpr int8_t max_val = 7;
26 static constexpr uint8_t min_val = 0;
27 static constexpr uint8_t max_val = 15;
34 template <
bool Signed>
49 bits_ =
static_cast<std::byte>(((val1 & 0xF) << 4) | (val0 & 0xF));
54 constexpr uint8_t shift = (
sizeof(int32_t) * 8) - 4;
55 return static_cast<int8_t
>((
static_cast<int32_t
>(bits) << shift) >> shift);
60 const uint8_t shift = 4 *
static_cast<uint8_t
>(index);
63 if constexpr (Signed) {
72 const uint8_t shift = 4 *
static_cast<uint8_t
>(index);
84 return (num_int4_elems + 1) / 2;
102 for (
size_t i = 0; i < dst.size(); i++) {
105 dst[i] =
src[
r].GetElem(c);
129 for (; src_i < src.size() - 1; src_i += 2) {
133 if (src_i < src.size()) {
151 return {index >> 1, index & 0x1};
UnpackedType GetElem(size_t index) const
static std::pair< size_t, size_t > GetTensorElemIndices(size_t index)
Returns hierarchical indices for a packed int4 element from the given element index.
static int8_t SignExtendLower4Bits(std::byte bits)
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...
static constexpr UnpackedType max_val
Stores 2 packed 4-bit elements in 1 byte.
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...
Int4x2Base(UnpackedType val0, UnpackedType val1)
static constexpr UnpackedType min_val
void SetElem(size_t index, UnpackedType val)
static size_t CalcNumInt4Pairs(size_t num_int4_elems)
Int4x2Base(std::byte bits)
typename Int4Traits< Signed >::UnpackedType UnpackedType
GLenum GLenum GLsizei void GLsizei void void * span