Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dialects: (stablehlo) add stablehlo.after_all #3104

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions tests/filecheck/dialects/stablehlo/ops.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
// CHECK: %add = "stablehlo.add"(%t0, %t0) : (tensor<i32>, tensor<i32>) -> tensor<i32>
%add = "stablehlo.add"(%t0, %t0) : (tensor<i32>, tensor<i32>) -> tensor<i32>

%token0 = "test.op"() : () -> !stablehlo.token
%token1 = "test.op"() : () -> !stablehlo.token
// CHECK: %after_all = "stablehlo.after_all"(%token0, %token1) : (!stablehlo.token, !stablehlo.token) -> !stablehlo.token
%after_all = "stablehlo.after_all"(%token0, %token1) : (!stablehlo.token, !stablehlo.token) -> !stablehlo.token

// CHECK: %multiply = "stablehlo.multiply"(%t0, %t0) : (tensor<i32>, tensor<i32>) -> tensor<i32>
%multiply = "stablehlo.multiply"(%t0, %t0) : (tensor<i32>, tensor<i32>) -> tensor<i32>

Expand Down
19 changes: 19 additions & 0 deletions xdsl/dialects/stablehlo.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"""

import abc
from collections.abc import Sequence
from typing import Annotated, TypeAlias, cast

from xdsl.dialects.builtin import AnyTensorType, DenseArrayBase, IntegerType, TensorType
Expand Down Expand Up @@ -145,6 +146,23 @@ class AddOp(ElementwiseBinaryOperation):
name = "stablehlo.add"


@irdl_op_definition
class AfterAllOp(IRDLOperation):
"""
Ensures that the operations producing the inputs are executed before any operations that depend on result.
Execution of this operation does nothing, it only exists to establish data dependencies from result to inputs.

https://github.com/openxla/stablehlo/blob/main/docs/spec.md#after_all
"""

name = "stablehlo.after_all"
inputs = var_operand_def(TokenType)
result = result_def(TokenType)

def __init__(self, inputs: Sequence[SSAValue]):
super().__init__(operands=[inputs], result_types=(TokenType(),))


IntegerTensorType: TypeAlias = TensorType[IntegerType]


Expand Down Expand Up @@ -318,6 +336,7 @@ def verify_(self) -> None:
[
AbsOp,
AddOp,
AfterAllOp,
AndOp,
BitcastConvertOp,
MultiplyOp,
Expand Down
Loading