onnx-mlir icon indicating copy to clipboard operation
onnx-mlir copied to clipboard

Krnl.global and Krnl.entry_point() to llvm

Open hm123450 opened this issue 1 year ago • 1 comments

Hi: I now have an MLIR file "add.onnx.mlir" that consists of both the affine dialect and the krnl dialect as a result of lowering. I am aware that I can lower the krnl dialect to LLVM, but I want to preserve the affine dialect in the file. In other words, I only want to lower "krnl.global" and "krnl.entry_point" to LLVM, while keeping the rest unchanged. Is there an instruction to achieve this? I will be very grateful if anyone can answer this question.

hm123450 avatar Nov 22 '23 09:11 hm123450

module attributes {llvm.data_layout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128", llvm.target_triple = "x86_64-unknown-linux-gnu", "onnx-mlir.symbol-postfix" = "add"} { func.func @main_graph(%arg0: memref<3x2xf32> {onnx.name = "X1"}, %arg1: memref<3x2xf32> {onnx.name = "X2"}) -> (memref<3x2xf32> {onnx.name = "Y"}) attributes {llvm.emit_c_interface} { %c1 = arith.constant 1 : index %c3 = arith.constant 3 : index %c2 = arith.constant 2 : index %c3_0 = arith.constant 3 : index %c2_1 = arith.constant 2 : index %c1_2 = arith.constant 1 : index %alloc = memref.alloc() {alignment = 16 : i64} : memref<3x2xf32> %c0 = arith.constant 0 : index %c3_3 = arith.constant 3 : index %c2_4 = arith.constant 2 : index %c3_5 = arith.constant 3 : index %c2_6 = arith.constant 2 : index %c3_7 = arith.constant 3 : index %c2_8 = arith.constant 2 : index affine.for %arg2 = 0 to 3 { affine.for %arg3 = 0 to 2 { %0 = affine.load %arg0[%arg2, %arg3] : memref<3x2xf32> %1 = affine.load %arg1[%arg2, %arg3] : memref<3x2xf32> %2 = arith.addf %0, %1 : f32 affine.store %2, %alloc[%arg2, %arg3] : memref<3x2xf32> } } return %alloc : memref<3x2xf32> } "krnl.entry_point"() {func = @main_graph, numInputs = 2 : i32, numOutputs = 1 : i32, signature = "[ { \22type\22 : \22f32\22 , \22dims\22 : [3 , 2] , \22name\22 : \22X1\22 }\0A , { \22type\22 : \22f32\22 , \22dims\22 : [3 , 2] , \22name\22 : \22X2\22 }\0A\0A]\00@[ { \22type\22 : \22f32\22 , \22dims\22 : [3 , 2] , \22name\22 : \22Y\22 }\0A\0A]\00"} : () -> () }

hm123450 avatar Nov 22 '23 09:11 hm123450