Skip to content

[vulkan] Support VK_KHR_buffer_device_address and PhysicalStorageBuffer #13945

Open

Description

@powderluv

Request description

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.

Some other references:
https://gpuopen-librariesandsdks.github.io/VulkanMemoryAllocator/html/enabling_buffer_device_address.html ? There were some references to it from KhronosGroup/Vulkan-Docs#1016

@antiagainst @benvanik @stellaraccident

What component(s) does this issue relate to?

No response

Additional context

No response

Activity

  1. added
    enhancement ➕
    on Jun 5, 2023
  2. added this to the Collab: Nod.ai milestone on Jun 5, 2023
  3. allieculp commented on Jun 5, 2023

    @allieculp

    Adding @antiagainst to take a look when you can.

  4. antiagainst commented on Jun 6, 2023

    @antiagainst
    Member

    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.

  5. added
    hal/vulkan
    codegen/spirv
    on Jun 6, 2023
  6. benvanik commented on Jun 6, 2023

    @benvanik
    Collaborator

    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.

  7. 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
  8. self-assigned this
    on Jun 6, 2023
  9. benvanik commented on Jun 6, 2023

    @benvanik
    Collaborator

    (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!)

  10. allieculp commented on Jun 6, 2023

    @allieculp

    Setting as P2 for now but leaving open for continued conversations and task lists etc. Please edit as needed.

  11. moved this from Inbox to Needs Scheduling in (Deprecated) IREEon Jun 6, 2023
  12. 18 remaining items

  13. antiagainst commented on Sep 28, 2023

    @antiagainst
    Member

    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.
  14. kuhar commented on Feb 2, 2024

    @kuhar
    Member

    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:

    $ ninja iree-compile ~/iree/iree/tests/e2e/stablehlo_ops/add.mlir --iree-hal-target-backends=vulkan-spirv --iree-vulkan-target-triple=rdna3-7900-linux --iree-vulkan-experimental-indirect-bindings=true -o add.vmfb --mlir-disable-threading --mlir-print-ir-after-all 2>add_all.log
    $ tools/iree-check-module --module=add.vmfb --device=vulkan://0
  15. added
    zombie 🧟
    on Jul 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

codegen/spirvenhancement ➕hal/vulkanzombie 🧟

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions