A crate that provides support for half-precision 16-bit floating point types.
This crate provides the
f16 type, which is an implementation of the IEEE 754-2008 standard
half floating point type. This 16-bit floating point type is intended for
efficient storage where the full range and precision of a larger floating point value is not
required. This is especially useful for image storage formats.
This crate also provides a
bf16 type, an alternative 16-bit floating point format. The
bfloat16 format is a truncated IEEE 754 standard
binary32 float that preserves the
exponent to allow the same range as
f32 but with only 8 bits of precision (instead of 11
f16). See the
bf16 type for details.
bf16 are primarily for efficient storage, floating point operations such
as addition, multiplication, etc. are not implemented by hardware. While this crate does provide
the appropriate trait implementations for basic operations, they each convert the value to
f32 before performing the operation and then back afterward. When performing complex
arithmetic, manually convert to and from
f32 before and after to reduce repeated conversions
for each operation.
This crate also provides a
slice module for zero-copy in-place conversions of
u16 slices to both
bf16, as well as efficient vectorized conversions of
larger buffers of floating point values to and from these half formats.
The crate uses
#[no_std] by default, so can be used in embedded environments without using the
std library. A
std feature to enable support for the standard library is available,
see the Cargo Features section below.
prelude module is provided for easy importing of available utility traits.
This crate supports a number of optional cargo features. None of these features are enabled by
core::archhardware intrinsics for
bf16conversions if available on the compiler target. This feature currently only works on nightly Rust until the corresponding intrinsics are stabilized.
When this feature is enabled and the hardware supports it, the functions and traits in the
slicemodule will use vectorized SIMD intructions for increased efficiency.
By default, without this feature, conversions are done only in software, which will also be the fallback if the target does not have hardware support. Note that without the
stdfeature enabled, no runtime CPU feature detection is used, so the hardware support is only compiled if the compiler target supports the CPU feature.
alloc– Enable use of the
alloccrate when not using the
Among other functions, this enables the
vecmodule, which contains zero-copy conversions for the
Vectype. This allows fast conversion between raw
Vec<bf16>arrays, and vice versa.
std– Enable features that depend on the Rust
stdlibrary. This also enables the
stdfeature also enables runtime CPU feature detection when the
use-intrsincisfeature is also enabled. Without this feature detection, intrinsics are only used when compiler target supports the target feature.
A collection of the most used items and traits in this crate for easy importing.