This is an archive of the discontinued LLVM Phabricator instance.

Add Async Function to the Async Dialect
ClosedPublic

Authored by yijia1212 on Nov 1 2022, 1:13 PM.

Details

Summary

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

Diff Detail

Event Timeline

yijia1212 created this revision.Nov 1 2022, 1:13 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 1 2022, 1:13 PM
yijia1212 requested review of this revision.Nov 1 2022, 1:13 PM
yijia1212 edited the summary of this revision. (Show Details)Nov 1 2022, 1:24 PM
yijia1212 retitled this revision from [xla:runtime] NFC: Add Async Function to the Async Dialect to NFC: Add Async Function to the Async Dialect.
yijia1212 edited the summary of this revision. (Show Details)
ezhulenev accepted this revision.Nov 1 2022, 1:25 PM
ezhulenev edited the summary of this revision. (Show Details)
This revision is now accepted and ready to land.Nov 1 2022, 1:26 PM
ezhulenev retitled this revision from NFC: Add Async Function to the Async Dialect to Add Async Function to the Async Dialect.Nov 1 2022, 1:26 PM

The description of this seems extremely light, and doesn't really touch on any rationale.

rriddle requested changes to this revision.Nov 1 2022, 1:28 PM
rriddle added inline comments.
mlir/include/mlir/Dialect/Async/IR/AsyncOps.td
145

Symbols aren't really expected to have results. These are SSA results, not function results.

This revision now requires changes to proceed.Nov 1 2022, 1:28 PM
rriddle added inline comments.Nov 1 2022, 1:29 PM
mlir/include/mlir/Dialect/Async/IR/AsyncOps.td
155–161

Are these create methods really necessary? func::FuncOp has them only really for historical reasons, using a builder is generally just cleaner/better.

251
277–297

The formatting here looks off.

ezhulenev edited the summary of this revision. (Show Details)Nov 1 2022, 1:31 PM
ezhulenev edited the summary of this revision. (Show Details)

The description of this seems extremely light, and doesn't really touch on any rationale.

I added a bit more context to the description.

yijia1212 updated this revision to Diff 472408.EditedNov 1 2022, 2:50 PM
yijia1212 edited the summary of this revision. (Show Details)

Address review.

yijia1212 marked 3 inline comments as done.Nov 1 2022, 2:53 PM
yijia1212 marked an inline comment as done.
ezhulenev added inline comments.Nov 1 2022, 3:25 PM
mlir/test/Dialect/Async/verify.mlir
48

missing new line

yijia1212 updated this revision to Diff 472432.Nov 1 2022, 3:33 PM

Address comments.

yijia1212 marked an inline comment as done.Nov 1 2022, 3:34 PM
rriddle accepted this revision.Nov 1 2022, 10:41 PM
This revision is now accepted and ready to land.Nov 1 2022, 10:41 PM
This revision was automatically updated to reflect the committed changes.