This is an archive of the discontinued LLVM Phabricator instance.

[mlir] Async: lowering async.value to LLVM
ClosedPublic

Authored by ezhulenev on Dec 20 2020, 3:38 AM.

Details

Summary
  1. Add new methods to Async runtime API to support yielding async values
  2. Add lowering from async.yield with value payload to the new runtime API calls

async.value lowering requires that payload type is convertible to LLVM and supported by llvm.mlir.cast (DialectCast) operation.

Diff Detail

Event Timeline

ezhulenev created this revision.Dec 20 2020, 3:38 AM
ezhulenev requested review of this revision.Dec 20 2020, 3:38 AM
ezhulenev edited the summary of this revision. (Show Details)Dec 20 2020, 3:41 AM
ezhulenev added a reviewer: mehdi_amini.
ezhulenev added a reviewer: csigg.
csigg accepted this revision.Dec 21 2020, 1:34 AM
csigg added inline comments.
mlir/include/mlir/ExecutionEngine/AsyncRuntime.h
75

Typo.

77

Could you document this parameter?

mlir/lib/ExecutionEngine/AsyncRuntime.cpp
133

Could you add brief comments what AsyncTokens/Values/Groups are?

This revision is now accepted and ready to land.Dec 21 2020, 1:34 AM
ezhulenev updated this revision to Diff 313042.Dec 21 2020, 2:06 AM
ezhulenev marked 3 inline comments as done.

Add documentation

ezhulenev updated this revision to Diff 313044.Dec 21 2020, 2:08 AM

Fix style warnings

ezhulenev updated this revision to Diff 313688.Dec 24 2020, 5:08 AM

Add missing targets to CMakeLists

This revision was automatically updated to reflect the committed changes.

Hi, @ezhulenev
I'm testing MLIR on System z (Triple = "s390x-ibm-linux", CPU = "z14"), but I realized installation test (cmake --build . --target check-mlir) failed after this patch.
Endianness of System z is big-endian. Do you think this patch depends on the endianness? Do you have any suggestions to fix this?

******************** TEST 'MLIR :: mlir-cpu-runner/async-value.mlir' FAILED ********************
Script:
--
: 'RUN: at line 1';     /home/imaihal/work/llvm-project/build/bin/mlir-opt /home/imaihal/docker/imaihal-ubuntu/work/llvm-project/mlir/te
st/mlir-cpu-runner/async-value.mlir -async-ref-counting                                                     -convert-async-to-llvm      
                                            -convert-vector-to-llvm                                                 -convert-std-to-llvm
                                      | mlir-cpu-runner                                                           -e main -entry-point-r
esult=void -O0                                    -shared-libs=/home/imaihal/work/llvm-project/build/lib/libmlir_c_runner_utils.so      
 -shared-libs=/home/imaihal/work/llvm-project/build/lib/libmlir_runner_utils.so         -shared-libs=/home/imaihal/work/llvm-project/bui
ld/lib/libmlir_async_runtime.so    | /home/imaihal/work/llvm-project/build/bin/FileCheck /home/imaihal/docker/imaihal-ubuntu/work/llvm-p
roject/mlir/test/mlir-cpu-runner/async-value.mlir --dump-input=always
--
Exit Code: 2

Command Output (stderr):
--
LLVM ERROR: out of memory
Allocation failed
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.
Stack dump:
0.      Program arguments: mlir-cpu-runner -e main -entry-point-result=void -O0 -shared-libs=/home/imaihal/work/llvm-project/build/lib/l
ibmlir_c_runner_utils.so -shared-libs=/home/imaihal/work/llvm-project/build/lib/libmlir_runner_utils.so -shared-libs=/home/imaihal/work/
llvm-project/build/lib/libmlir_async_runtime.so
 #0 0x000002aa38d54f18 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/imaihal/docker/imaihal-ubuntu/work/llvm-project/build/
bin/mlir-cpu-runner+0x2d4f18)
 #1 0x000002aa38d52dc6 llvm::sys::RunSignalHandlers() (/home/imaihal/docker/imaihal-ubuntu/work/llvm-project/build/bin/mlir-cpu-runner+0
x2d2dc6)
 #2 0x000002aa38d52f82 SignalHandler(int) (/home/imaihal/docker/imaihal-ubuntu/work/llvm-project/build/bin/mlir-cpu-runner+0x2d2f82)
 #3 0x000002aa3d689b2e 
 #4 0x000003ff96fbdef4 raise (/lib/s390x-linux-gnu/libc.so.6+0x3def4)
 #5 0x000003ff96fbf37a abort (/lib/s390x-linux-gnu/libc.so.6+0x3f37a)
 #6 0x000002aa38d6a22e llvm::report_bad_alloc_error(char const*, bool) (/home/imaihal/docker/imaihal-ubuntu/work/llvm-project/build/bin/
mlir-cpu-runner+0x2ea22e)
 #7 0x000002aa38d6a26c (/home/imaihal/docker/imaihal-ubuntu/work/llvm-project/build/bin/mlir-cpu-runner+0x2ea26c)
 #8 0x000003ff973a957a operator new(unsigned long) (/usr/lib/s390x-linux-gnu/libstdc++.so.6+0xa957a)
 #9 0x000003ff96d82a80 mlirAsyncRuntimeCreateValue (/home/imaihal/work/llvm-project/build/lib/libmlir_async_runtime.so+0x2a80)
#10 0x000003ff97749200 
#11 0x000003ff97749460 
#12 0x000002aa38e666be compileAndExecute((anonymous namespace)::Options&, mlir::ModuleOp, llvm::StringRef, (anonymous namespace)::CompileAndExecuteConfig, void**) (/home/imaihal/docker/imaihal-ubuntu/work/llvm-project/build/bin/mlir-cpu-runner+0x3e66be)
#13 0x000002aa38e66c0c compileAndExecuteVoidFunction((anonymous namespace)::Options&, mlir::ModuleOp, llvm::StringRef, (anonymous namespace)::CompileAndExecuteConfig) (/home/imaihal/docker/imaihal-ubuntu/work/llvm-project/build/bin/mlir-cpu-runner+0x3e6c0c)
#14 0x000002aa38e6b3a0 mlir::JitRunnerMain(int, char**, mlir::JitRunnerConfig) (/home/imaihal/docker/imaihal-ubuntu/work/llvm-project/build/bin/mlir-cpu-runner+0x3eb3a0)
#15 0x000002aa38cd4588 main (/home/imaihal/docker/imaihal-ubuntu/work/llvm-project/build/bin/mlir-cpu-runner+0x254588)
#16 0x000003ff96fa3aca __libc_start_main (/lib/s390x-linux-gnu/libc.so.6+0x23aca)
#17 0x000002aa38d40efc _start (/home/imaihal/docker/imaihal-ubuntu/work/llvm-project/build/bin/mlir-cpu-runner+0x2c0efc)
#18 0x0000000000000000 
FileCheck error: '<stdin>' is empty.
FileCheck command line:  /home/imaihal/work/llvm-project/build/bin/FileCheck /home/imaihal/docker/imaihal-ubuntu/work/llvm-project/mlir/test/mlir-cpu-runner/async-value.mlir --dump-input=always

I simplified the async.value.mlir as follows, but I still got the error.

func @main() {

  // ------------------------------------------------------------------------ //
  // Blocking async.await outside of the async.execute.
  // ------------------------------------------------------------------------ //
  %token, %result = async.execute -> !async.value<f32> {
    %0 = constant 123.456 : f32
    async.yield %0 : f32
  }
  %1 = async.await %result : !async.value<f32>

  // CHECK: 123.456
  vector.print %1 : f32

  return
}

func private @print_memref_f32(memref<*xf32>)
  attributes { llvm.emit_c_interface }

Can the problem be in calculation of the value storage size?

@ezhulenev Thanks for replying. It seems the size has problem, but, I see strange behavior.
When the size is printed out in mlirAsyncRuntimeCreateValue(), it seems correct (the size was 4), but the execution failed. When I wrote it directory in the argument like AsyncValue *value = new AsyncValue(getDefaultAsyncRuntime(), 4);, it worked without the error.

Also, when I wrote the size directory here as follows, it worked.

AsyncValue(AsyncRuntime *runtime, int32_t size)
      : RefCounted(runtime, /*count=*/2), storage(4) {}

Hi, @ezhulenev
I'm testing MLIR on System z (Triple = "s390x-ibm-linux", CPU = "z14"), but I realized installation test (cmake --build . --target check-mlir) failed after this patch.
Endianness of System z is big-endian. Do you think this patch depends on the endianness? Do you have any suggestions to fix this?

Update:
I found an workaround to avoid this error. In gcc(gcc (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0), I needed to use -O0 instead of -O3 in this file. When using clang, I didn't got this error. This might be a bug in gcc.