ONNX Runtime
Loading...
Searching...
No Matches
Ort::BFloat16_t Struct Reference

bfloat16 (Brain Floating Point) data type More...

#include <onnxruntime_cxx_api.h>

Inheritance diagram for Ort::BFloat16_t:

Public Types

using Base = onnxruntime_float16::BFloat16Impl< BFloat16_t >
 

Public Member Functions

 BFloat16_t ()=default
 
 BFloat16_t (float v) noexcept
 __ctor from float. Float is converted into bfloat16 16-bit representation.
 
float ToFloat () const noexcept
 Converts bfloat16 to float.
 
 operator float () const noexcept
 User defined conversion operator. Converts BFloat16_t to float.
 
bool operator== (const BFloat16_t &rhs) const noexcept
 
bool operator!= (const BFloat16_t &rhs) const noexcept
 
bool operator< (const BFloat16_t &rhs) const noexcept
 

Static Public Member Functions

static constexpr BFloat16_t FromBits (uint16_t v) noexcept
 Explicit conversion to uint16_t representation of bfloat16.
 

Detailed Description

bfloat16 (Brain Floating Point) data type

This struct is used for converting float to bfloat16 and back so the user could feed inputs and fetch outputs using these type.

The size of the structure should align with uint16_t and one can freely cast uint16_t buffers to/from Ort::BFloat16_t to feed and retrieve data.

// This example demonstrates converion from float to float16
constexpr float values[] = {1.f, 2.f, 3.f, 4.f, 5.f};
std::vector<Ort::BFloat16_t> bfp16_values;
bfp16_values.reserve(std::size(values));
std::transform(std::begin(values), std::end(values), std::back_inserter(bfp16_values),
[](float value) { return Ort::BFloat16_t(value); });

Member Typedef Documentation

◆ Base

using Ort::BFloat16_t::Base = onnxruntime_float16::BFloat16Impl<BFloat16_t>

Constructor & Destructor Documentation

◆ BFloat16_t() [1/2]

Ort::BFloat16_t::BFloat16_t ( )
default

◆ BFloat16_t() [2/2]

Ort::BFloat16_t::BFloat16_t ( float  v)
inlineexplicitnoexcept

__ctor from float. Float is converted into bfloat16 16-bit representation.

Parameters
vfloat value

Member Function Documentation

◆ FromBits()

static constexpr BFloat16_t Ort::BFloat16_t::FromBits ( uint16_t  v)
inlinestaticconstexprnoexcept

Explicit conversion to uint16_t representation of bfloat16.

Parameters
vuint16_t bit representation of bfloat16
Returns
new instance of BFloat16_t

◆ operator float()

Ort::BFloat16_t::operator float ( ) const
inlineexplicitnoexcept

User defined conversion operator. Converts BFloat16_t to float.

◆ operator!=()

bool Ort::BFloat16_t::operator!= ( const BFloat16_t rhs) const
inlinenoexcept

◆ operator<()

bool Ort::BFloat16_t::operator< ( const BFloat16_t rhs) const
noexcept

◆ operator==()

bool Ort::BFloat16_t::operator== ( const BFloat16_t rhs) const
noexcept

◆ ToFloat()

float Ort::BFloat16_t::ToFloat ( ) const
inlinenoexcept

Converts bfloat16 to float.

Returns
float representation of bfloat16 value