[RFC] More flexible floating-point type specification
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 35/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Active
- Domain
- backend-api-design
Research direction
Start with the kDLDataTypeCode enum and DLDataType definition in include/dlpack/dlpack.h, then read the linked MLIR discussion and issue #184 comment for compatibility context. The open questions, especially float8_e4m3b11fnuz and ABI constraints, need resolution before an implementation can be considered done.
Written by the indexing model from the issue text.
Description
Motivation
There are a large number of floating-point types in DLPack, especially 4-bit and 8-bit variants. The structure to define new FP types for DLPack exchange currently requires modifications to DLPack itself, and this RFC aims to relax that limitation.
MLIR moved to a more flexible system in the beginning of last year (discussion, PR), and I feel we should follow in their footsteps.
@seberg commented in a different issue that a way forward without ABI breakage would be a requirement to do this short-term, and I agree.
Proposal
This RFC proposes a few things, that when taken together, allow one to specify many¹ floating point types.
- The introduction of two new enum values in the
kDLDataTypeCodeenum: kDLFlexibleFloat and kDLFlexibleComplex. - That the
DLDataTypestruct be turned into a (C-style) union. The existing layout would become the first variant of the struct, and the second variant is specified below.
typedef struct {
/*!
* \brief Type code of base types.
* We keep it uint8_t instead of DLDataTypeCode for minimal memory
* footprint, but the value should be one of DLDataTypeCode enum values.
* */
uint8_t code;
/*!
* \brief Number of bits minus one, common choices are 2, 4, 8, 16, 32, 64.
* For complex, specify the number of bits for the components rather than the whole.
*/
uint8_t bitsm1;
/*!
* \brief Number of mantissa bits.
* Implies number of exponent bits are bits - 1 - mantissa in the common case.
* mantissa = 0 specifies an exponent-only format (one example is float8_e8m0fnu)
*/
uint8_t mantissa;
/*!
* \brief The flags associated with this FP type.
* Beginning with the LSB:
* Bit 0: Finite bit, often specified by f
* Bit 1: NaN bit, often specified by n
* Bit 2: (Signed) zero bit, often specified by z
* Bit 3: Unsigned zero bit, often specified by uz
* Bits 5-7: Reserved.
*/
uint8_t flags;
/*! \brief Specifies the number of lanes in the type, used for vector types.
* The value should be raised to a power of two, i.e., a value of 5 means 32 lanes.
*/
uint8_t p2lanes;
} DLDataTypeFloatingSpec;
This variant of the struct is only activated by the two enum values above. The existing enum and equivalents here would be considered aliases to each other, but implementations are not required to support the latter if they already support the former.
Open Questions
The float8_e4m3b11fnuz type is not covered by this proposal in its current form. I'm currently debating how best to address that. Options are:
- Leave it as out of scope/requiring its own enum value.
- Split
p2lanesinto two 4-bit fields, one forp2lanesand the other forbias. - Use the reserved bits for
biasinstead. - Use a combination to increase the bits available to
bias.
¹ I would consider non IEEE-style types such as POSIT and TAKUM to be explicitly excluded from the scope of this proposal, perhaps to be addressed by future flags.
cc @seberg and @hpkfft as they showed interest.
- Dominant language
- C++
- Stars
- 1.3k
- Forks
- 168
- Avg merge
- 1m
- Merged PRs (30d)
- 2
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from dmlc/dlpack
-
SpecificationOpen
Difficulty 2/5 1-3 hours Newbie friendliness 57/100
-
Difficulty 5/5 Over a week Newbie friendliness 30/100
-
Difficulty 5/5 Over a week Newbie friendliness 30/100
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
Maintainers usually reply within 1 day
-
[BUG] VPN auth dialog spawned by the secret agent fails with "TLS support is not available" on NixOSOpenbug nixos umbriel
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
noctalia-dev/noctalia#5310 ·
Maintainers usually reply within 1 day
-
area/docdb kind/bug priority/medium status/awaiting-triage
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
yugabyte/yugabyte-db#37426 ·
Maintainers usually reply within 1 day
-
[Engine] Two prompt block scorers enabled at once: WMMA silently wins and no log line is printedOpen
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Niko1221/Strata#5693 · 2 comments ·
Maintainers usually reply within 4 days
-
Difficulty 1/5 Under an hour Newbie friendliness 82/100
facebookresearch/faiss#5878 ·
Maintainers usually reply within 2 days