[TOPI][Vulkan, Metal] Avoid passing int64 scalar arg to VK/Metal runtime #7457
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I hit the error below when running TIR sort/scan on Vulkan backend:
tvm/src/runtime/pack_args.h
Line 186 in 1831c17
This is because unlike most other kernels, TIR sort/scan needs to pass an integer scalar from host to GPU, to realize multipass kernel launches:
tvm/python/tvm/topi/cuda/sort.py
Lines 203 to 206 in 1e0d356
Currently,
width
argument, which is int64 scalar, is passed to GPU backend runtime. But VK/Metal runtime use the calling convention that is different from the one used in CUDA/OpenCL (search forPackFuncNonBufferArg
) and VK/Metal runtime don't support passing 64 bit scalar, see:tvm/src/runtime/pack_args.h
Lines 41 to 49 in 1831c17
tvm/src/runtime/vulkan/vulkan.cc
Line 1047 in 1831c17
The fix to this problem is simply to pass int32 scalar instead, and does cast to int64 inside GPU kernel. This enabled TIR scan tests to pass on Vulkan. It also fixed the runtime error that happened while running TIR sort, but the sort result is still not correct on Vulkan. I suspect there is an issue in our SPIR-V codegen.