Skip to content

Polyfill non-4-byte-aligned fills in the Vulkan HAL. - #7317

Merged
ScottTodd merged 12 commits into
iree-org:mainfrom
ScottTodd:vulkan-fill
Oct 18, 2021
Merged

ScottTodd merged 12 commits into
iree-org:mainfrom
ScottTodd:vulkan-fill

Conversation

@ScottTodd

Copy link
Copy Markdown
Member

This fixes #7228 by introducing a new BuiltinExecutables class under the Vulkan HAL that uses a 1x1x1 dispatch to fill any unaligned bytes within a buffer fill operation. Aligned regions of buffer fills will still use the native vkCmdFillBuffer. New CTS test cases provide coverage for each [pattern_size x offset x fill_length] permutation.

Inserting a dispatch into a command buffer (that was expecting to just have a native vkCmdFillBuffer transfer operation inside it) requires some special handling:

  • Descriptor set layout index 3 is used (Android typically only supports 4, so this is the last slot), to avoid overlap with descriptor set layouts used by the compiler.
  • Push constants are tracked for each command buffer so when this dispatch uses its own push constants it can restore from that backup.
  • Command buffers that may go down this polyfill path need to run on a queue compatible with dispatch operations (i.e. not transfer exclusive). We had some ideas for adding a compiler analysis and attribute for "will only contain aligned fills", but without that I'm just defaulting to command_categories |= IREE_HAL_COMMAND_CATEGORY_DISPATCH where needed.

I have not yet tested this in a real program and there are still a few TODOs for optimal performance and correct synchronization behavior.

@ScottTodd ScottTodd added runtime Relating to the IREE runtime library hal/vulkan Runtime Vulkan GPU HAL backend labels Oct 12, 2021
@google-cla google-cla Bot added the cla: yes label Oct 12, 2021
Fixes this validation layer error when binding an entire buffer that is small:
```
E D:\dev\projects\iree\iree\hal\vulkan\debug_reporter.cc:38] Validation Error: [ VUID-VkDescriptorBufferInfo-range-00342 ] Object 0: handle = 0xec4bec000000000b, type = VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT; | MessageID = 0xe9e00038 | vkCmdPushDescriptorSetKHR() VkWriteDescriptorSet[0] failed update validation: Write update to Push Descriptors defined with VkDescriptorSetLayout 0xec4bec000000000b[] binding #0 failed with error message: Attempted write update to buffer descriptor failed due to: For buffer VkBuffer 0xdcc8fd0000000012[] VkDescriptorBufferInfo range is 4 which is greater than buffer size (2) minus requested offset of 0. The Vulkan spec states: If range is not equal to VK_WHOLE_SIZE, range must be less than or equal to the size of buffer minus offset (https://vulkan.lunarg.com/doc/view/1.2.189.2/windows/1.2-extensions/vkspec.html#VUID-VkDescriptorBufferInfo-range-00342)
```

@benvanik benvanik left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

Comment thread iree/hal/vulkan/builtin/BUILD Resolved
Comment thread iree/hal/vulkan/builtin_executables.cc Resolved
Comment thread iree/hal/vulkan/builtin_executables.cc Resolved
Comment thread iree/hal/vulkan/builtin_executables.h Resolved
Comment thread iree/hal/vulkan/builtin_executables.cc Resolved
This aggregate library will be simpler to include. If we add more shaders and conditionally include them in builds, we can iterate through the iree_file_toc_t array and check the file names before just touching data/size. YAGNI until then.
@ScottTodd
ScottTodd requested a review from benvanik October 18, 2021 21:15
@ScottTodd

Copy link
Copy Markdown
Member Author

Addressed the first round of comments, PTAL

Comment thread iree/hal/vulkan/builtin/BUILD Resolved
@ScottTodd
ScottTodd enabled auto-merge (squash) October 18, 2021 21:39
@ScottTodd
ScottTodd merged commit 4ceb86f into iree-org:main Oct 18, 2021
@ScottTodd
ScottTodd deleted the vulkan-fill branch October 18, 2021 21:51
bjacob pushed a commit to bjacob/iree that referenced this pull request Oct 21, 2021
This fixes iree-org#7228 by introducing a new `BuiltinExecutables` class under the Vulkan HAL that uses a 1x1x1 dispatch to fill any unaligned bytes within a buffer fill operation. Aligned regions of buffer fills will still use the native `vkCmdFillBuffer`. New CTS test cases provide coverage for each [pattern_size x offset x fill_length] permutation.

Inserting a dispatch into a command buffer (that was expecting to just have a native `vkCmdFillBuffer` transfer operation inside it) requires some special handling:

* Descriptor set layout index 3 is used (Android typically only supports 4, so this is the last slot), to avoid overlap with descriptor set layouts used by the compiler.
* Push constants are tracked for each command buffer so when this dispatch uses its own push constants it can restore from that backup.
* Command buffers that may go down this polyfill path need to run on a queue compatible with dispatch operations (i.e. not transfer exclusive). We had some ideas for adding a compiler analysis and attribute for "will only contain aligned fills", but without that I'm just defaulting to `command_categories |= IREE_HAL_COMMAND_CATEGORY_DISPATCH` where needed.

---

I have not yet tested this in a real program and there are still a few TODOs for optimal performance and correct synchronization behavior.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hal/vulkan Runtime Vulkan GPU HAL backend runtime Relating to the IREE runtime library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Polyfill non-4-byte-aligned fills in the Vulkan HAL

2 participants