2020-07-22 06:30:39 +08:00
|
|
|
// RUN: onnx-mlir-opt --shape-inference --lower-frontend --enable-memory-pool %s -split-input-file | FileCheck %s
|
2020-06-10 04:48:33 +08:00
|
|
|
|
|
|
|
/// One intermediate value to allocate in the memory pool.
|
|
|
|
func @test_enable_memory_pool(%arg0: tensor<10x10xf32>) -> tensor<10x10xf32> {
|
|
|
|
%0 = "onnx.Add"(%arg0, %arg0) : (tensor<10x10xf32>, tensor<10x10xf32>) -> tensor<10x10xf32>
|
|
|
|
%1 = "onnx.Add"(%0, %arg0) : (tensor<10x10xf32>, tensor<10x10xf32>) -> tensor<10x10xf32>
|
|
|
|
return %1 : tensor<10x10xf32>
|
|
|
|
|
|
|
|
// CHECK-LABEL: test_enable_memory_pool
|
|
|
|
// CHECK: [[CONST0:%.+]] = constant 0 : i64
|
|
|
|
// CHECK: [[RES:%.+]] = alloc() : memref<10x10xf32>
|
|
|
|
// CHECK: [[MEMPOOL:%.+]] = alloc() : memref<400xi8>
|
|
|
|
// CHECK: [[GETREF:%.+]] = "krnl.getref"([[MEMPOOL]], [[CONST0]]) : (memref<400xi8>, i64) -> memref<10x10xf32>
|
|
|
|
// CHECK: krnl.define_loops
|
|
|
|
// CHECK: krnl.iterate
|
2020-07-22 06:30:39 +08:00
|
|
|
// CHECK: [[LOAD1:%.+]] = affine.load %arg0[%arg1, %arg2] : memref<10x10xf32>
|
|
|
|
// CHECK: [[LOAD2:%.+]] = affine.load %arg0[%arg1, %arg2] : memref<10x10xf32>
|
2020-06-10 04:48:33 +08:00
|
|
|
// CHECK: [[ADDF1:%.+]] = addf [[LOAD1]], [[LOAD2]] : f32
|
2020-07-22 06:30:39 +08:00
|
|
|
// CHECK: affine.store [[ADDF1]], [[GETREF]][%arg1, %arg2] : memref<10x10xf32>
|
2020-06-10 04:48:33 +08:00
|
|
|
// CHECK: krnl.define_loops
|
|
|
|
// CHECK: krnl.iterate
|
|
|
|
// CHECK: dealloc [[MEMPOOL]] : memref<400xi8>
|
|
|
|
// CHECK: return [[RES]] : memref<10x10xf32>
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Two intermediate values to allocate in the memory pool.
|
|
|
|
func @test_enable_memory_pool_2(%arg0: tensor<10x10xf32>, %arg1: tensor<10x20xf32>) -> tensor<10x20xf32> {
|
|
|
|
%0 = "onnx.Add"(%arg0, %arg0) : (tensor<10x10xf32>, tensor<10x10xf32>) -> tensor<10x10xf32>
|
|
|
|
%1 = "onnx.MatMul"(%0, %arg1) : (tensor<10x10xf32>, tensor<10x20xf32>) -> tensor<10x20xf32>
|
|
|
|
%2 = "onnx.Add"(%1, %arg1) : (tensor<10x20xf32>, tensor<10x20xf32>) -> tensor<10x20xf32>
|
|
|
|
return %2 : tensor<10x20xf32>
|
|
|
|
|
|
|
|
// CHECK-LABEL: test_enable_memory_pool_2
|
2020-07-21 07:24:17 +08:00
|
|
|
// CHECK: [[CONST0:%.+]] = constant 0 : i64
|
2020-07-22 06:30:39 +08:00
|
|
|
// CHECK: [[CONST1:%.+]] = constant 0.000000e+00 : f32
|
2020-06-10 04:48:33 +08:00
|
|
|
// CHECK: [[RES:%.+]] = alloc() : memref<10x20xf32>
|
|
|
|
// CHECK: [[MEMPOOL0:%.+]] = alloc() : memref<800xi8>
|
|
|
|
// CHECK: [[GETREF0:%.+]] = "krnl.getref"([[MEMPOOL0]], [[CONST0]]) : (memref<800xi8>, i64) -> memref<10x20xf32>
|
|
|
|
// CHECK: [[MEMPOOL1:%.+]] = alloc() : memref<400xi8>
|
|
|
|
// CHECK: [[GETREF1:%.+]] = "krnl.getref"([[MEMPOOL1]], [[CONST0]]) : (memref<400xi8>, i64) -> memref<10x10xf32>
|
|
|
|
// CHECK: krnl.define_loops
|
|
|
|
// CHECK: krnl.iterate
|
2020-07-22 06:30:39 +08:00
|
|
|
// CHECK: [[LOAD1:%.+]] = affine.load %arg0[%arg2, %arg3] : memref<10x10xf32>
|
|
|
|
// CHECK: [[LOAD2:%.+]] = affine.load %arg0[%arg2, %arg3] : memref<10x10xf32>
|
2020-06-10 04:48:33 +08:00
|
|
|
// CHECK: [[ADDF1:%.+]] = addf [[LOAD1]], [[LOAD2]] : f32
|
2020-07-22 06:30:39 +08:00
|
|
|
// CHECK: affine.store [[ADDF1]], [[GETREF1]][%arg2, %arg3] : memref<10x10xf32>
|
2020-06-10 04:48:33 +08:00
|
|
|
// CHECK: krnl.define_loops
|
|
|
|
// CHECK: krnl.iterate
|
2020-07-22 06:30:39 +08:00
|
|
|
// CHECK: [[LOAD3:%.+]] = affine.load [[GETREF1]][%arg2, %arg4] : memref<10x10xf32>
|
|
|
|
// CHECK: [[LOAD4:%.+]] = affine.load %arg1[%arg4, %arg3] : memref<10x20xf32>
|
|
|
|
// CHECK: [[LOAD5:%.+]] = affine.load [[GETREF0]][%arg2, %arg3] : memref<10x20xf32>
|
2020-06-10 04:48:33 +08:00
|
|
|
// CHECK: [[MULF1:%.+]] = mulf [[LOAD3]], [[LOAD4]] : f32
|
|
|
|
// CHECK: [[ADDF2:%.+]] = addf [[LOAD5]], [[MULF1]] : f32
|
2020-07-22 06:30:39 +08:00
|
|
|
// CHECK: affine.store [[ADDF2]], [[GETREF0]][%arg2, %arg3] : memref<10x20xf32>
|
2020-06-10 04:48:33 +08:00
|
|
|
// CHECK: krnl.define_loops
|
|
|
|
// CHECK: krnl.iterate
|
2020-07-22 06:30:39 +08:00
|
|
|
// CHECK: [[LOAD6:%.+]] = affine.load [[GETREF0]][%arg2, %arg3] : memref<10x20xf32>
|
|
|
|
// CHECK: [[LOAD7:%.+]] = affine.load %arg1[%arg2, %arg3] : memref<10x20xf32>
|
2020-06-10 04:48:33 +08:00
|
|
|
// CHECK: [[ADDF3:%.+]] = addf [[LOAD6]], [[LOAD7]] : f32
|
2020-07-22 06:30:39 +08:00
|
|
|
// CHECK: affine.store [[ADDF3]], [[RES]][%arg2, %arg3] : memref<10x20xf32>
|
2020-06-10 04:48:33 +08:00
|
|
|
// CHECK: dealloc [[MEMPOOL1]] : memref<400xi8>
|
|
|
|
// CHECK: dealloc [[MEMPOOL0]] : memref<800xi8>
|
|
|
|
// CHECK: return [[RES]] : memref<10x20xf32>
|
|
|
|
}
|