aboutsummaryrefslogtreecommitdiff
path: root/mlir/test/mlir-vulkan-runner/time.mlir
blob: 1e86f66877edfba1331a644a9c26a0dfecbad8fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// RUN: mlir-vulkan-runner %s --shared-libs=%vulkan-runtime-wrappers,%mlir_runner_utils --entry-point-result=void | FileCheck %s

// CHECK: Compute shader execution time
// CHECK: Command buffer submit time
// CHECK: Wait idle time

module attributes {
  gpu.container_module,
  spirv.target_env = #spirv.target_env<
    #spirv.vce<v1.0, [Shader], [SPV_KHR_storage_buffer_storage_class]>, #spirv.resource_limits<>>
} {
  gpu.module @kernels {
    gpu.func @kernel_add(%arg0 : memref<16384xf32>, %arg1 : memref<16384xf32>, %arg2 : memref<16384xf32>)
      kernel attributes { spirv.entry_point_abi = #spirv.entry_point_abi<workgroup_size = [128, 1, 1]>} {
      %bid = gpu.block_id x
      %tid = gpu.thread_id x
      %cst = arith.constant 128 : index
      %b = arith.muli %bid, %cst : index
      %0 = arith.addi %b, %tid : index
      %1 = memref.load %arg0[%0] : memref<16384xf32>
      %2 = memref.load %arg1[%0] : memref<16384xf32>
      %3 = arith.addf %1, %2 : f32
      memref.store %3, %arg2[%0] : memref<16384xf32>
      gpu.return
    }
  }

  func.func @main() {
    %arg0 = memref.alloc() : memref<16384xf32>
    %arg1 = memref.alloc() : memref<16384xf32>
    %arg2 = memref.alloc() : memref<16384xf32>
    %0 = arith.constant 0 : i32
    %1 = arith.constant 1 : i32
    %2 = arith.constant 2 : i32
    %value0 = arith.constant 0.0 : f32
    %value1 = arith.constant 1.1 : f32
    %value2 = arith.constant 2.2 : f32
    %arg3 = memref.cast %arg0 : memref<16384xf32> to memref<?xf32>
    %arg4 = memref.cast %arg1 : memref<16384xf32> to memref<?xf32>
    %arg5 = memref.cast %arg2 : memref<16384xf32> to memref<?xf32>
    call @fillResource1DFloat(%arg3, %value1) : (memref<?xf32>, f32) -> ()
    call @fillResource1DFloat(%arg4, %value2) : (memref<?xf32>, f32) -> ()
    call @fillResource1DFloat(%arg5, %value0) : (memref<?xf32>, f32) -> ()

    %cst1 = arith.constant 1 : index
    %cst128 = arith.constant 128 : index
    gpu.launch_func @kernels::@kernel_add
        blocks in (%cst128, %cst1, %cst1) threads in (%cst128, %cst1, %cst1)
        args(%arg0 : memref<16384xf32>, %arg1 : memref<16384xf32>, %arg2 : memref<16384xf32>)
    %arg6 = memref.cast %arg5 : memref<?xf32> to memref<*xf32>
    return
  }
  func.func private @fillResource1DFloat(%0 : memref<?xf32>, %1 : f32)
  func.func private @printMemrefF32(%ptr : memref<*xf32>)
}