You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[vulkan] Support VK_KHR_buffer_device_address and PhysicalStorageBuffer #13945
codegen/spirvSPIR-V code generation compiler backendenhancement ➕New feature or requesthal/vulkanRuntime Vulkan GPU HAL backendzombie 🧟Issue/PR is likely stale and will be closed if inactive.
Branching off issue #13196 to see what it would take to implement VK_KHR_buffer_device_address and PhysicalStorageBuffer based access to Vulkan devices. Increasing we are dealing with very large tensors (>4GB) and maxStorageBufferRange is limited to 4GB. While we explore options with #13196 this feature request is to see what it would take to move us to using VK_KHR_buffer_device_address.
We are seeing increasing model sizes Stable Diffusion (768x768) , LLaMA upto 65B etc that we are unable to run on our Vulkan backend today without doing a multi-process hack. We are also starting to see 16GB+ VRAM allocations on mobile SoC devices so this a requirement across the board for vulkan devices.
This would be a major change w.r.t. how we handle buffers across runtime and kernel. What the device buffer address extension does is enabling querying int64 physical GPU addresses for storage buffers so that we can populate them in uniform buffers or push constants and then let kernels directly load them as buffer pointers and do load/store thereafter. So it's pretty substantial, at least at the conceptual level.
Now, regarding what needs to be changed to support this extension, a few big parts:
Runtime-kernel boundary: we'd need a way/convention to make sure we have consistency between runtime (in IREE) and kernel CodeGen (in MLIR). E.g., using a uniform buffer or push constants for all base buffer address. Using push constants avoids indirection but push constants already used for shape dimensions and such. If uniform buffer, which descriptor set. How buffer addresses for different descriptor (set, binding) are organized in the uniform buffer, etc.
Runtime: we'd need to change how push descriptors are handled in the Vulkan HAL driver, to query device buffer address and populate them in the above manner. This actually makes it closer to LLVMGPU side in a sense.
Kernel: we'd need to plumb through support for physical storage buffer and related capabilities in MLIR/SPIR-V CodeGen. And then follow the convention to not generate descriptors but load device pointers directly and use them.
I'd need to talk with @benvanik to get a more detailed picture w.r.t. what's need to be changed, esp. on the runtime side.
Yeah, lots tangled up here - we'll need to break it down. There's some easier solutions and some harder ones for sure :)
I suspect we'll build ArgumentBuffer-like thing in the Vulkan HAL driver and map descriptor sets into that instead of native descriptor sets.
changed the title [-]Vulkan: Investigate using VK_KHR_buffer_device_address and PhysicalStorageBuffer for vulkan memory access[/-][+][vulkan] Support VK_KHR_buffer_device_address and PhysicalStorageBuffer[/+]on Jun 6, 2023
(this was how I was imagining enabling secondary command buffer buffer substitution in iree_hal_command_buffer_execute - so doing it may get us that too!)
Thanks @benvanik for the details! @kuhar will help to flesh out the SPIR-V part:
As we chatted, the majority of the changes can happen in the ConvertToSPIRVPass right now--there is a pre-step there analyzing subspan ops and creating SPIR-V global variables for them. We can add the logic there to perform the extra indirect indexing via the argument/parameter buffer.
The addressing model needs to be PhysicalStorageBuffer64--the spv.module op is directly created in ConvertToSPIRVPass too so should be direct to modify.
And we need to plumb through support for the extension and associated capabilties in the upstream MLIR and IREE SPIR-V CodeGen side.
I opened a PR with the compiler support: #16301, and landed another one with hal device queries for the related Vulkan extension: #16282. There's also a landed MLIR PR for memref to spir-v conversion: llvm/llvm-project#80243.
With these three PRs in the tree and 64-bit indexing enabled, the following e2e compiles but fails at runtime:
codegen/spirvSPIR-V code generation compiler backendenhancement ➕New feature or requesthal/vulkanRuntime Vulkan GPU HAL backendzombie 🧟Issue/PR is likely stale and will be closed if inactive.
Activity
allieculp commentedon Jun 5, 2023
Adding @antiagainst to take a look when you can.
antiagainst commentedon Jun 6, 2023
This would be a major change w.r.t. how we handle buffers across runtime and kernel. What the device buffer address extension does is enabling querying int64 physical GPU addresses for storage buffers so that we can populate them in uniform buffers or push constants and then let kernels directly load them as buffer pointers and do load/store thereafter. So it's pretty substantial, at least at the conceptual level.
Now, regarding what needs to be changed to support this extension, a few big parts:
I'd need to talk with @benvanik to get a more detailed picture w.r.t. what's need to be changed, esp. on the runtime side.
benvanik commentedon Jun 6, 2023
Yeah, lots tangled up here - we'll need to break it down. There's some easier solutions and some harder ones for sure :)
I suspect we'll build ArgumentBuffer-like thing in the Vulkan HAL driver and map descriptor sets into that instead of native descriptor sets.
[-]Vulkan: Investigate using VK_KHR_buffer_device_address and PhysicalStorageBuffer for vulkan memory access[/-][+][vulkan] Support VK_KHR_buffer_device_address and PhysicalStorageBuffer[/+]benvanik commentedon Jun 6, 2023
(this was how I was imagining enabling secondary command buffer buffer substitution in iree_hal_command_buffer_execute - so doing it may get us that too!)
allieculp commentedon Jun 6, 2023
Setting as P2 for now but leaving open for continued conversations and task lists etc. Please edit as needed.
18 remaining items
Adding `--iree-vulkan-experimental-indirect-bindings=true` flag.
Adding `--iree-vulkan-experimental-indirect-bindings=true` flag. (#14977
antiagainst commentedon Sep 28, 2023
Thanks @benvanik for the details! @kuhar will help to flesh out the SPIR-V part:
ConvertToSPIRVPassright now--there is a pre-step there analyzing subspan ops and creating SPIR-V global variables for them. We can add the logic there to perform the extra indirect indexing via the argument/parameter buffer.PhysicalStorageBuffer64--thespv.moduleop is directly created inConvertToSPIRVPasstoo so should be direct to modify.[CodeGen][SPIR-V] Add codegen for Indirect Bindings
kuhar commentedon Feb 2, 2024
I opened a PR with the compiler support: #16301, and landed another one with hal device queries for the related Vulkan extension: #16282. There's also a landed MLIR PR for memref to spir-v conversion: llvm/llvm-project#80243.
With these three PRs in the tree and 64-bit indexing enabled, the following e2e compiles but fails at runtime:
[CodeGen][SPIR-V] Add codegen for Indirect Bindings (#16301)
[spirv] Add explicit layout to the top-level buffer (#16370)