Skip to content

Commit

Permalink
[WebGPU] Translate int8x4 into u32 (#17071)
Browse files Browse the repository at this point in the history
This patch translates an `int8x4` into a `u32` in WGSL shaders as
8-bit integers are not supported in WebGPU right now and the WGSL
built-in function `dot4I8Packed()` accepts `u32` as its inputs and
each of the `u32` value logically represents a 4-element 8-bit
integer vector.

issue: #16627
  • Loading branch information
Jiawei-Shao authored Jun 7, 2024
1 parent 57914ff commit 2f800df
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/target/source/codegen_webgpu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,11 @@ void CodeGenWebGPU::PrintType(DataType t, std::ostream& os) { // NOLINT(*)

if (lanes != 1) {
ICHECK(lanes >= 2 && lanes <= 4) << "CodeGenWebGPU: only allows vector with lanes in {2, 3, 4}";
// Currently WebGPU doesn't support `i8` and an `int8x4` is represented as a `u32`.
if (t.is_int() && t.bits() == 8 && lanes == 4) {
os << "u32";
return;
}
os << "vec" << lanes << "<";
}

Expand Down

0 comments on commit 2f800df

Please sign in to comment.