google / google/clspv

Support for physical addressing

Open
#826 3 comments 6 reactions 0 assignees View on GitHub
Dominant language
LLVM
Stars
729
Forks
110
Avg merge
17h 51m
Merged PRs (30d)
23

Description

## Motivation

- Full support for OpenCL C requires physical addressing. While clspv has done a great job of enabling many OpenCL C programs without the use of physical addressing, there will always be programs that cannot be compiled without physical addressing.
- clspv's pointer bitcast rewriting passes are rather complex and tend to require changes when large new code bases are compiled.
- Some OpenCL CTS tests would be easy to pass with physical addressing (e.g. support for `NULL` kernel arguments).
- Physical addressing opens the door to supporting OpenCL SVM or USM which in addition to being desirable features in their own right are also very useful to provide a bridge to enable other programming languages to target Vulkan.

## Proposed design outline

Here's a rough outline of what I prototyped:

- Use the SPV_KHR_physical_storage_buffer extension to enable the use of the **PhysicalStorageBufferEXT** storage class where **StorageBuffer** is currently used.
- Disable pointer transformation passes (pointer bitcast replacement and simplification passes).
- Introduce new runtime interfaces in the clspv non-semantic instruction set to allow passing pointers obtained by the runtime using `VK_KHR_buffer_device_address` via either push constants or uniform buffers. The interface uses a structure of 64-bit integers (or 2-element vectors of 32-bit integers), one for each pointer argument, that is part of the global push constant structure or stored in a dedicated uniform buffer. Pointer arguments to kernel functions are rewritten to load the required integers from this structure and convert them to pointers. A new pass is introduced to declare the interface structure and perform the necessary rewriting.
- Add a new command line option to enable the use of physical addressing where possible (disabled by default)
- Add a new command line option to select the 64-bit addressing model (disabled by default, implied by or required with physical addressing)

## Proposed staging

- [ ] Support 64-bit addressing model (hard requirement of the **PhysicalStorageBuffer64EXT** addressing model)
- [x] Add libclc target (https://reviews.llvm.org/D116668)
- [x] Build libclc as part of clspv's build system
- [x] Add support for 64-bit addressing model https://github.com/google/clspv/pull/936
- [x] Update clspv non-semantic instruction set with new runtime interface instructions
- [x] Specification (https://github.com/KhronosGroup/SPIRV-Registry/pull/153)
- [x] Headers (https://github.com/KhronosGroup/SPIRV-Headers/pull/284)
- [x] Use in clspv and other dependent projects (e.g. SPIR-V Tools)
- [x] Introduce utilities to manage global push constants https://github.com/google/clspv/pull/882
- [x] Add support for physical addressing (using 64-bit integers) https://github.com/google/clspv/pull/954
- [ ] Add support for physical addressing (using 2-element vectors of 32-bit integers) https://github.com/google/clspv/issues/956

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.