1// RUN: mlir-spirv-cpu-runner %s -e main --entry-point-result=void --shared-libs=%mlir_runner_utils_dir/libmlir_runner_utils%shlibext,%spirv_wrapper_library_dir/libmlir_test_spirv_cpu_runner_c_wrappers%shlibext
2
3// CHECK: [8,  8,  8,  8,  8,  8]
4module attributes {
5  gpu.container_module,
6  spv.target_env = #spv.target_env<
7    #spv.vce<v1.0, [Shader], [SPV_KHR_variable_pointers]>,
8    #spv.resource_limits<
9     max_compute_workgroup_invocations = 128,
10     max_compute_workgroup_size = [128, 128, 64]>>
11} {
12  gpu.module @kernels {
13    gpu.func @double(%arg0 : memref<6xi32>, %arg1 : memref<6xi32>)
14      kernel attributes { spv.entry_point_abi = #spv.entry_point_abi<local_size = dense<[1, 1, 1]>: vector<3xi32>>} {
15      %factor = arith.constant 2 : i32
16
17      %i0 = arith.constant 0 : index
18      %i1 = arith.constant 1 : index
19      %i2 = arith.constant 2 : index
20      %i3 = arith.constant 3 : index
21      %i4 = arith.constant 4 : index
22      %i5 = arith.constant 5 : index
23
24      %x0 = memref.load %arg0[%i0] : memref<6xi32>
25      %x1 = memref.load %arg0[%i1] : memref<6xi32>
26      %x2 = memref.load %arg0[%i2] : memref<6xi32>
27      %x3 = memref.load %arg0[%i3] : memref<6xi32>
28      %x4 = memref.load %arg0[%i4] : memref<6xi32>
29      %x5 = memref.load %arg0[%i5] : memref<6xi32>
30
31      %y0 = arith.muli %x0, %factor : i32
32      %y1 = arith.muli %x1, %factor : i32
33      %y2 = arith.muli %x2, %factor : i32
34      %y3 = arith.muli %x3, %factor : i32
35      %y4 = arith.muli %x4, %factor : i32
36      %y5 = arith.muli %x5, %factor : i32
37
38      memref.store %y0, %arg1[%i0] : memref<6xi32>
39      memref.store %y1, %arg1[%i1] : memref<6xi32>
40      memref.store %y2, %arg1[%i2] : memref<6xi32>
41      memref.store %y3, %arg1[%i3] : memref<6xi32>
42      memref.store %y4, %arg1[%i4] : memref<6xi32>
43      memref.store %y5, %arg1[%i5] : memref<6xi32>
44      gpu.return
45    }
46  }
47  func.func @main() {
48    %input = memref.alloc() : memref<6xi32>
49    %output = memref.alloc() : memref<6xi32>
50    %four = arith.constant 4 : i32
51    %zero = arith.constant 0 : i32
52    %input_casted = memref.cast %input : memref<6xi32> to memref<?xi32>
53    %output_casted = memref.cast %output : memref<6xi32> to memref<?xi32>
54    call @fillI32Buffer(%input_casted, %four) : (memref<?xi32>, i32) -> ()
55    call @fillI32Buffer(%output_casted, %zero) : (memref<?xi32>, i32) -> ()
56
57    %one = arith.constant 1 : index
58    gpu.launch_func @kernels::@double
59        blocks in (%one, %one, %one) threads in (%one, %one, %one)
60        args(%input : memref<6xi32>, %output : memref<6xi32>)
61    %result = memref.cast %output : memref<6xi32> to memref<*xi32>
62    call @printMemrefI32(%result) : (memref<*xi32>) -> ()
63    return
64  }
65
66  func.func private @fillI32Buffer(%arg0 : memref<?xi32>, %arg1 : i32)
67  func.func private @printMemrefI32(%ptr : memref<*xi32>)
68}
69