Skip to content

Conversation

@MrSidims
Copy link
Contributor

@MrSidims MrSidims commented Jun 10, 2025

Signed-off-by: Sidorov, Dmitry <[email protected]>
@MrSidims
Copy link
Contributor Author

@svenvh please take a look if such representation makes sense

Copy link
Member

@svenvh svenvh left a comment

Choose a reason for hiding this comment

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

Left some initial thoughts and nits.

@MrSidims MrSidims marked this pull request as ready for review August 1, 2025 15:12
@MrSidims MrSidims requested a review from svenvh August 1, 2025 15:12
@MrSidims
Copy link
Contributor Author

MrSidims commented Aug 1, 2025

@Keenuts @michalpaszkowski please also take a look as I plan to introduce the extension to the SPIR-V backend as well, and contact for the frontends should be identical for both SPIR-V generators.

Remaining TODOs:

  1. Way to make it working with cooperative matrices. Currently internally I'm using bitmasks on the place of cooperative matrix operands of OpCoorerativeMatrixMulAddKHR, but it barely acceptable solution as some might claim the same bits for different purposes;
  2. Way to represent SaturatedToLargestFloat8NormalConversionEXT. There are 2 considirations:
    a. (used in internal implementation) a new builtin-like function for clamp conversions - quite straight forward and robust solution;
    b. spirv.Decorations metadata attached to a one of the appropriate conversion buitins described in this PR - it will work out of a box for the translator, but in general relying semantics on metadata attached to an instruction is not a great design, though here it should work, as it would be attacked on an external function call and middle end transformations should not touch such call.

@Keenuts
Copy link

Keenuts commented Aug 4, 2025

@Keenuts @michalpaszkowski please also take a look as I plan to introduce the extension to the SPIR-V backend as well, and contact for the frontends should be identical for both SPIR-V generators.

Shoud this be an RFC in discourse since it's about how to represent something in the LLVM IR?
From a quick look at other float type additions, seems like the suggested form for those are either opaque target types or i8 as long as it's storage-only.
If we go the i8 way, this means we'll have to do some additional type scavenging to correctly lower the i8 types to either a SPV Int8 or the E4M3/E5M2 type no?

@MrSidims
Copy link
Contributor Author

MrSidims commented Aug 4, 2025

Shoud this be an RFC in discourse since it's about how to represent something in the LLVM IR?

Sure, I can open one.

From a quick look at other float type additions, seems like the suggested form for those are either opaque target types

SPV_EXT_float8 specification allows to have conversion instructions and LLVM won't allow to have target extension type input to fptrunc and other instructions. So we have to introduce builtins or intrinsics to make it working.

or i8 as long as it's storage-only. If we go the i8 way, this means we'll have to do some additional type scavenging to correctly lower the i8 types to either a SPV Int8 or the E4M3/E5M2 type no?

Kind of. For all of the instructions, with an exception of conversions and cooperative-matrix related instructions, it's fine to leave the value be i8. For conversions and matrices - we can insert a bitcast right before (and after if necessary) the use of fp8 value. In this case we won't actually scavenge any type information before lowering to SPIR-V and it won't introduce extra complexity for lowering (apart of necessity to de-mangle the builtins). I actually have an internal implementation for this, just need to make it 'open-source ready' (but it doesn't mean, that I'm not open to change it - I'm keen to adjust it according to the feedback I can get here or elsewhere).

@MrSidims
Copy link
Contributor Author

MrSidims commented Aug 7, 2025

MrSidims added a commit to MrSidims/SPIRV-LLVM-Translator that referenced this pull request Oct 2, 2025
Way it's implemented is described in:
KhronosGroup#3221

Currently only conversion instructions (and internal builtins) are
covered.

TODO: add packed int4 conversion tests and saturation declration
handling.

Signed-off-by: Sidorov, Dmitry <[email protected]>
MrSidims added a commit to MrSidims/SPIRV-LLVM-Translator that referenced this pull request Oct 2, 2025
Way it's implemented is described in:
KhronosGroup#3221

Currently only conversion instructions (and internal builtins) are
covered.

TODO: add packed int4 conversion tests and saturation declration
handling.

Signed-off-by: Sidorov, Dmitry <[email protected]>
MrSidims added a commit to MrSidims/SPIRV-LLVM-Translator that referenced this pull request Oct 2, 2025
Way it's implemented is described in:
KhronosGroup#3221

Currently only conversion instructions (and internal builtins) are
covered.

TODO: add packed int4 conversion tests and saturation declration
handling.

Signed-off-by: Sidorov, Dmitry <[email protected]>
MrSidims added a commit to MrSidims/SPIRV-LLVM-Translator that referenced this pull request Oct 6, 2025
Way they are implemented is described in:
KhronosGroup#3221

The PR also adds SPV_EXT_float8 extension and packed conversions for
SPV_INTEL_int4

Currently only conversion instructions (and internal builtins) are
covered.

TODO: in the following PR Saturation decoration will be added.

Signed-off-by: Sidorov, Dmitry <[email protected]>
MrSidims added a commit to MrSidims/SPIRV-LLVM-Translator that referenced this pull request Oct 6, 2025
Way they are implemented is described in:
KhronosGroup#3221

The PR also adds SPV_EXT_float8 extension and packed conversions for
SPV_INTEL_int4

Currently only conversion instructions (and internal builtins) are
covered.

TODO: in the following PR Saturation decoration will be added.

Signed-off-by: Sidorov, Dmitry <[email protected]>
MrSidims added a commit that referenced this pull request Oct 21, 2025
Way they are implemented is described in:
#3221

The PR also adds SPV_EXT_float8 extension and packed conversions for
SPV_INTEL_int4

Currently only conversion instructions (and internal builtins) are
covered.

TODO: in the following PR Saturation decoration will be added.

Signed-off-by: Sidorov, Dmitry <[email protected]>

---------

Signed-off-by: Sidorov, Dmitry <[email protected]>
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