KhronosGroup / KhronosGroup/SPIRV-LLVM-Translator

Core SPIR-V feature `SubgroupSize` is translated to non-core attribute `intel_reqd_sub_group_size`

Open
#3,742 4 comments 0 reactions 1 assignee Claimed by @vmaksimo View on GitHub
Dominant language
LLVM
Stars
625
Forks
279
Avg merge
3d 5h
Merged PRs (30d)
34

Description

It appears that the[ `SubgroupSize` execution mode](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#Execution_Mode) is being translated to the attribute `intel_reqd_sub_group_size`. This is surprising, as `SubgroupSize` is a core part of SPIR-V (since version 1.1), while the `intel_reqd_sub_group_size` annotation is part of a (non-core) [OpenCL vendor extension](https://registry.khronos.org/OpenCL/extensions/intel/cl_intel_required_subgroup_size.html).

Attached are an example SPIR-V assembly kernel, along with the llvm IR that the translator emits by default. The pertinent sections are:

SPIR-V:
```
OpEntryPoint Kernel %11 "kernel"
OpExecutionMode %11 ContractionOff
; CHECK: !intel_reqd_sub_group_size [[METADATA:\![0-9]+]]
; CHECK: [[METADATA]] = !{i32 42}
OpExecutionMode %11 SubgroupSize 42
```

LLVM:
```llvm
; Function Attrs: nounwind
define spir_kernel void @kernel(...) ... !intel_reqd_sub_group_size !15
...
!15 = !{i32 42}
```

Is this intended behaviour? I'm aware that a consumer of SPIR-V may not always go through the translator, but for consumers who *do*, it seems odd to translate to a vendor-specific OpenCL extension for a core language feature.

My opinion is that this should be changed so that it translates to a vendor-agnostic attribute, which vendors (or consumers) can translate into internal representations (such as intel's existing attribute), or implement directly.

I'd be keen to hear any background or rationale for the current implementation.

[subgroup_size.spvasm.txt](https://github.com/user-attachments/files/27520175/subgroup_size.spvasm.txt)
[subgroup_size_.spvasm.tmp.ll.txt](https://github.com/user-attachments/files/27520174/subgroup_size_.spvasm.tmp.ll.txt)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.