Skip to content

Commit

Permalink
dialects: (stablehlo) add stablehlo.token
Browse files Browse the repository at this point in the history
  • Loading branch information
Erick Ochoa committed Aug 24, 2024
1 parent b55fadc commit 3cd9d19
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
3 changes: 3 additions & 0 deletions tests/filecheck/dialects/stablehlo/attrs.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
highest = #stablehlo<precision HIGHEST>
} : () -> ()

%token = "test.op"() : () -> (!stablehlo.token)

// CHECK: builtin.module {
// CHECK-NEXT: "test.op"() {"default" = #stablehlo<precision DEFAULT>, "high" = #stablehlo<precision HIGH>, "highest" = #stablehlo<precision HIGHEST>} : () -> ()
// CHECK-NEXT: %token = "test.op"() : () -> !stablehlo.token
// CHECK-NEXT: }
22 changes: 21 additions & 1 deletion xdsl/dialects/stablehlo.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@
from xdsl.dialects.builtin import AnyTensorType, DenseArrayBase, IntegerType, TensorType
from xdsl.ir import (
Attribute,
Data,

Check failure on line 15 in xdsl/dialects/stablehlo.py

View workflow job for this annotation

GitHub Actions / build (3.10)

Import "Data" is not accessed (reportUnusedImport)
Dialect,
EnumAttribute,
SpacedOpaqueSyntaxAttribute,
SSAValue,
StrEnum,
ParametrizedAttribute,
TypeAttribute,
)
from xdsl.irdl import (
ConstraintVar,
Expand Down Expand Up @@ -77,6 +80,22 @@ class PrecisionAttr(EnumAttribute[Precision], SpacedOpaqueSyntaxAttribute):
name = "stablehlo.precision"


@irdl_attr_definition
class TokenType(TypeAttribute, ParametrizedAttribute):
"""
Token types represent tokens, i.e. opaque values produced and consumed by some operations.
Tokens are used for imposing execution order on operations as described in the Execution section.
E.g.,
// %input0: !stablehlo.token
// %input1: !stablehlo.token
%result = "stablehlo.after_all"(%input0, %input1) : (!stablehlo.token, !stablehlo.token) -> !stablehlo.token
"""

name = "stablehlo.token"


# endregion


Expand Down Expand Up @@ -277,11 +296,12 @@ def verify_(self) -> None:
AddOp,
AndOp,
MultiplyOp,
SubtractOp,
ReturnOp,
SubtractOp,
TransposeOp,
],
[
PrecisionAttr,
TokenType,
],
)

0 comments on commit 3cd9d19

Please sign in to comment.