Skip to content

Commit 866b91d

Browse files
Fix importing Cast opset >=19 (#2927)
Signed-off-by: Tung D. Le <[email protected]> Co-authored-by: Alexandre Eichenberger <[email protected]>
1 parent e03932b commit 866b91d

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

src/Builder/FrontendDialectTransformer.cpp

+9-4
Original file line numberDiff line numberDiff line change
@@ -906,10 +906,15 @@ class FrontendGenImpl {
906906
std::vector<NamedAttribute> attributes;
907907
for (int i = 0; i < node.attribute_size(); ++i) {
908908
auto attr = node.attribute(i);
909-
auto mlir_type = convertONNXTypeToMLIRType(
910-
builder_, static_cast<onnx::TensorProto_DataType>(attr.i()));
911-
Attribute mlirAttr = TypeAttr::get(mlir_type);
912-
attributes.push_back(builder_.getNamedAttr(attr.name(), mlirAttr));
909+
if (attr.name() == "to") {
910+
auto mlir_type = convertONNXTypeToMLIRType(
911+
builder_, static_cast<onnx::TensorProto_DataType>(attr.i()));
912+
Attribute mlirAttr = TypeAttr::get(mlir_type);
913+
attributes.push_back(builder_.getNamedAttr(attr.name(), mlirAttr));
914+
} else {
915+
NamedAttribute na = convertOnnxAttributeProtoToMlirNamedAttribute(attr);
916+
attributes.push_back(na);
917+
}
913918
}
914919

915920
// If the node has a name, then import it.
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: onnx-mlir --EmitONNXBasic --printIR %s | FileCheck %s
2+
3+
<
4+
ir_version: 7,
5+
opset_import: ["" : 19],
6+
producer_name: "backend-test"
7+
>
8+
test_cast (int64[1] x) => (float[1] y) {
9+
y = Cast<saturate = 0, to = 1>(x)
10+
}
11+
12+
// CHECK-LABEL: func.func @main_graph
13+
// CHECK-SAME: ([[PARAM_0_:%.+]]: tensor<1xi64> {onnx.name = "x"}) -> (tensor<1xf32> {onnx.name = "y"}) {
14+
// CHECK: [[VAR_0_:%.+]] = "onnx.Cast"([[PARAM_0_]]) {saturate = 0 : si64, to = f32} : (tensor<1xi64>) -> tensor<1xf32>
15+
// CHECK: onnx.Return [[VAR_0_]] : tensor<1xf32>
16+
// CHECK: }
17+
// CHECK: "onnx.EntryPoint"() {func = @main_graph} : () -> ()

0 commit comments

Comments
 (0)