You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Tracking Issue] [WebGPU] Supporting DP4A in WebGPU backend #16627
I am stuck on the translation of int8 to WGSL so I have to turn to you for help.
Currently WGSL doesn't support 8-bit integers, so in the output WGSL we can only load and store a uint32s as int8x4. What can I do to ask TVM to generate TIR that always loads and stores 4 int8 together instead of loading or storing int8 separately?
The declarations of X_shared and X are easy to handle (for example, I can change var<workgroup> X_shared : array<i8, 228> to var<workgroup> X_shared : array<u32, 57>) while the loop in the load of int8 data is difficult to handle. Could you give me some advice on how to do it?
Here is the python script I used for test. I cannot upload .py files so I just renamed it to .txt. tvm_dp4a.txt
@Jiawei-Shao , in this case. i think we can go with directly creating an array of "int8x4"(aka the vector type), so all loading and store are vectorized. and we lower int8x4 to uint32
Another simpler approach(which could be one step easier) would be to simply first take dp4a as an intrinsic that takes in uint32 and produces the i32. That does mean that we need to write special tvm programs in uint32, but at least this would serve as a first step
here is a simple example writing program directly in int8x4, note that the array of (4,) in int8x4 will be represented as extra dimension (4, 4) in this case, where the lowest dim come from the vector dtype
Activity
tqchen commentedon Feb 27, 2024
Thanks @Jiawei-Shao ! contribution is more than welcomed
Jiawei-Shao commentedon Mar 20, 2024
Hi @tqchen,
I am stuck on the translation of
int8to WGSL so I have to turn to you for help.Currently WGSL doesn't support 8-bit integers, so in the output WGSL we can only load and store a
uint32s asint8x4. What can I do to ask TVM to generate TIR that always loads and stores 4int8together instead of loading or storingint8separately?For example,
will generate below TIR
And it will generate below WGSL (X is an
int8array, which is incorrect in WGSL):While I'd like to have below WGSL (X_shared and X are both
uint32arrays):The declarations of
X_sharedandXare easy to handle (for example, I can changevar<workgroup> X_shared : array<i8, 228>tovar<workgroup> X_shared : array<u32, 57>) while the loop in the load ofint8data is difficult to handle. Could you give me some advice on how to do it?Here is the python script I used for test. I cannot upload
.pyfiles so I just renamed it to.txt.tvm_dp4a.txt
tqchen commentedon Mar 21, 2024
@Jiawei-Shao , in this case. i think we can go with directly creating an array of "int8x4"(aka the vector type), so all loading and store are vectorized. and we lower int8x4 to uint32
tqchen commentedon Mar 21, 2024
Another simpler approach(which could be one step easier) would be to simply first take dp4a as an intrinsic that takes in uint32 and produces the i32. That does mean that we need to write special tvm programs in uint32, but at least this would serve as a first step
vinx13 commentedon Mar 21, 2024
@Jiawei-Shao in this case, we can do
sch.vectorize(ax1)to convert the loop to a vectorized one. https://github.com/apache/tvm/blob/main/src/target/spirv/spirv_utils.cc#L123 will rewrite buffer with vectorized access toint8x4as long as both read and write are vectorized. You may need to use tensorization to vectorize the load from this buffertqchen commentedon Mar 21, 2024
tqchen commentedon Mar 21, 2024
here is a simple example writing program directly in int8x4, note that the array of (4,) in int8x4 will be represented as extra dimension
(4, 4)in this case, where the lowest dim come from the vector dtype[WebGPU] Support `__dp4a(int8x4, int8x4)` as a pure extern method
[WebGPU] Support `__dp4a(int8x4, int8x4)` as a pure extern method
[WebGPU] Translate `int8x4` into `u32`
[WebGPU] Translate `int8x4` into `u32` (#17071)
[WebGPU] Implement `tir.dp4a` with WGSL built-in function `dot4I8Pack…
Jiawei-Shao commentedon Jul 5, 2024
Thanks for all your review!
We can open another issue for the support of tensorization with
dp4aon WebGPU backend.[WebGPU] Translate `int8x4` into `u32` (#17071)
[WebGPU] Implement `tir.dp4a` with WGSL built-in function `dot4I8Pack…
[WebGPU] Translate `int8x4` into `u32` (#17071)
[WebGPU] Implement `tir.dp4a` with WGSL built-in function `dot4I8Pack…