[TOPI][Vulkan, Metal] Avoid passing int64 scalar arg to VK/Metal runtime - #7457
[TOPI][Vulkan, Metal] Avoid passing int64 scalar arg to VK/Metal runtime#7457masahi wants to merge 2 commits into
Conversation
|
Thanks masa, perhaps it is a good time to revisit whether Vulkan metal could work with i64. |
|
Does it make sense to use |
|
Maybe a more straightforward approach is to send a scalar as a buffer of size 1, just like CUDA/OpenCL backend does. |
|
I take another look and it seems that both vulkan and metal(after metal 2.2) now support i64. Perhaps we could update the ArgUnion solution of these APIs to allow pass 64 bit integer. For example union ArgUnion64 {
int32_t v_int32;
uint32_t v_uint32;
float v_float32;
int64_t v_int64;
}'On the device end, always create array of size two @masahi do you mind to make that change and test out instead? |
|
ok I'll try that |
|
The way device side works is through creating a struct. say the original function is We generate the following device code: |
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,
widthargument, 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.