From 2f800df89d9e4ba366a1285b4246f286680951a6 Mon Sep 17 00:00:00 2001 From: Jiawei Shao Date: Fri, 7 Jun 2024 21:03:29 +0800 Subject: [PATCH] [WebGPU] Translate `int8x4` into `u32` (#17071) 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 --- src/target/source/codegen_webgpu.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/target/source/codegen_webgpu.cc b/src/target/source/codegen_webgpu.cc index f62e0db7ffdf..a95f6e0fa04a 100644 --- a/src/target/source/codegen_webgpu.cc +++ b/src/target/source/codegen_webgpu.cc @@ -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 << "<"; }