brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.4 KiB · e385dae Raw
80 lines · plain
1// RUN: mlir-opt %s -pass-pipeline='builtin.module(spirv-attach-target{ver=v1.0 caps=Addresses,Int64,Kernel},convert-gpu-to-spirv{use-64bit-index=true},gpu.module(spirv.module(spirv-lower-abi-attrs,spirv-update-vce)),func.func(llvm-request-c-wrappers),convert-scf-to-cf,convert-cf-to-llvm,convert-arith-to-llvm,convert-math-to-llvm,convert-func-to-llvm,gpu-to-llvm{use-bare-pointers-for-kernels=true},gpu-module-to-binary,expand-strided-metadata,lower-affine,finalize-memref-to-llvm,reconcile-unrealized-casts)' \2// RUN: | mlir-runner \3// RUN:   --shared-libs=%mlir_sycl_runtime \4// RUN:   --shared-libs=%mlir_runner_utils \5// RUN:   --entry-point-result=void \6// RUN: | FileCheck %s7 8module @relu attributes {gpu.container_module} {9  memref.global "private" constant @__constant_4x5xf32 : memref<4x5xf32> = dense<[10    [-1.000000e-01, -2.000000e-01, -3.000000e-01, 4.000000e-01, 5.000000e-01],11    [1.000000e-01, -2.000000e-01, 3.000000e-01, -4.000000e-01, 5.000000e-01],12    [1.000000e-01, 2.000000e-01, 3.000000e-01, -4.000000e-01, -5.000000e-01],13    [1.000000e-01, 2.000000e-01, 3.000000e-01, 4.000000e-01, 5.000000e-01]14  ]>15 16  func.func @main() {17    %c1 = arith.constant 1 : index18    %c100 = arith.constant 100 : index19    %c0 = arith.constant 0 : index20    %0 = memref.get_global @__constant_4x5xf32 : memref<4x5xf32>21 22    scf.for %arg0 = %c0 to %c100 step %c1 {23      %1 = func.call @test(%0) : (memref<4x5xf32>) -> memref<4x5xf32>24      %cast = memref.cast %1 : memref<4x5xf32> to memref<*xf32>25      func.call @printMemrefF32(%cast) : (memref<*xf32>) -> ()26      // CHECK: [0, 0, 0, 0.4, 0.5],27      // CHECK: [0.1, 0, 0.3, 0, 0.5],28      // CHECK: [0.1, 0.2, 0.3, 0, 0],29      // CHECK: [0.1, 0.2, 0.3, 0.4, 0.5]30    }31    return32  }33 34  func.func private @printMemrefF32(memref<*xf32>)35  func.func @test(%arg0: memref<4x5xf32>) -> memref<4x5xf32> {36    %c5 = arith.constant 5 : index37    %c4 = arith.constant 4 : index38    %cst = arith.constant 0.000000e+00 : f3239    %c1 = arith.constant 1 : index40    %memref = gpu.alloc host_shared () : memref<4x5xf32>41    memref.copy %arg0, %memref : memref<4x5xf32> to memref<4x5xf32>42    %memref_0 = gpu.alloc host_shared () : memref<4x5xi1>43    %2 = gpu.wait async44    %3 = gpu.launch_func async [%2]  @test_kernel::@test_kernel blocks in (%c4, %c5, %c1) threads in (%c1, %c1, %c1) args(%memref : memref<4x5xf32>, %cst : f32, %memref_0 : memref<4x5xi1>)45    gpu.wait [%3]46    %memref_1 = gpu.alloc host_shared () : memref<4x5xf32>47    %4 = gpu.wait async48    %5 = gpu.launch_func async [%4]  @test_kernel_0::@test_kernel blocks in (%c4, %c5, %c1) threads in (%c1, %c1, %c1) args(%memref_0 : memref<4x5xi1>, %memref : memref<4x5xf32>, %cst : f32, %memref_1 : memref<4x5xf32>)49    gpu.wait [%5]50    %alloc = memref.alloc() : memref<4x5xf32>51    memref.copy %memref_1, %alloc : memref<4x5xf32> to memref<4x5xf32>52    %6 = gpu.wait async53    %7 = gpu.dealloc async [%6] %memref_1 : memref<4x5xf32>54    %8 = gpu.dealloc async [%7] %memref_0 : memref<4x5xi1>55    %9 = gpu.dealloc async [%8] %memref : memref<4x5xf32>56    return %alloc : memref<4x5xf32>57  }58  gpu.module @test_kernel attributes {spirv.target_env = #spirv.target_env<#spirv.vce<v1.0, [Addresses, Int64, Int8, Kernel], []>, api=OpenCL, #spirv.resource_limits<>>} {59    gpu.func @test_kernel(%arg0: memref<4x5xf32>, %arg1: f32, %arg2: memref<4x5xi1>) kernel attributes {gpu.known_block_size = array<i32: 1, 1, 1>, gpu.known_grid_size = array<i32: 4, 5, 1>, spirv.entry_point_abi = #spirv.entry_point_abi<>} {60      %0 = gpu.block_id  x61      %1 = gpu.block_id  y62      %2 = memref.load %arg0[%0, %1] : memref<4x5xf32>63      %3 = arith.cmpf olt, %2, %arg1 : f3264      memref.store %3, %arg2[%0, %1] : memref<4x5xi1>65      gpu.return66    }67  }68  gpu.module @test_kernel_0 attributes {spirv.target_env = #spirv.target_env<#spirv.vce<v1.0, [Addresses, Int64, Int8, Kernel], []>, api=OpenCL, #spirv.resource_limits<>>} {69    gpu.func @test_kernel(%arg0: memref<4x5xi1>, %arg1: memref<4x5xf32>, %arg2: f32, %arg3: memref<4x5xf32>) kernel attributes {gpu.known_block_size = array<i32: 1, 1, 1>, gpu.known_grid_size = array<i32: 4, 5, 1>, spirv.entry_point_abi = #spirv.entry_point_abi<>} {70      %0 = gpu.block_id  x71      %1 = gpu.block_id  y72      %2 = memref.load %arg0[%0, %1] : memref<4x5xi1>73      %3 = memref.load %arg1[%0, %1] : memref<4x5xf32>74      %4 = arith.select %2, %arg2, %3 : f3275      memref.store %4, %arg3[%0, %1] : memref<4x5xf32>76      gpu.return77    }78  }79}80