-
Notifications
You must be signed in to change notification settings - Fork 1.1k
[vulkan] Fix vector shuffle for Vulkan CodeGen #8621
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Re-enable vector_shuffle correctness test for Vulkan.
mcourteaux
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good overall. I have a few points of feedback.
Perhaps, as you took my code from the GPU C codegen for this, I suggest we move this into a helper function:
namespace Internal {
std::vector<std::pair<int, int>> calculate_shuffle_vector_and_lane_indices(const Shuffle *s)
}And clean up both CodeGen_GPU and Codegen_Vulkan using this helper. All the sanity checks can then also go in there.
| idx -= vec_lanes; | ||
| } | ||
|
|
||
| } else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I'm not overlooking anything, it seems there is no specialized branch for simply joining (i.e., concatenating) vectors. Either put a TODO comment, make an issue, or add that branch. Falling back on the generic vector shuffle, below, seems like a performance waste.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tracking this here: #8622
|
Also, is this fixable: to actually give a meaningful name to the error code this produced? Khronos spec says:
I'm guessing I get the last one? Weird that that would be NVIDIA specific. |
…dices(). Clean up CodeGen Vulkan Dev comments and asserts.
…ector index mapping now covers this as well.
mcourteaux
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! Thanks :)
All of the above are handled in vk_get_error_name(). In this case the return value was -13 (or VK_ERROR_UNKNOWN). However, if your Vulkan driver supports the debug extension, the runtime registers callbacks to get more information. On my machine I was seeing the following output before this PR: |
|
Ready to land, @derek-gerstmann ? |
|
Yep all good with me! @abadams any objections to us adding a helper method to the IR Shuffle node? |
…ethod name. Simplify vector/lane index method to create all indices, and return each pair. Refactor call sites to use `auto vector_and_lane_indices = op->vector_and_lane_indices()`
src/CodeGen_Vulkan_Dev.cpp
Outdated
|
|
||
| // Sanity check that the total lane count matches between the op-type and indices | ||
| internal_assert(!op->vectors.empty()); | ||
| for (size_t i = 1; i < op->vectors.size(); i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think shuffle nodes are allowed to combine vectors of different sizes. It looks like the removed code handles this, but this assert looks like it would fail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Handling that case looks like it was the whole point of the PR, so I must be missing something. Maybe a longer comment here would help.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, good catch! These asserts seem wrong or out of date ... I lifted them from CodeGen_GPU:
And the date on those lines is from 3 years ago. So my guess is those asserts were written to match the implementation as it was ... without support to handle vectors of different lanes.
Thanks! I'll remove these lines from both CodeGen_Vulkan and CodeGen_GPU.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We actually aren't triggering those asserts at all. Even the test case seems to produce lowered code that has vectors of the same size for the arguments, but only uses a few lanes from the arguments to produce the shuffle. That case wasn't handled correctly before ... it triggered a type mismatch for the assignments which generated invalid code for mixing vector/scalar types of different sizes.
…rent lanes to be mixed between the arguments and result type.
|
Okay to merge? @abadams |
CodeGen wasn't handling arbitrary mixing of vectors with different lanes to form a shuffle, causing a cast instruction to be generated with mixed types which generated invalid SPIR-V and caused the driver compiler to fail to compile.
Now, we handle the extraction of each selected lane of each vector argument, and construct a new Vector from the combined composite.
Fixes #8580