feat(dart): add bfloat16 and bfloat16_array support#3527
Open
miantalha45 wants to merge 3 commits intoapache:mainfrom
Open
feat(dart): add bfloat16 and bfloat16_array support#3527miantalha45 wants to merge 3 commits intoapache:mainfrom
miantalha45 wants to merge 3 commits intoapache:mainfrom
Conversation
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.
Description
This PR introduces the
bfloat16andbfloat16_arrayprimitives to the Fory Dart runtime, fulfilling the requirement for a memory-efficient brain floating-point formulation commonly used in ML/AI workflows. It strictly mirrors the structural implementations of the existingfloat16work.Fixes #3287
Changes Made
Dart Runtime Type Definitions:
BFloat16as a strongly-typed subclass of theFixedNumbase class, safely wrapping the 16-bit integer representing the representation bits without exposing rawuint16in public math APIs.BFloat16Arrayas a packed contiguous array collection optimally backed byUint16List.IEEE 754 Conversions:
BFloat16.fromFloat32andtoFloat32()doing bitwise round-to-nearest and ties-to-even operations over proxy memory layers (Float32List/Uint32List.view) mapped exactly to cross-language canonical IEEE 754 bfloat16 bit representations.value,toBits(),fromBits()).Reflection & Serialization Integration:
_BFloat16SerializerCacheinsideprimitive_type_serializer.dartdirectly wiring toBFloat16Serializer.BFloat16serialization route inside thetypeToTypeInforegistry inserializer_pool.dart.fory.dartbarrel file.Testing:
0x3f80 == 1.0).BFloat16Arraydynamic generic injections handlingList<dynamic>scaling natively.Type of change
Checklist:
///)dart test)AI Assistance Checklist
AI Usage Disclosure