Struct BFloat16
This value type represents A BFloat16 value. See https://cloud.google.com/blog/products/ai-machine-learning/bfloat16-the-secret-to-high-performance-on-cloud-tpus for details. it is blittable as defined in https://docs.microsoft.com/en-us/dotnet/framework/interop/blittable-and-non-blittable-types and as such, represented the same way in managed and native memories. This means that arrays of this type do not have to be copied to be passed to native memory but simply pinnned and read by native code. Thus, one can create a Tensor on top of an array of these structures and feed it directly to Onnxruntime library. Binary wise, it is the same as ushort[] (uint16_t in C++). However, we would like a separate type for type dispatching.
Inherited Members
Namespace: Microsoft.ML.OnnxRuntime
Assembly: Microsoft.ML.OnnxRuntime.dll
Syntax
public readonly struct BFloat16 : IComparable, IComparable<BFloat16>, IEquatable<BFloat16>
Constructors
| Improve this Doc View SourceBFloat16(ushort)
Constructor from ushort, no conversion takes place. The value is assumed to be converted
Declaration
public BFloat16(ushort v)
Parameters
| Type | Name | Description |
|---|---|---|
| ushort | v | bfloat16 representation bits |
Fields
| Improve this Doc View Sourcevalue
bfloat16 representation bits
Declaration
public readonly ushort value
Field Value
| Type | Description |
|---|---|
| ushort |
Properties
| Improve this Doc View SourceEpsilon
BFloat16 Epsilon value
Declaration
public static BFloat16 Epsilon { get; }
Property Value
| Type | Description |
|---|---|
| BFloat16 |
MaxValue
BFloat16 Max value
Declaration
public static BFloat16 MaxValue { get; }
Property Value
| Type | Description |
|---|---|
| BFloat16 |
MinValue
BFloat16 Min value
Declaration
public static BFloat16 MinValue { get; }
Property Value
| Type | Description |
|---|---|
| BFloat16 |
NaN
BFloat16 NaN
Declaration
public static BFloat16 NaN { get; }
Property Value
| Type | Description |
|---|---|
| BFloat16 |
NegativeInfinity
BFloat16 Negative infinity value
Declaration
public static BFloat16 NegativeInfinity { get; }
Property Value
| Type | Description |
|---|---|
| BFloat16 |
NegativeZero
BFloat16 Negative Zero
Declaration
public static BFloat16 NegativeZero { get; }
Property Value
| Type | Description |
|---|---|
| BFloat16 |
One
BFloat16 One
Declaration
public static BFloat16 One { get; }
Property Value
| Type | Description |
|---|---|
| BFloat16 |
Pi
BFloat16 Pi value
Declaration
public static BFloat16 Pi { get; }
Property Value
| Type | Description |
|---|---|
| BFloat16 |
PositiveInfinity
BFloat16 Positive infinity value
Declaration
public static BFloat16 PositiveInfinity { get; }
Property Value
| Type | Description |
|---|---|
| BFloat16 |
Zero
BFloat16 Positive Zero
Declaration
public static BFloat16 Zero { get; }
Property Value
| Type | Description |
|---|---|
| BFloat16 |
Methods
| Improve this Doc View SourceCompareTo(BFloat16)
Compares this object to another object, returning an integer that indicates the relationship.
Declaration
public int CompareTo(BFloat16 other)
Parameters
| Type | Name | Description |
|---|---|---|
| BFloat16 | other | Object to compare to |
Returns
| Type | Description |
|---|---|
| int | A value less than zero if this is less than |
CompareTo(object)
Compares this object to another object, returning an integer that indicates the relationship.
Declaration
public int CompareTo(object obj)
Parameters
| Type | Name | Description |
|---|---|---|
| object | obj | Object to compare to |
Returns
| Type | Description |
|---|---|
| int | A value less than zero if this is less than |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown when |
Equals(BFloat16)
Returns a value indicating whether this instance and other BFloat16 represent the same value.
Declaration
public bool Equals(BFloat16 other)
Parameters
| Type | Name | Description |
|---|---|---|
| BFloat16 | other | A BFloat16 object to compare to this instance. |
Returns
| Type | Description |
|---|---|
| bool | true if other.value is equal to this instance; otherwise, false. |
Equals(object)
Returns a value indicating whether this instance and a specified System.Object represent the same type and value.
Declaration
public override bool Equals(object obj)
Parameters
| Type | Name | Description |
|---|---|---|
| object | obj | An System.Object. |
Returns
| Type | Description |
|---|---|
| bool | true if obj is BFloat16 its value is equal to this instance; otherwise, false. |
Overrides
| Improve this Doc View SourceGetHashCode()
Returns the hash code for this instance.
Declaration
public override int GetHashCode()
Returns
| Type | Description |
|---|---|
| int | A 32-bit signed integer hash code. |
Overrides
| Improve this Doc View SourceIsFinite(BFloat16)
Determines whether the specified value is finite (zero, subnormal, or normal).
Declaration
public static bool IsFinite(BFloat16 value)
Parameters
| Type | Name | Description |
|---|---|---|
| BFloat16 | value | BFloat16 instance. |
Returns
| Type | Description |
|---|---|
| bool | true if the value is finite |
IsInfinity(BFloat16)
Determines whether the specified value is infinite.
Declaration
public static bool IsInfinity(BFloat16 value)
Parameters
| Type | Name | Description |
|---|---|---|
| BFloat16 | value | BFloat16 instance. |
Returns
| Type | Description |
|---|---|
| bool | true if the value is infinite |
IsNaN(BFloat16)
Determines whether the specified value is NaN.
Declaration
public static bool IsNaN(BFloat16 value)
Parameters
| Type | Name | Description |
|---|---|---|
| BFloat16 | value | BFloat16 instance |
Returns
| Type | Description |
|---|---|
| bool | true if the value is not a number |
IsNaNOrZero(BFloat16)
The function returns true if the value is either NaN or zero.
Declaration
public static bool IsNaNOrZero(BFloat16 value)
Parameters
| Type | Name | Description |
|---|---|---|
| BFloat16 | value | instance of BFloat16 |
Returns
| Type | Description |
|---|---|
| bool | true if NaN or zero. |
IsNegative(BFloat16)
Determines whether the specified value is negative.
Declaration
public static bool IsNegative(BFloat16 value)
Parameters
| Type | Name | Description |
|---|---|---|
| BFloat16 | value | BFloat16 instance |
Returns
| Type | Description |
|---|---|
| bool | true if the value is negative |
IsNegativeInfinity(BFloat16)
Determines whether the specified value is negative infinity.
Declaration
public static bool IsNegativeInfinity(BFloat16 value)
Parameters
| Type | Name | Description |
|---|---|---|
| BFloat16 | value | BFloat16 instance |
Returns
| Type | Description |
|---|---|
| bool | true if the value is negative infinity |
IsNormal(BFloat16)
Determines whether the specified value is normal
Declaration
public static bool IsNormal(BFloat16 value)
Parameters
| Type | Name | Description |
|---|---|---|
| BFloat16 | value |
Returns
| Type | Description |
|---|---|
| bool | true or false |
IsPositiveInfinity(BFloat16)
Determines whether the specified value is positive infinity.
Declaration
public static bool IsPositiveInfinity(BFloat16 value)
Parameters
| Type | Name | Description |
|---|---|---|
| BFloat16 | value | BFloat16 instance |
Returns
| Type | Description |
|---|---|
| bool |
IsSubnormal(BFloat16)
Determines whether the specified value is subnormal.
Declaration
public static bool IsSubnormal(BFloat16 value)
Parameters
| Type | Name | Description |
|---|---|---|
| BFloat16 | value | BFloat16 instance |
Returns
| Type | Description |
|---|---|
| bool | true if the value is subnormal |
Negate(BFloat16)
Flips the sign. NaNs are not affected. IEEE 754 specifies NaNs to be propagated
Declaration
public static BFloat16 Negate(BFloat16 value)
Parameters
| Type | Name | Description |
|---|---|---|
| BFloat16 | value |
Returns
| Type | Description |
|---|---|
| BFloat16 |
ToFloat()
Explicit conversion
Declaration
public float ToFloat()
Returns
| Type | Description |
|---|---|
| float | single precision value converted from Float16 |
ToString()
Returns a string representation of the current value.
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| string | Text representation of BFloat16 |
Overrides
Operators
| Improve this Doc View Sourceoperator ==(BFloat16, BFloat16)
Compares values of two BFloat16 for binary equality. If either of the values is NaN, this will return false.
Declaration
public static bool operator ==(BFloat16 left, BFloat16 right)
Parameters
| Type | Name | Description |
|---|---|---|
| BFloat16 | left | left hand side |
| BFloat16 | right | right hand side |
Returns
| Type | Description |
|---|---|
| bool | result of value comparisons |
explicit operator float(BFloat16)
Explicitly converts a BFloat16 value to its nearest representable float value.
Declaration
public static explicit operator float(BFloat16 value)
Parameters
| Type | Name | Description |
|---|---|---|
| BFloat16 | value | The value to convert. |
Returns
| Type | Description |
|---|---|
| float |
|
explicit operator BFloat16(float)
Explicitly converts a float value to its nearest representable bfloat16 value.
Declaration
public static explicit operator BFloat16(float value)
Parameters
| Type | Name | Description |
|---|---|---|
| float | value | The value to convert. |
Returns
| Type | Description |
|---|---|
| BFloat16 |
|
operator >(BFloat16, BFloat16)
Compares two BFloat16 instances.
Declaration
public static bool operator >(BFloat16 left, BFloat16 right)
Parameters
| Type | Name | Description |
|---|---|---|
| BFloat16 | left | |
| BFloat16 | right |
Returns
| Type | Description |
|---|---|
| bool | true if the left is greater than right according to IEEE |
operator >=(BFloat16, BFloat16)
Compares two BFloat16 instances.
Declaration
public static bool operator >=(BFloat16 left, BFloat16 right)
Parameters
| Type | Name | Description |
|---|---|---|
| BFloat16 | left | |
| BFloat16 | right |
Returns
| Type | Description |
|---|---|
| bool | true if the left is greater or equal than right according to IEEE |
operator !=(BFloat16, BFloat16)
Compares values of two BFloat16 for binary inequality If either of the values is NaN it would return true.
Declaration
public static bool operator !=(BFloat16 left, BFloat16 right)
Parameters
| Type | Name | Description |
|---|---|---|
| BFloat16 | left | |
| BFloat16 | right |
Returns
| Type | Description |
|---|---|
| bool | result of value comparisons |
operator <(BFloat16, BFloat16)
Compares two BFloat16 instances.
Declaration
public static bool operator <(BFloat16 left, BFloat16 right)
Parameters
| Type | Name | Description |
|---|---|---|
| BFloat16 | left | |
| BFloat16 | right |
Returns
| Type | Description |
|---|---|
| bool | true if the left is less than right according to IEEE |
operator <=(BFloat16, BFloat16)
Compares two BFloat16 instances.
Declaration
public static bool operator <=(BFloat16 left, BFloat16 right)
Parameters
| Type | Name | Description |
|---|---|---|
| BFloat16 | left | |
| BFloat16 | right |
Returns
| Type | Description |
|---|---|
| bool | true if the left is less or equal than right according to IEEE |