Skip to content

Represent FP4 E2M1 with SPV_EXT_ocp_microscaling_types#3828

Open
vmaksimo wants to merge 6 commits into
KhronosGroup:mainfrom
vmaksimo:fp4-e2m1-ocp-microscaling
Open

Represent FP4 E2M1 with SPV_EXT_ocp_microscaling_types#3828
vmaksimo wants to merge 6 commits into
KhronosGroup:mainfrom
vmaksimo:fp4-e2m1-ocp-microscaling

Conversation

@vmaksimo

@vmaksimo vmaksimo commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Switch the FP4 (E2M1) type from SPV_INTEL_float4 extension to the multi-vendor SPV_EXT_ocp_microscaling_types extension.

Plain FP4 conversion builtins get the EXT postfix (e.g. ConvertE2M1ToFP16EXT);
stochastic-rounding builtins keep the INTEL postfix as their operation belongs to SPV_INTEL_fp_conversions.

Specs:

Note:
In this patch we still accept both SPV_INTEL_float4 and SPV_EXT_ocp_microscaling_types encodings for E2M1; each encoding round-trips to its own builtin. The reason is not all producers/consumers are ready to switch to the new extension yet. At the same time, we want to introduce E2M1 through SPV_EXT_ocp_microscaling_types ASAP for those who are ready and willing to switch to it.

AI-assisted: Claude Opus 4.8 (commercial SaaS)

@vmaksimo vmaksimo force-pushed the fp4-e2m1-ocp-microscaling branch from 1d18f64 to 64eb474 Compare July 3, 2026 16:16
Add the multi-vendor SPV_EXT_ocp_microscaling_types extension as the preferred
representation for the FP4 (E2M1) type, alongside the existing Intel-only
SPV_INTEL_float4 extension.

Plain FP4 conversion builtins are recognized with both the EXT postfix (e.g.
ConvertE2M1ToFP16EXT, mapping to the Float4E2M1EXT encoding and Float4EXT
capability) and the INTEL postfix (ConvertE2M1ToFP16INTEL, mapping to the
Float4E2M1INTEL encoding and capability).
The two encodings translate independently in both directions, so a module using
either extension round-trips to the matching builtin.
Stochastic-rounding builtins keep the INTEL postfix as their operation belongs
to SPV_INTEL_fp_conversions.

The Float4EXT capability and the Float4E2M1EXT floating-point encoding are
published in the core enums by SPV_EXT_ocp_microscaling_types, so bump the
SPIRV-Headers pin to that revision and reference the published symbols directly
instead of internal copies, matching how the other EXT float encodings are used.

AI-assisted: Claude Opus 4.8 (commercial SaaS)
@vmaksimo vmaksimo force-pushed the fp4-e2m1-ocp-microscaling branch from 64eb474 to 303ea6f Compare July 4, 2026 12:06
Complete the switch to SPV_EXT_ocp_microscaling_types by removing the
SPV_INTEL_float4 representation of the FP4 (E2M1) type: the Float4E2M1INTEL
encoding (6214) and capability (6212), the INTEL-postfix conversion builtins,
and the reader paths that recognized them.

FP4 values are now represented exclusively with the Float4E2M1EXT encoding;
FP4 matrix operands are still passed as packed integers.
Float4E2M1CooperativeMatrixINTEL is retained: it gates FP4 cooperative-matrix
component types, which use the Float4E2M1EXT encoding.

AI-assisted: Claude Opus 4.8 (commercial SaaS)
@vmaksimo vmaksimo force-pushed the fp4-e2m1-ocp-microscaling branch from 303ea6f to 28ac54b Compare July 4, 2026 12:18
@Qi-Ye-079

Copy link
Copy Markdown
Contributor

@YuriPlyakhin 2nd commit reverted

Comment thread test/extensions/INTEL/SPV_INTEL_float4/conversions_packed.ll
Comment thread test/extensions/EXT/SPV_EXT_ocp_microscaling_types/upscale_o0.ll
Comment thread test/extensions/EXT/SPV_EXT_ocp_microscaling_types/upscale_o2.ll
Comment thread lib/SPIRV/SPIRVReader.cpp
@Qi-Ye-079 Qi-Ye-079 force-pushed the fp4-e2m1-ocp-microscaling branch from 04e8d1c to ce3f220 Compare July 10, 2026 15:44
Comment thread test/extensions/EXT/SPV_EXT_ocp_microscaling_types/conversions_both_encodings.ll Outdated
Comment thread test/extensions/INTEL/SPV_INTEL_float4/conversions_intel_encoding.ll Outdated
; for scalar

; RUN: llvm-spirv %s -o %t.spv --spirv-ext=+SPV_EXT_float8,+SPV_INTEL_float4,+SPV_INTEL_int4,+SPV_KHR_bfloat16,+SPV_INTEL_fp_conversions
; RUN: llvm-spirv %s -o %t.spv --spirv-ext=+SPV_EXT_float8,+SPV_EXT_ocp_microscaling_types,+SPV_INTEL_int4,+SPV_KHR_bfloat16,+SPV_INTEL_fp_conversions

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: spirv-val?

__builtin_spirv_ConvertE2M1ToFP16EXT, __builtin_spirv_ConvertE2M1ToBF16EXT,
__builtin_spirv_ConvertFP16ToE2M1EXT, __builtin_spirv_ConvertBF16ToE2M1EXT

For backward compatibility the equivalent INTEL-postfix builtins (e.g. *__builtin_spirv_ConvertE2M1ToFP16INTEL*)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit

Suggested change
For backward compatibility the equivalent INTEL-postfix builtins (e.g. *__builtin_spirv_ConvertE2M1ToFP16INTEL*)
For backward compatibility, the equivalent INTEL-postfix builtins (e.g. *__builtin_spirv_ConvertE2M1ToFP16INTEL*)

@YuriPlyakhin YuriPlyakhin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (just couple nits left)

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.

3 participants