-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DenseResourceElementsAttr as constant value E2E (#2381)
### Ticket Closes #2378 ### Problem description When the value of a `stalbehlo/ttir/ttnn` constant op is a `DenseResourceElementsAttr` instead of a `DenseElementsAttr`, we fail to lower stablehlo to ttir. We also do not yet handle the case where the value of a constant is in a `DenseResourceElementsAttr` when generating the flatbuffer. ### What's changed - Legalize lowering of `stablehlo.constant` when the value type is `DenseResourceElementsAttr` - Handle case where value type is `DenseResourceElementsAttr` when generating flatbuffer - Add verifier to `ttnn.constant` to ensure that the `ElementsAttr` holding the constant data is either `DenseResourceElementsAttr` or `DenseElementsAttr`
- Loading branch information
1 parent
b37728f
commit 995aad9
Showing
18 changed files
with
112 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
test/ttmlir/Dialect/TTNN/constant/negative/simple_constant_sparse_resource.mlir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// RUN: not ttmlir-opt --ttir-to-ttnn-backend-pipeline %s 2>&1 | FileCheck %s | ||
|
||
module attributes {} { | ||
func.func @test_dense_attr() -> tensor<1x2xbf16> { | ||
// CHECK: error: 'ttnn.constant' op value attribute must be one of DenseResourceElementsAttr or DenseElementsAttr. | ||
%0 = "ttir.constant"() <{value = sparse<[[0, 0], [0, 1]], [2.0, 2.0]> : tensor<1x2xbf16>}> : () -> tensor<1x2xbf16> | ||
return %0 : tensor<1x2xbf16> | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
test/ttmlir/Silicon/StableHLO/n150/Constant/constant_bf16.mlir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
test/ttmlir/Silicon/StableHLO/n150/Constant/constant_bool.mlir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
test/ttmlir/Silicon/StableHLO/n150/Constant/constant_dense_resource_bf16.mlir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// REQUIRES: stablehlo | ||
// RUN: rm -rf %t.ttnn | ||
// RUN: rm -rf %t.mlir | ||
// RUN: ttmlir-opt --stablehlo-to-ttir-pipeline --ttir-to-ttnn-backend-pipeline="system-desc-path=%system_desc_path%" %s > %t.mlir | ||
// RUN: ttmlir-translate --ttnn-to-flatbuffer %t.mlir > %t.ttnn | ||
// RUN: FileCheck --input-file=%t.mlir %s | ||
|
||
module attributes {} { | ||
func.func @test_dense_attr() -> tensor<1x2xbf16> { | ||
// CHECK: ttnn.constant | ||
// CHECK-SAME: dense_resource<dense_attr> | ||
%0 = stablehlo.constant dense_resource<dense_attr> : tensor<1x2xbf16> | ||
return %0 : tensor<1x2xbf16> | ||
} | ||
} | ||
{-# | ||
dialect_resources: { | ||
builtin: { | ||
// This should encode for two bfloat16 values which are both 2.0 | ||
// 0x020000000 is a hex string blob | ||
// 0x0040 is 2.0 in bfloat16 | ||
// 0x00400040 is 2.0, 2.0 | ||
dense_attr: "0x0200000000400040" | ||
} | ||
} | ||
#-} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
test/ttmlir/Silicon/StableHLO/n150/Constant/constant_ui16.mlir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
test/ttmlir/Silicon/StableHLO/n150/Constant/constant_ui32.mlir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
test/ttmlir/Silicon/StableHLO/n150/Constant/constant_ui64.mlir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters