Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Half-precision floating point types f16 and bf16 for Rust.

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
NotificationsYou must be signed in to change notification settings

VoidStarKat/half-rs

Repository files navigation

Crates.ioDocumentationCrates.ioBuild statusCircleCI

This crate implements a half-precision floating pointf16 type for Rust implementing the IEEE754-2008 standardbinary16a.k.a "half" format, as well as abf16 type implementing thebfloat16 format.

Usage

Thef16 andbf16 types attempt to match existing Rust floating point type functionality where possible, and provides both conversion operations (such as to/fromf32 andf64) and basicarithmetic operations. Hardware support for these operations will be used whenever hardware supportis available—either through instrinsics or targeted assembly—although a nightly Rust toolchain maybe required for some hardware.

This crate providesno_std support so can easily be used in embedded code where a smaller float format is most useful.

Requires Rust 1.81 or greater. If you need support for older versions of Rust, use previousversions of this crate.

See thecrate documentation for more details.

Optional Features

  • alloc — Enable use of thealloc crate when not usingthestd library.

    This enables thevec module, which contains zero-copy conversions for theVec type. Thisallows fast conversion between rawVec<u16> bits andVec<f16> orVec<bf16> arrays, and viceversa.

  • std — Enable features that depend on the Ruststd library, including everything in thealloc feature.

    Enabling thestd feature enables runtime CPU feature detection of hardware support.Without this feature detection, harware is only used when compiler target supports them.

  • serde - ImplementSerialize andDeserialize traits forf16 andbf16. This adds adependency on theserde crate.

  • num-traits — EnableToPrimitive,FromPrimitive,ToBytes,FromBytes,Num,Float,FloatCore,Signed, andBounded trait implementations from thenum-traits crate.

  • bytemuck — EnableZeroable andPod trait implementations from thebytemuck crate.

  • rand_distr — Enable sampling from distributions likeStandardUniform andStandardNormalfrom therand_distr crate.

  • rkyv -- Enable zero-copy deserializtion withrkyv crate.

  • aribtrary -- Enable fuzzing support witharbitrarycrate by implementingArbitrary trait.

  • nightly -- Enable nightly-only features (currentlyloongarch64 intrinsics).

Hardware support

The following list details hardware support for floating point types in this crate. When usingstdlibrary, runtime CPU target detection will be used. To get the most performance benefits, compilefor specific CPU features which avoids the runtime overhead and works in ano_std environment.

ArchitectureCPU Target FeatureNotes
x86/x86_64f16cThis supports conversion to/fromf16 only (including vector SIMD) and does not support anybf16 or arithmetic operations.
aarch64fp16This supports all operations onf16 only.
loongarch64lsx(nightly feature only) This supports conversion to/fromf16 only (including vector SIMD) and does not support anybf16 or arithmetic operations.

More Documentation

License

All files in this library are dual-licensed and distributed under the terms of either of:

at your option.

Contributing

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in thework by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without anyadditional terms or conditions.

About

Half-precision floating point types f16 and bf16 for Rust.

Topics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Sponsor this project

  •  

Contributors32

Languages


[8]ページ先頭

©2009-2025 Movatter.jp