This is an archive of the discontinued LLVM Phabricator instance.

[SPIRV] Add support for SPV_KHR_bit_instructions
AbandonedPublic

Authored by pmatos on Jul 31 2023, 3:11 AM.

Details

Summary

Draft version of patch to add support for SPV_KHR_bit_instructions.

Created revision so we can discuss how to proceed here.
SPV_KHR_bit_instructions (http://htmlpreview.github.io/?https://github.com/KhronosGroup/SPIRV-Registry/blob/main/extensions/KHR/SPV_KHR_bit_instructions.html),
adds support for instructions that we already support through
the Shader capability but without requiring the shader cap.

However we currently have no way to disable the shader cap afaiu.
On the other hand, SPV_KHR_bit_instructions was one of the
extensions @mpaszkowski listed that we need to implement.

So what does it mean at the moment the need to implement this?
Is it just the ability to issue the extension and capabilities
instructions without issuing the Shader capability? If so,
then I will need to add here a way to disable the Shader
capability. What do you think?

Diff Detail

Event Timeline

pmatos created this revision.Jul 31 2023, 3:11 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 31 2023, 3:11 AM
pmatos requested review of this revision.Jul 31 2023, 3:11 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 31 2023, 3:11 AM

For such cases, we can use SPIRV translator as a reference tool. You can build it (https://github.com/KhronosGroup/SPIRV-LLVM-Translator) and run to see what output it generates. It also has a set of tests that we partly adopted for our backend, so you can use its test base to search for tests of some functionality and reuse them.

For example, they have test/transcoding/cl_khr_extended_bit_ops.cl for SPV_KHR_bit_instructions extension. Here is the beginning of SPIRV, which the translator outputs:

...
               OpCapability Addresses
               OpCapability Linkage
               OpCapability Kernel
               OpCapability Vector16
               OpCapability Int64
               OpCapability Int16
               OpCapability Int8
               OpCapability BitInstructions
               OpExtension "SPV_KHR_bit_instructions"
          %1 = OpExtInstImport "OpenCL.std"
...

There is no Shader capability but we have BitInstructions capability and SPV_KHR_bit_instructions extension (as you suggested).

pmatos added a comment.Aug 1 2023, 1:42 AM

For such cases, we can use SPIRV translator as a reference tool. You can build it (https://github.com/KhronosGroup/SPIRV-LLVM-Translator) and run to see what output it generates. It also has a set of tests that we partly adopted for our backend, so you can use its test base to search for tests of some functionality and reuse them.

For example, they have test/transcoding/cl_khr_extended_bit_ops.cl for SPV_KHR_bit_instructions extension. Here is the beginning of SPIRV, which the translator outputs:

...
               OpCapability Addresses
               OpCapability Linkage
               OpCapability Kernel
               OpCapability Vector16
               OpCapability Int64
               OpCapability Int16
               OpCapability Int8
               OpCapability BitInstructions
               OpExtension "SPV_KHR_bit_instructions"
          %1 = OpExtInstImport "OpenCL.std"
...

There is no Shader capability but we have BitInstructions capability and SPV_KHR_bit_instructions extension (as you suggested).

OK - thanks. I think you confirmed what I wanted to know.
When using these instructions, we can use BitInstructions, instead of Shader cap. This means that the current hardcoded (afaiu) Shader cap will need to be optionally enabled only when required.

pmatos updated this revision to Diff 549919.Aug 14 2023, 7:07 AM

Implement support for dropping the shader capability if BitInstructions is all that's needed.

Still need to add some tests ensuring this works and that we never use both Shader and BitInstructions capability since that's redundant.

pmatos updated this revision to Diff 550198.Aug 14 2023, 11:47 PM

Modify test OpBitReverse* to use BitInstructions.
Add bit instructions as available cap.

Still need to add some tests ensuring this works and that we never use both Shader and BitInstructions capability since that's redundant.

Are you going to add these tests in this patch or later?

pmatos abandoned this revision.Sep 13 2023, 7:57 AM

Still need to add some tests ensuring this works and that we never use both Shader and BitInstructions capability since that's redundant.

Are you going to add these tests in this patch or later?

In this patch. Moving to GitHub PR: https://github.com/llvm/llvm-project/pull/66215