Skip to content

Real widths on Julia 1.14, and BitPacking 0.3 - #37

Merged
AntonOresten merged 5 commits into
mainfrom
native-widths
Nov 7, 2026
Merged

AntonOresten merged 5 commits into
mainfrom
native-widths

Conversation

@AntonOresten

@AntonOresten AntonOresten commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

Sub-byte microfloats keep their real width on Julia 1.14, and Microfloats moves to BitPacking 0.3.

Real widths on Julia 1.14

On Julia 1.14 and later, @microfloat declares a type narrower than a byte with its real width, so Core.bitsizeof(Float4_E2M1FN) == 4. Before 1.14 every microfloat stays an 8-bit primitive.

BitPacking 0.3

  • Compat: BitPacking = "0.3". On 1.14, 0.3 is the first BitPacking release that packs primitive types with unused bits.
  • raw_bits and from_raw_bits: Microfloats now uses and re-exports BitPacking's, which have the same contract. On 1.14 the conversions compile to the same code. Before 1.14, from_raw_bits also clears the bits above an 8-bit type's width, which adds one and on the narrowing paths.
  • The 1.14 reinterpret overrides are gone. On 1.14, Base's reinterpret refuses to convert a sub-byte type to or from UInt8, because that changes its width. Microfloats used to override this; now raw_bits(x) and from_raw_bits(T, bits) do those conversions on every version. One consequence is that PackedStructs can't read Microfloats fields on 1.14, since it reads values through reinterpret.
  • reinterpret(Unsigned, x) is deprecated in favor of raw_bits(x).
  • Version 0.2.9. BitPacking 0.3 requires Microfloats 0.2.9 or later in any environment that has Microfloats, so this is the release that pairs with it. The overrides removed above were never released, so nothing released breaks.
  • CUDA extension: fp4, fp8, ue8m0 and 16-bit pair registers are now built and read as NVector{T,2}, which is exactly their PTX register layout. This replaces four hand-written helpers. fp6 pairs keep a byte per lane, as PTX stores them. Every native conversion compiles to the same PTX instructions as before.
  • Tests: sub-byte and generic values are now built with from_raw_bits and read with raw_bits. The FP8 bit-pattern tests keep reinterpret, which doesn't change an 8-bit type's width.

The Float16x2/BFloat16x2 aliases are still SVectors. Making them NVectors would be a breaking change.

Tests

The full suite passes on Julia 1.12 (82035 tests) and 1.14.0-alpha2 (54102), including the CUDA extension tests on a GB10. On 1.14 the high-bits tests no longer run for sub-byte types, since those types have no bits above their width there.

Requires BitPacking 0.3 (MurrellGroup/BitPacking.jl#18), which is now registered.

🤖 Generated with Claude Code

https://claude.ai/code/session_01GqhLuuGKG92oXMxGJxVHDf

Julia 1.14 lets a primitive type declare fewer bits than it stores
(JuliaLang/julia#61359). There, `@microfloat` now declares a type
narrower than a byte with its sign + exponent + significand bits, so
`Core.bitsizeof(Float4_E2M1FN) == 4`; before 1.14 it keeps 8. Values
then cannot carry bits above the width, and `===` agrees with every
other operation.

`raw_bits` and `from_raw_bits` widen and truncate such types. Base's
`reinterpret` refuses them, so on 1.14 Microfloats defines
`reinterpret` between a microfloat and `UInt8`, which keeps
single-value conversions working (dropping bits above the width), and
BitPacking 0.2.5's packing with them. Arrays of these types can no
longer be reinterpreted on 1.14.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 33.33333% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.82%. Comparing base (ac5234a) to head (d48cf30).

Files with missing lines Patch % Lines
ext/CUDACoreExt/conversion.jl 0.00% 7 Missing ⚠️
src/Microfloat.jl 80.00% 1 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (ac5234a) and HEAD (d48cf30). Click for more details.

HEAD has 2 uploads less than BASE
Flag BASE (ac5234a) HEAD (d48cf30)
8 6
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #37      +/-   ##
==========================================
- Coverage   87.04%   80.82%   -6.23%     
==========================================
  Files          14       11       -3     
  Lines         664      657       -7     
==========================================
- Hits          578      531      -47     
- Misses         86      126      +40     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

AntonOresten and others added 4 commits November 6, 2026 23:53
BitPacking 0.3 defines raw_bits and from_raw_bits for every element type with
the contract Microfloats' own versions had, through the same intrinsics, so
Microfloats now uses and re-exports those. On Julia 1.14 the conversions
compile to the same code. Before 1.14 from_raw_bits also clears the bits above
the width of an 8-bit type, one extra and on the narrowing paths.

Julia 1.14's sub-byte microfloats need BitPacking 0.3, the first release that
packs primitive types with unused bits.

In BitPacking 0.3 reinterpret on an NVector keeps the array rule, so the bits of
a Float4x2 as one integer are raw_bits(v).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GqhLuuGKG92oXMxGJxVHDf
…Unsigned, x)

On Julia 1.14 a sub-byte microfloat declares only its bits, and Base's
reinterpret refuses to change its width. Microfloats overrode that for
conversions to and from UInt8, the one exception to the rule that reinterpret
keeps the width. raw_bits and from_raw_bits do those conversions on every
version, so the overrides go, and reinterpret(Unsigned, x), another width
change, is deprecated in favor of raw_bits.

The tests build sub-byte and generic values with from_raw_bits and read them
with raw_bits. The FP8 bit-pattern tests keep reinterpret, which does not change
an 8-bit type's width. The high-bits tests skip types that have no bits above
their width.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GqhLuuGKG92oXMxGJxVHDf
A PTX pair register holds lane 1 in its low bits. For fp4, fp8, ue8m0 and the
16-bit floats that is exactly the storage of an NVector{T,2}, which BitPacking
0.3 allows for elements wider than a byte, so raw_bits and from_raw_bits of an
NVector replace the four hand-written helpers. fp6 pairs, which PTX keeps a
byte per lane, keep their own path. Every native conversion compiles to the
same instructions as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GqhLuuGKG92oXMxGJxVHDf
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GqhLuuGKG92oXMxGJxVHDf
@AntonOresten AntonOresten changed the title Declare sub-byte microfloats with their real width on Julia 1.14 Real widths on Julia 1.14, and BitPacking 0.3 Nov 7, 2026
@AntonOresten
AntonOresten merged commit e8c090e into main Nov 7, 2026
9 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant