Skip to content

Commit

Permalink
fix format and krnl_to_llvm test
Browse files Browse the repository at this point in the history
Signed-off-by: Yan Xu <[email protected]>
  • Loading branch information
Connor-XY committed Jun 7, 2024
1 parent bf0928f commit 8003881
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/Conversion/ONNXToTOSA/ONNXToTOSALegalizeUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ T getValueFromTosaConst(mlir::Value &val) {
// op. This allows shape inference during the framework to TOSA lowering.
template <typename TosaOp, typename... Args>
TosaOp CreateOpAndInfer(mlir::PatternRewriter &rewriter, mlir::Location loc,
mlir::Type result_ty, Args &&...args) {
mlir::Type result_ty, Args &&... args) {
auto op = rewriter.create<TosaOp>(loc, result_ty, args...);

mlir::InferShapedTypeOpInterface shapeInterface =
Expand Down Expand Up @@ -73,7 +73,7 @@ TosaOp CreateOpAndInfer(mlir::PatternRewriter &rewriter, mlir::Location loc,

template <typename TosaOp, typename... Args>
void CreateReplaceOpAndInfer(mlir::PatternRewriter &rewriter,
mlir::Operation *op, mlir::Type result_ty, Args &&...args) {
mlir::Operation *op, mlir::Type result_ty, Args &&... args) {
auto result =
CreateOpAndInfer<TosaOp>(rewriter, op->getLoc(), result_ty, args...);
rewriter.replaceOp(op, result->getResults());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// RUN: onnx-mlir-opt --convert-krnl-to-llvm="store-constants-to-file constants-to-file-single-threshold=0.03 constants-to-file-total-threshold=0.00000006" --canonicalize %s -split-input-file | FileCheck %s && rm model.constants.bin
// RUN: onnx-mlir-opt --convert-krnl-to-llvm="store-constants-to-file constants-to-file-single-threshold=0.03 constants-to-file-total-threshold=0.00000006" --canonicalize %s -split-input-file | FileCheck %s && rm model.constants.bin

// Thresholds for this files:
// -constants-to-file-single-threshold=0.03: 30 bytes for a single constants
// -constants-to-file-total-threshold=0.00000006: 60 bytes for all constants
// Thresholds for this files:
// -constants-to-file-single-threshold=0.03: 30 bytes for a single constants
// -constants-to-file-total-threshold=0.00000006: 60 bytes for all constants

// Donot save to file if a constant is a return value.
module {
Expand All @@ -11,7 +11,7 @@ func.func @test_constants_to_file_return_value() -> memref<10xi64> {
return %0 : memref<10xi64>

// CHECK-LABEL: module
// CHECK: llvm.mlir.global internal constant @constant(dense<[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]> : tensor<10xi64>) {addr_space = 0 : i32, alignment = 4096 : i64} : !llvm.array<10 x i64>
// CHECK: llvm.mlir.global internal constant @constant(dense<[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]> : tensor<10xi64>) {addr_space = 0 : i32, alignment = 4096 : i64} : !llvm.array<10 x i64>
}
}

Expand Down Expand Up @@ -61,16 +61,16 @@ func.func @test_constants_to_file() -> memref<10xi64> {

// CHECK: llvm.func @omLoadConstantsFromFile() {
// CHECK-DAG: [[VAR_0_9_:%.+]] = llvm.mlir.constant(4096 : i64) : i64
// CHECK-DAG: [[VAR_1_3_:%.+]] = llvm.mlir.constant(4176 : i64) : i64
// CHECK-DAG: [[VAR_1_3_:%.+]] = llvm.mlir.addressof @om_external_constant_data_constant_0 : !llvm.ptr
// CHECK-DAG: [[VAR_2_3_:%.+]] = llvm.mlir.constant(0 : i64) : i64
// CHECK-DAG: [[VAR_3_3_:%.+]] = llvm.mlir.addressof @om_external_constant_filename : !llvm.ptr
// CHECK-NOT: separator of consecutive DAGs
// CHECK-DAG: [[VAR_5_3_:%.+]] = llvm.mlir.addressof @om_external_constant_packedConst : !llvm.ptr
// CHECK: llvm.call @omMMapBinaryFile([[VAR_5_3_]], [[VAR_3_3_]], [[VAR_1_3_]], [[VAR_2_3_]]) : (!llvm.ptr, !llvm.ptr, i64, i64) -> ()
// CHECK: [[VAR_7_3_:%.+]] = llvm.mlir.addressof @om_external_constant_data_constant_1 : !llvm.ptr
// CHECK: llvm.call @omGetExternalConstantAddr([[VAR_7_3_]], [[VAR_5_3_]], [[VAR_2_3_]]) : (!llvm.ptr, !llvm.ptr, i64) -> ()
// CHECK: [[VAR_9_3_:%.+]] = llvm.mlir.addressof @om_external_constant_data_constant_0 : !llvm.ptr
// CHECK: llvm.call @omGetExternalConstantAddr([[VAR_9_3_]], [[VAR_5_3_]], [[VAR_0_9_]]) : (!llvm.ptr, !llvm.ptr, i64) -> ()
// CHECK-DAG: [[VAR_3_3_:%.+]] = llvm.mlir.addressof @om_external_constant_data_constant_1 : !llvm.ptr
// CHECK-DAG: [[VAR_4_3_:%.+]] = llvm.mlir.constant(4176 : i64) : i64
// CHECK-DAG: [[VAR_5_3_:%.+]] = llvm.mlir.constant(1 : i64) : i64
// CHECK-DAG: [[VAR_6_3_:%.+]] = llvm.mlir.addressof @om_external_constant_packedConst : !llvm.ptr
// CHECK-DAG: [[VAR_7_3_:%.+]] = llvm.mlir.addressof @om_external_constant_filename : !llvm.ptr
// CHECK: llvm.call @omMMapBinaryFile([[VAR_6_3_]], [[VAR_7_3_]], [[VAR_4_3_]], [[VAR_5_3_]]) : (!llvm.ptr, !llvm.ptr, i64, i64) -> ()
// CHECK: llvm.call @omGetExternalConstantAddr([[VAR_3_3_]], [[VAR_6_3_]], [[VAR_2_3_]]) : (!llvm.ptr, !llvm.ptr, i64) -> ()
// CHECK: llvm.call @omGetExternalConstantAddr([[VAR_1_3_]], [[VAR_6_3_]], [[VAR_0_9_]]) : (!llvm.ptr, !llvm.ptr, i64) -> ()
// CHECK: llvm.return
// CHECK: }

Expand Down
2 changes: 1 addition & 1 deletion test/mlir/conversion/krnl_to_llvm/symbol-postfix.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ module attributes {"onnx-mlir.symbol-postfix" = "tag_constants_to_file"} {
// CHECK-CONST-TO-FILE-DAG: [[VAR_5_8_:%.+]] = llvm.mlir.constant(1 : i64) : i64
// CHECK-CONST-TO-FILE-DAG: [[VAR_6_6_:%.+]] = llvm.mlir.addressof @om_external_constant_packedConst_tag_constants_to_file : !llvm.ptr
// CHECK-CONST-TO-FILE-DAG: [[VAR_7_4_:%.+]] = llvm.mlir.addressof @om_external_constant_filename_tag_constants_to_file : !llvm.ptr
// CHECK-CONST-TO-FILE: llvm.call @omMMapBinaryFile([[VAR_6_6_]], [[VAR_7_4_]], [[VAR_4_7_]], [[VAR_5_8_]]) : (!llvm.ptr, !llvm.ptr, i64, i64) -> ()
// CHECK-CONST-TO-FILE: llvm.call @omMMapBinaryFile([[VAR_6_6_]], [[VAR_7_4_]], [[VAR_4_7_]], {{.*}}) : (!llvm.ptr, !llvm.ptr, i64, i64) -> ()
// CHECK-CONST-TO-FILE: llvm.call @omGetExternalConstantAddr([[VAR_3_9_]], [[VAR_6_6_]], [[VAR_2_9_]]) : (!llvm.ptr, !llvm.ptr, i64) -> ()
// CHECK-CONST-TO-FILE: llvm.call @omGetExternalConstantAddr([[VAR_1_9_]], [[VAR_6_6_]], [[VAR_0_18_]]) : (!llvm.ptr, !llvm.ptr, i64) -> ()
// CHECK-CONST-TO-FILE: llvm.return
Expand Down
4 changes: 1 addition & 3 deletions utils/gen_onnx_mlir.py
Original file line number Diff line number Diff line change
Expand Up @@ -1268,9 +1268,7 @@ def gen_op_def(schema, with_version=False):
+ (", " + elTy if elTy else "")
+ ");\n"
)
r += (
"{indent}auto shapedType = mlir::dyn_cast_or_null<ShapedType>(resultType);\n"
)
r += "{indent}auto shapedType = mlir::dyn_cast_or_null<ShapedType>(resultType);\n"
r += "{indent}if (!shapedType || !shapedType.hasStaticShape())\n"
r += (
"{indent} resultType = UnrankedTensorType::get("
Expand Down

0 comments on commit 8003881

Please sign in to comment.