Repository navigation
Real widths on Julia 1.14, and BitPacking 0.3 - #37
Merged
Merged
Conversation
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 Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
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
force-pushed
the
native-widths
branch
from
November 7, 2026 10:46
d48cf30 to
c8c48fa
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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,
@microfloatdeclares a type narrower than a byte with its real width, soCore.bitsizeof(Float4_E2M1FN) == 4. Before 1.14 every microfloat stays an 8-bit primitive.BitPacking 0.3
BitPacking = "0.3". On 1.14, 0.3 is the first BitPacking release that packs primitive types with unused bits.raw_bitsandfrom_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_bitsalso clears the bits above an 8-bit type's width, which adds oneandon the narrowing paths.reinterpretoverrides are gone. On 1.14, Base'sreinterpretrefuses to convert a sub-byte type to or fromUInt8, because that changes its width. Microfloats used to override this; nowraw_bits(x)andfrom_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 throughreinterpret.reinterpret(Unsigned, x)is deprecated in favor ofraw_bits(x).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.from_raw_bitsand read withraw_bits. The FP8 bit-pattern tests keepreinterpret, which doesn't change an 8-bit type's width.The
Float16x2/BFloat16x2aliases are stillSVectors. Making themNVectors 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