Skip to content
Merged

v0.2 #22

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
name = "Microfloats"
uuid = "31c70f10-a750-4521-b13c-797315ae2933"
version = "0.2.0"
authors = ["Anton Oresten <antonoresten@gmail.com> and contributors"]
version = "0.1.1"

[workspace]
projects = ["test"]

[deps]
BFloat16s = "ab4f0b2a-ad5b-11e8-123f-65d77653426b"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"

[weakdeps]
BitPacking = "b58c8408-13c4-4787-8733-7038ae624acf"

[extensions]
BitPackingExt = "BitPacking"
Republic = "27243419-9dde-4721-b67c-fd63626fea7f"

[compat]
BFloat16s = "0.5, 0.6"
BitPacking = "0.1"
Random = "1"
Republic = "2.1"
julia = "1.10"
35 changes: 6 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,58 +1,35 @@
# <img src="docs/src/assets/icon.svg" width="200" align="right"> Microfloats
# Microfloats

[![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://MurrellGroup.github.io/Microfloats.jl/stable/)
[![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://MurrellGroup.github.io/Microfloats.jl/dev/)
[![Build Status](https://github.com/MurrellGroup/Microfloats.jl/actions/workflows/CI.yml/badge.svg?branch=main)](https://github.com/MurrellGroup/Microfloats.jl/actions/workflows/CI.yml?query=branch%3Amain)
[![Coverage](https://codecov.io/gh/MurrellGroup/Microfloats.jl/branch/main/graph/badge.svg)](https://codecov.io/gh/MurrellGroup/Microfloats.jl)

Microfloats is a Julia package that implements types and arithmetic (through wider intermediates) for sub-8 bit floating points, supporting arbitrary combinations of sign, exponent, and mantissa (significand) bits.
Microfloats is a Julia package that implements types and arithmetic (through wider intermediates) for sub-byte floating points, supporting arbitrary combinations of sign, exponent, and significand (mantissa) bits.

Instances of a sub-8 bit floating point type are still 8 bits wide in memory; the goal of `Microfloat` is to serve as a base for arithmetic operations and method dispatch, lending downstream packages a good abstraction for doing bitpacking and hardware acceleration.
Instances of a sub-8 bit floating point type are still 8 bits wide in memory; Microfloats serves as a base and reference for arithmetic operations and method dispatch, lending downstream packages a good abstraction for bitpacking and hardware acceleration.

## Usage

Along with the types already exported by Microfloats, we can also create our own types by passing the number of sign, exponent, and mantissa bits to the `Microfloat` type constructor. For example, one can recreate the `Float8` and `Float8_4` types exported by Float8s.jl:
Define your own primitive type with the macro:

```julia
using Microfloats

# IEEE_754_like variant for {Float64,Float32,Float16}-like overflowing
const MicrofloatIEEE{S,E,M} = Microfloat{S,E,M,IEEE_754_like}

const Float8 = MicrofloatIEEE{1,3,4}
const Float8_4 = MicrofloatIEEE{1,4,3}

# creating a sawed-off Float16 (BFloat8?) becomes trivial:
const Float8_5 = MicrofloatIEEE{1,5,2}

# unsigned variants:
const UFloat7 = MicrofloatIEEE{0,3,4}
const UFloat7_4 = MicrofloatIEEE{0,4,3}
const UFloat7_5 = MicrofloatIEEE{0,5,2}
@microfloat MyE5M2 sign=1 exponent=5 significand=2 nonfinite=Microfloats.IEEE
```

### Microscaling (MX)

Microfloats implements the E4M3, E5M2, E2M3, E3M2, E2M1, and E8M0 types from the [Open Compute Project Microscaling Formats (MX) Specification](https://www.opencompute.org/documents/ocp-microscaling-formats-mx-v1-0-spec-final-pdf). These are exported as `MX_E4M3`, `MX_E5M2`, `MX_E2M3`, `MX_E3M2`, `MX_E2M1`, and `MX_E8M0`, respectively, with most of these using saturated arithmetic (no Inf or NaN), and a different encoding for the types that do have NaNs.

For INT8, see `FixedPointNumbers.Q1f6`.

> [!NOTE]
> MX types may not be fully MX compliant, but efforts have been and continue to be made to adhere to the specification. See issues with the [![MX-compliance](https://img.shields.io/github/labels/MurrellGroup/Microfloats.jl/mx-compliance)](https://github.com/MurrellGroup/Microfloats.jl/labels/mx-compliance) label.

Since Microfloats.jl only implements the primitive types, microscaling itself may be done with [Microscaling.jl](https://github.com/MurrellGroup/Microscaling.jl), which includes quantization and bitpacking.
or see the documentation for a list of predefined types.

## Installation

```julia
using Pkg
Pkg.Registry.add(url="https://github.com/MurrellGroup/MurrellGroupRegistry")
Pkg.add("Microfloats")
```

## See also

- [Microscaling.jl](https://github.com/MurrellGroup/Microscaling.jl)
- [FixedPointNumbers.jl](https://github.com/JuliaMath/FixedPointNumbers.jl)
- [MicroFloatingPoints.jl](https://github.com/goualard-f/MicroFloatingPoints.jl)
- [DLFP8Types.jl](https://github.com/chengchingwen/DLFP8Types.jl)
Expand Down
4 changes: 2 additions & 2 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ makedocs(;
),
pages=[
"Home" => "index.md",
"Microfloats" => "microfloats.md",
"Conversion" => "conversion.md",
"The Microfloat type" => "microfloat.md",
"Predefined types" => "predefined.md",
],
)

Expand Down
37 changes: 0 additions & 37 deletions docs/src/assets/icon.svg

This file was deleted.

82 changes: 0 additions & 82 deletions docs/src/conversion.md

This file was deleted.

2 changes: 1 addition & 1 deletion docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ CurrentModule = Microfloats
## Contents

```@contents
Pages = ["index.md", "microfloats.md", "conversion.md"]
Pages = ["index.md", "microfloat.md", "predefined.md"]
```

## Index
Expand Down
41 changes: 41 additions & 0 deletions docs/src/microfloat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# The Microfloat type

```@docs
Microfloat
```

## Defining a new Microfloat

```@docs
@microfloat
```

## API

### Non-Finite Behavior

```@docs
Microfloats.hasinf
Microfloats.hasnan
Microfloats.non_finite_behavior
Microfloats.IEEE
Microfloats.NanOnlyAllOnes
Microfloats.FiniteOnly
```

### Overflow policies

```@docs
Microfloats.overflow_policy
Microfloats.OVF
Microfloats.SAT
```

### Reflection

```@docs
Microfloats.bitwidth
Microfloats.sign_bits
Microfloats.exponent_bits
Microfloats.significand_bits
```
41 changes: 0 additions & 41 deletions docs/src/microfloats.md

This file was deleted.

25 changes: 25 additions & 0 deletions docs/src/predefined.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
## Predefined types

Microfloats defines and exports a set of common types.

### IEEE-like

These types have IEEE 754-like Inf/NaN encodings, with Inf being represented as all 1s in the exponent and a significand of zero, and NaN being represented as all 1s in the exponent and a non-zero significand.

```@docs
Float8_E5M2
Float8_E4M3
Float8_E3M4
```

### Finite

These types have no Inf encoding, with alternate or no NaN encodings at all.

```@docs
Float8_E4M3FN
Float8_E8M0FNU
Float6_E3M2FN
Float6_E2M3FN
Float4_E2M1FN
```
8 changes: 0 additions & 8 deletions ext/BitPackingExt.jl

This file was deleted.

Loading