Add Async Function to the Async Dialect
Today `async.execute` operation semantics requires attached region to be executed in a thread managed by the runtime, and always returns an `!async.token` result. We need to model async functions that are not necessarily executed in a runtime-managed threads, but eventually lowered to llvm coroutines.
Example:
```
async.func @foo(%arg0: !async.value<f32>) -> !async.token {
%0 = async.await %arg0: !async.value<f32>
"do_something_with_f32"(%0)
return
}
```
If `arg0` is available this function will be executed in the caller thread. If it's not available it will be suspended and resumed later later on a thread managed by the async runtime. Currently this is not representable with `async.execute` operations.
The longer term goal is to make async dialect more like https://github.com/lewissbaker/cppcoro to be able to represent structured host concurrency in MLIR.
(1) Add async.func, async.call, and async.return operations in Async Dialect
Reviewed By: ezhulenev, rriddle
Differential Revision: https://reviews.llvm.org/D137189
48 lines
1.5 KiB
MLIR
48 lines
1.5 KiB
MLIR
// RUN: mlir-opt %s -split-input-file -verify-diagnostics | FileCheck %s
|
|
|
|
// FileCheck test must have at least one CHECK statement.
|
|
// CHECK-LABEL: @no_op
|
|
func.func @no_op(%arg0: !async.token) {
|
|
return
|
|
}
|
|
|
|
// -----
|
|
|
|
func.func @wrong_async_await_arg_type(%arg0: f32) {
|
|
// expected-error @+1 {{'async.await' op operand #0 must be async value type or async token type, but got 'f32'}}
|
|
async.await %arg0 : f32
|
|
}
|
|
|
|
// -----
|
|
|
|
func.func @wrong_async_await_result_type(%arg0: !async.value<f32>) {
|
|
// expected-error @+1 {{'async.await' op result type 'f64' does not match async value type 'f32'}}
|
|
%0 = "async.await"(%arg0): (!async.value<f32>) -> f64
|
|
}
|
|
|
|
|
|
// -----
|
|
// expected-error @+1 {{'async.func' op result is expected to be at least of size 1, but got 0}}
|
|
async.func @wrong_async_func_void_result_type(%arg0: f32) {
|
|
return
|
|
}
|
|
|
|
|
|
// -----
|
|
// expected-error @+1 {{'async.func' op result type must be async value type or async token type, but got 'f32'}}
|
|
async.func @wrong_async_func_result_type(%arg0: f32) -> f32 {
|
|
return %arg0 : f32
|
|
}
|
|
|
|
// -----
|
|
// expected-error @+1 {{'async.func' op results' (optional) async token type is expected to appear as the 1st return value, but got 2}}
|
|
async.func @wrong_async_func_token_type_placement(%arg0: f32) -> (!async.value<f32>, !async.token) {
|
|
return %arg0 : f32
|
|
}
|
|
|
|
// -----
|
|
async.func @wrong_async_func_return_type(%arg0: f32) -> (!async.token, !async.value<i32>) {
|
|
// expected-error @+1 {{'async.return' op operand types do not match the types returned from the parent FuncOp}}
|
|
return %arg0 : f32
|
|
}
|