Skip to content

Commit 02f45b0

Browse files
chentong319tungldAlexandreEichenberger
authored
try to use new buffer deallocation (#2919)
* implementation Signed-off-by: Chen Tong <[email protected]> * comments Signed-off-by: Chen Tong <[email protected]> * format Signed-off-by: Chen Tong <[email protected]> --------- Signed-off-by: Chen Tong <[email protected]> Co-authored-by: Tung D. Le <[email protected]> Co-authored-by: Alexandre Eichenberger <[email protected]>
1 parent c814ad0 commit 02f45b0

File tree

7 files changed

+24
-2
lines changed

7 files changed

+24
-2
lines changed

src/Compiler/CompilerDialects.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@ DialectRegistry registerDialects(ArrayRef<accel::Accelerator::Kind> accels) {
4646
for (auto *accel : accel::Accelerator::getAccelerators())
4747
accel->registerDialects(registry);
4848

49-
if (useOldBufferization)
50-
memref::registerAllocationOpInterfaceExternalModels(registry);
49+
// Register interface needed by both old and new buffer deallocation pass.
50+
memref::registerAllocationOpInterfaceExternalModels(registry);
51+
arith::registerBufferDeallocationOpInterfaceExternalModels(registry);
5152

5253
return registry;
5354
}

src/Compiler/CompilerOptions.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ bool enableONNXHybridPass; // common for both
4242
std::vector<std::string> functionsToDecompose; // common for both
4343
std::string opsForCall; // common for both
4444
bool disableKrnlOpFusion; // common for both
45+
bool disableMemRefPrefetch; // common for both
4546
EmissionTargetType emissionTarget; // onnx-mlir only
4647
bool invokeOnnxVersionConverter; // onnx-mlir only
4748
bool preserveLocations; // onnx-mlir only
@@ -211,6 +212,13 @@ static llvm::cl::opt<bool, true> disableKrnlOpFusionOpt(
211212
llvm::cl::location(disableKrnlOpFusion), llvm::cl::init(false),
212213
llvm::cl::cat(OnnxMlirCommonOptions));
213214

215+
static llvm::cl::opt<bool, true> disableMemRefPrefetchOpt(
216+
"disable-memref-prefetch",
217+
llvm::cl::desc("disable generation of memref.prefetch (default=false)\n"
218+
"Set to 'true' if you want to disable prefetch."),
219+
llvm::cl::location(disableMemRefPrefetch), llvm::cl::init(false),
220+
llvm::cl::cat(OnnxMlirCommonOptions));
221+
214222
static llvm::cl::opt<bool, true> disableRecomposeOptionOpt("disable-recompose",
215223
llvm::cl::desc("Disable recomposition of ONNX operations."),
216224
llvm::cl::location(disableRecomposeOption), llvm::cl::init(false),

src/Compiler/CompilerOptions.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ extern bool enableONNXHybridPass; // common for both
8787
extern std::vector<std::string> functionsToDecompose; // common for both
8888
extern std::string opsForCall; // common for both
8989
extern bool disableKrnlOpFusion; // common for both
90+
extern bool disableMemRefPrefetch; // common for both
9091
extern EmissionTargetType emissionTarget; // onnx-mlir only
9192
extern bool invokeOnnxVersionConverter; // onnx-mlir only
9293
extern bool preserveLocations; // onnx-mlir only

src/Dialect/Krnl/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ add_onnx_mlir_library(OMKrnlOps
2020
OMSpecializedKernelOpInterface
2121

2222
LINK_LIBS PUBLIC
23+
OMCompilerOptions
2324
OMONNXOps
2425
MLIRLLVMCommonConversion
2526
MLIRAffineDialect

src/Dialect/Krnl/DialectBuilder.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include "llvm/ADT/TypeSwitch.h"
1616

17+
#include "src/Compiler/CompilerOptions.hpp"
1718
#include "src/Conversion/ONNXToKrnl/ONNXToKrnlCommon.hpp"
1819
#include "src/Dialect/Krnl/DialectBuilder.hpp"
1920
#include "src/Dialect/ONNX/ONNXOps.hpp"
@@ -94,12 +95,16 @@ Value KrnlBuilder::getLinearOffsetIndexIE(
9495

9596
void KrnlBuilder::prefetch(Value memref, ValueRange indices, bool isWrite,
9697
unsigned localityHint, bool isDataCache) {
98+
if (disableMemRefPrefetch)
99+
return;
97100
b().create<KrnlPrefetchOp>(
98101
loc(), memref, indices, isWrite, localityHint, isDataCache);
99102
}
100103

101104
void KrnlBuilder::prefetchIE(Value memref, ArrayRef<IndexExpr> indices,
102105
bool isWrite, unsigned localityHint, bool isDataCache) {
106+
if (disableMemRefPrefetch)
107+
return;
103108
SmallVector<Value, 4> indexValues;
104109
IndexExpr::getValues(indices, indexValues);
105110
b().create<KrnlPrefetchOp>(

src/Dialect/Mlir/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ add_onnx_mlir_library(OMMlirDialects
1212
OMSpecializedKernelOpInterface
1313

1414
LINK_LIBS PUBLIC
15+
OMCompilerOptions
1516
MLIRMathDialect
1617
MLIRAffineDialect
1718
MLIRSCFDialect

src/Dialect/Mlir/DialectBuilder.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "llvm/Support/Debug.h"
2626

2727
// Please do not add dependences on ONNX or KRNL dialects.
28+
#include "src/Compiler/CompilerOptions.hpp"
2829
#include "src/Dialect/Mlir/DialectBuilder.hpp"
2930
#include "src/Dialect/Mlir/VectorMachineSupport.hpp"
3031

@@ -1657,12 +1658,16 @@ Value MemRefBuilder::dim(Value val, Value index) const {
16571658

16581659
void MemRefBuilder::prefetch(Value memref, ValueRange indices, bool isWrite,
16591660
unsigned locality, bool isData) {
1661+
if (disableMemRefPrefetch)
1662+
return;
16601663
b().create<memref::PrefetchOp>(
16611664
loc(), memref, indices, isWrite, locality, isData);
16621665
}
16631666

16641667
void MemRefBuilder::prefetchIE(Value memref, ArrayRef<IndexExpr> indices,
16651668
bool isWrite, unsigned locality, bool isData) {
1669+
if (disableMemRefPrefetch)
1670+
return;
16661671
SmallVector<Value, 4> indexVals;
16671672
IndexExpr::getValues(indices, indexVals);
16681673
prefetch(memref, indexVals, isWrite, locality, isData);

0 commit comments

Comments
 (0)