1 // Make sure that signed extended multiplication produces expected results
2 // with and without expansion to primitive mul/add ops for WebGPU.
4 // RUN: mlir-vulkan-runner %s \
5 // RUN: --shared-libs=%vulkan-runtime-wrappers,%mlir_runner_utils \
6 // RUN: --entry-point-result=void | FileCheck %s
8 // RUN: mlir-vulkan-runner %s --vulkan-runner-spirv-webgpu-prepare \
9 // RUN: --shared-libs=%vulkan-runtime-wrappers,%mlir_runner_utils \
10 // RUN: --entry-point-result=void | FileCheck %s
12 // CHECK: [0, 1, -2, 1, 1048560, -87620295, -131071, 560969770]
13 // CHECK: [0, 0, -1, 0, 0, -1, 0, -499807318]
16 spirv.target_env = #spirv.target_env<
17 #spirv.vce<v1.4, [Shader], [SPV_KHR_storage_buffer_storage_class]>, #spirv.resource_limits<>>
20 gpu.func @kernel_add(%arg0 : memref<8xi32>, %arg1 : memref<8xi32>, %arg2 : memref<8xi32>, %arg3 : memref<8xi32>)
21 kernel attributes { spirv.entry_point_abi = #spirv.entry_point_abi<workgroup_size = [1, 1, 1]>} {
23 %lhs = memref.load %arg0[%0] : memref<8xi32>
24 %rhs = memref.load %arg1[%0] : memref<8xi32>
25 %low, %hi = arith.mulsi_extended %lhs, %rhs : i32
26 memref.store %low, %arg2[%0] : memref<8xi32>
27 memref.store %hi, %arg3[%0] : memref<8xi32>
33 %buf0 = memref.alloc() : memref<8xi32>
34 %buf1 = memref.alloc() : memref<8xi32>
35 %buf2 = memref.alloc() : memref<8xi32>
36 %buf3 = memref.alloc() : memref<8xi32>
37 %i32_0 = arith.constant 0 : i32
39 // Initialize output buffers.
40 %buf4 = memref.cast %buf2 : memref<8xi32> to memref<?xi32>
41 %buf5 = memref.cast %buf3 : memref<8xi32> to memref<?xi32>
42 call @fillResource1DInt(%buf4, %i32_0) : (memref<?xi32>, i32) -> ()
43 call @fillResource1DInt(%buf5, %i32_0) : (memref<?xi32>, i32) -> ()
45 %idx_0 = arith.constant 0 : index
46 %idx_1 = arith.constant 1 : index
47 %idx_8 = arith.constant 8 : index
49 // Initialize input buffers.
50 %lhs_vals = arith.constant dense<[0, 1, -1, -1, 65535, 65535, -65535, 2088183954]> : vector<8xi32>
51 %rhs_vals = arith.constant dense<[0, 1, 2, -1, 16, -1337, -65535, -1028001427]> : vector<8xi32>
52 vector.store %lhs_vals, %buf0[%idx_0] : memref<8xi32>, vector<8xi32>
53 vector.store %rhs_vals, %buf1[%idx_0] : memref<8xi32>, vector<8xi32>
55 gpu.launch_func @kernels::@kernel_add
56 blocks in (%idx_8, %idx_1, %idx_1) threads in (%idx_1, %idx_1, %idx_1)
57 args(%buf0 : memref<8xi32>, %buf1 : memref<8xi32>, %buf2 : memref<8xi32>, %buf3 : memref<8xi32>)
58 %buf_low = memref.cast %buf4 : memref<?xi32> to memref<*xi32>
59 %buf_hi = memref.cast %buf5 : memref<?xi32> to memref<*xi32>
60 call @printMemrefI32(%buf_low) : (memref<*xi32>) -> ()
61 call @printMemrefI32(%buf_hi) : (memref<*xi32>) -> ()
64 func.func private @fillResource1DInt(%0 : memref<?xi32>, %1 : i32)
65 func.func private @printMemrefI32(%ptr : memref<*xi32>)