From 1705de8224bb91875fec66e78310498a4171c96a Mon Sep 17 00:00:00 2001 From: Michael Levesque-Dion Date: Tue, 6 Feb 2024 08:36:16 -0800 Subject: [PATCH] Add a simple example for execution order The text refers to "the example above", but said example is actually near the top of the file (thousands of lines above). The example is also longer than necessary for the purposes of illustrating execution order. --- docs/spec.md | 15 ++++++++++++--- test.mlir | 6 ++++++ 2 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 test.mlir diff --git a/docs/spec.md b/docs/spec.md index 364635e18f7..b5c1c7bee2a 100644 --- a/docs/spec.md +++ b/docs/spec.md @@ -5960,9 +5960,18 @@ The execution order is implementation-defined as long as it is aligned with dataflow, i.e. if ops are executed before their uses. In StableHLO, all side-effecting ops consume one token and produce one token (multiple tokens can be multiplexed into one token via `after_all`), so the execution order of side -effects is also aligned with dataflow. Possible execution orders of the example -program above are `%0` → `%1` → `%2` → `%3` → `%4` → `return` or `%3` → `%0` → -`%1` → `%2` → `%4` → `return`. +effects is also aligned with dataflow. For example, in the below program +there are two possible execution orders: `%0` → `%1` → `%2` → `return` and +`%1` → `%0` → `%2` → `return`. + +```mlir +func.func @main() -> tensor { + %0 = stablehlo.constant dense<1.0> : tensor + %1 = stablehlo.constant dense<2.0> : tensor + %2 = stablehlo.add %0, %1 : tensor + return %2 : tensor +} +``` More formally, a **StableHLO process** is a combination of: 1\) a StableHLO program, 2) operation statuses (not executed yet, diff --git a/test.mlir b/test.mlir new file mode 100644 index 00000000000..9d5f4709b40 --- /dev/null +++ b/test.mlir @@ -0,0 +1,6 @@ +func.func @main() -> tensor { + %0 = stablehlo.constant dense<1.0> : tensor + %1 = stablehlo.constant dense<2.0> : tensor + %2 = stablehlo.add %0, %1 : tensor + return %2 : tensor +}