brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.1 KiB · 11a3230 Raw
88 lines · plain
1// RUN:   mlir-opt %s -pass-pipeline="builtin.module(async-to-async-runtime,func.func(async-runtime-ref-counting,async-runtime-ref-counting-opt),convert-async-to-llvm,func.func(convert-linalg-to-loops,convert-scf-to-cf),finalize-memref-to-llvm,func.func(convert-arith-to-llvm),convert-func-to-llvm,convert-cf-to-llvm,reconcile-unrealized-casts)" \2// RUN: | mlir-runner                                                      \3// RUN:     -e main -entry-point-result=void -O0                               \4// RUN:     -shared-libs=%mlir_c_runner_utils  \5// RUN:     -shared-libs=%mlir_runner_utils    \6// RUN:     -shared-libs=%mlir_async_runtime   \7// RUN: | FileCheck %s8 9// FIXME: https://github.com/llvm/llvm-project/issues/5723110// UNSUPPORTED: asan11// UNSUPPORTED: hwasan12// FIXME: Windows does not have aligned_alloc13// UNSUPPORTED: system-windows14 15func.func @main() {16  %i0 = arith.constant 0 : index17  %i1 = arith.constant 1 : index18  %i2 = arith.constant 2 : index19  %i3 = arith.constant 3 : index20 21  %c0 = arith.constant 0.0 : f3222  %c1 = arith.constant 1.0 : f3223  %c2 = arith.constant 2.0 : f3224  %c3 = arith.constant 3.0 : f3225  %c4 = arith.constant 4.0 : f3226 27  %A = memref.alloc() : memref<4xf32>28  linalg.fill ins(%c0 : f32) outs(%A : memref<4xf32>)29 30  // CHECK: [0, 0, 0, 0]31  %U = memref.cast %A :  memref<4xf32> to memref<*xf32>32  call @printMemrefF32(%U): (memref<*xf32>) -> ()33 34  // CHECK: Current thread id: [[MAIN:.*]]35  // CHECK: [1, 0, 0, 0]36  memref.store %c1, %A[%i0]: memref<4xf32>37  call @mlirAsyncRuntimePrintCurrentThreadId(): () -> ()38  call @printMemrefF32(%U): (memref<*xf32>) -> ()39 40  %outer = async.execute {41    // CHECK: Current thread id: [[THREAD0:.*]]42    // CHECK: [1, 2, 0, 0]43    memref.store %c2, %A[%i1]: memref<4xf32>44    func.call @mlirAsyncRuntimePrintCurrentThreadId(): () -> ()45    func.call @printMemrefF32(%U): (memref<*xf32>) -> ()46 47    // No op async region to create a token for testing async dependency.48    %noop = async.execute {49      // CHECK: Current thread id: [[THREAD1:.*]]50      func.call @mlirAsyncRuntimePrintCurrentThreadId(): () -> ()51      async.yield52    }53 54    %inner = async.execute [%noop] {55      // CHECK: Current thread id: [[THREAD2:.*]]56      // CHECK: [1, 2, 3, 0]57      memref.store %c3, %A[%i2]: memref<4xf32>58      func.call @mlirAsyncRuntimePrintCurrentThreadId(): () -> ()59      func.call @printMemrefF32(%U): (memref<*xf32>) -> ()60 61      async.yield62    }63    async.await %inner : !async.token64 65    // CHECK: Current thread id: [[THREAD3:.*]]66    // CHECK: [1, 2, 3, 4]67    memref.store %c4, %A[%i3]: memref<4xf32>68    func.call @mlirAsyncRuntimePrintCurrentThreadId(): () -> ()69    func.call @printMemrefF32(%U): (memref<*xf32>) -> ()70 71    async.yield72  }73  async.await %outer : !async.token74 75  // CHECK: Current thread id: [[MAIN]]76  // CHECK: [1, 2, 3, 4]77  call @mlirAsyncRuntimePrintCurrentThreadId(): () -> ()78  call @printMemrefF32(%U): (memref<*xf32>) -> ()79 80  memref.dealloc %A : memref<4xf32>81 82  return83}84 85func.func private @mlirAsyncRuntimePrintCurrentThreadId() -> ()86 87func.func private @printMemrefF32(memref<*xf32>) attributes { llvm.emit_c_interface }88