Skip to content

Read old SPV_INTEL_float4 type for StochasticRound*ToE2M1INTEL#3901

Open
fda0 wants to merge 1 commit into
KhronosGroup:mainfrom
fda0:main_fp4fix
Open

Read old SPV_INTEL_float4 type for StochasticRound*ToE2M1INTEL#3901
fda0 wants to merge 1 commit into
KhronosGroup:mainfrom
fda0:main_fp4fix

Conversation

@fda0

@fda0 fda0 commented Jul 21, 2026

Copy link
Copy Markdown

For backward compatibility of the SPIRV Reader only: older modules
emitted the SPV_INTEL_float4 Float4E2M1INTEL type (6214) as the
StochasticRoundFToFINTEL result. Map it to the same builtin as the
current SPV_EXT_ocp_microscaling_types Float4E2M1EXT type (4225).

The Writer keeps unchanged and emits the EXT type.

@CLAassistant

CLAassistant commented Jul 21, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

; RUN: llvm-spirv %t.spv -o %t.spt --to-text
; RUN: FileCheck < %t.spt %s --check-prefix=CHECK-SPIRV
; The E2M1INTEL builtins must produce the SPV_INTEL_float4 type (encoding 6214),
; not the SPV_EXT_ocp_microscaling_types Float4E2M1EXT type (encoding 4225).

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: personally I think this comment is redundant, because the produced TypeFloat [[#E2M1Ty:]] 4 6214 says it all.

@Qi-Ye-079

Copy link
Copy Markdown
Contributor

LGTM. I can't say I fully know the context of this PR but I think it makes sense technically.

@bashbaug Maybe you know the context better for this one? Please also help review, approve and merge this one if it looks ok to you, as I don't have write permission to approve and merge.

@bashbaug

Copy link
Copy Markdown
Contributor

Note, the "INTEL" suffix should be considered part of the instruction name, not part of the type name, so I disagree that this change should be done for some sort of naming reasons.

I'd also like to move away from SPV_INTEL_float4 if at all possible in the SPIR-V writer, since we have no plans to productize this extension. Ideally, the SPIR-V writer should be generating SPV_EXT_ocp_microscaling_types in all cases, instead. We can continue to support SPV_INTEL_float4 in the SPIR-V reader for some time if needed for backwards compatibility, but eventually we should move away from it, also.

I suggest:

  1. Keep the path that generates the SPV_EXT_ocp_microscaling_types Float4E2M1EXT float encoding as the preferred path when SPV_EXT_ocp_microscaling_types is enabled.
  2. If needed, also support a path that generates the SPV_INTEL_float4 Float4E2M1INTEL float encoding as a backwards compatibility path when SPV_INTEL_float4 is enabled and SPV_EXT_ocp_microscaling_types is NOT enabled, but this won't be a preferred path, and it should eventually be removed.

@fda0 fda0 changed the title Fix StochasticRound*ToE2M1INTEL to emit SPV_INTEL_float4 type Read old SPV_INTEL_float4 type for StochasticRound*ToE2M1INTEL Jul 22, 2026
@fda0

fda0 commented Jul 22, 2026

Copy link
Copy Markdown
Author

@bashbaug @Qi-Ye-079 thanks for the feedback. Pushed an update that is based on previous commit 6734efd

This should be scoped to SPIRV-Reader. The change now simply allows us to use OpStochasticRoundFToFINTEL with E2M1INTEL as was the case with older SPIRV-Reader versions.

Comment thread lib/SPIRV/SPIRVReader.cpp
Comment on lines +1140 to +1142
if (LookupOC == internal::OpStochasticRoundFToFINTEL &&
DstEnc == FPEncodingWrap::E2M1INTEL)
LookupDstEnc = FPEncodingWrap::E2M1;

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.

This is done conditionally right now, only for OpStochasticRoundFToFINTEL, but might we want it to be done unconditionally to fix all usages of the Intel-specific encoding?

We might want to do the same for the source encoding, also.

Even if we decide to do this, I'm fine doing it in a separate PR.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I don't know to be honest why only this case is an issue - but with this conditional fix for OpStochasticRoundFToFINTEL we have full backwards compatibility for SPV_INTEL_float4 right now (at least that's what testing shows). So broadening this is not strictly needed but I can prepare follow up a PR if you think it's a good idea.

; RUN: FileCheck < %t.rev.ll %s --check-prefix=CHECK-LLVM

; CHECK-LLVM: call spir_func i4 @_Z46__builtin_spirv_StochasticRoundFP16ToE2M1INTELDhi(half 1.000000e+00, i32 1)
; CHECK-LLVM: call spir_func i4 @_Z46__builtin_spirv_StochasticRoundBF16ToE2M1INTELDF16bi(bfloat 1.000000e+00, i32 1)

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: you don't need --check-prefix=CHECK-LLVM here; a plain CHECK will suffice.

For backward compatibility of the SPIRV Reader only: older modules
emitted the `SPV_INTEL_float4` `Float4E2M1INTEL` type (6214) as the
`StochasticRoundFToFINTEL` result. Map it to the same builtin as the
current `SPV_EXT_ocp_microscaling_types` `Float4E2M1EXT` type (4225).

The Writer keeps unchanged and emits the EXT type.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

4 participants