Skip to content

Commit

Permalink
try to use new buffer deallocation (#2919)
Browse files Browse the repository at this point in the history
* implementation

Signed-off-by: Chen Tong <chentong@us.ibm.com>

* comments

Signed-off-by: Chen Tong <chentong@us.ibm.com>

* format

Signed-off-by: Chen Tong <chentong@us.ibm.com>

---------

Signed-off-by: Chen Tong <chentong@us.ibm.com>
Co-authored-by: Tung D. Le <tung@jp.ibm.com>
Co-authored-by: Alexandre Eichenberger <alexe@us.ibm.com>
  • Loading branch information
3 people authored Sep 11, 2024
1 parent c814ad0 commit 02f45b0
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Compiler/CompilerDialects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ DialectRegistry registerDialects(ArrayRef<accel::Accelerator::Kind> accels) {
for (auto *accel : accel::Accelerator::getAccelerators())
accel->registerDialects(registry);

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

return registry;
}
Expand Down
8 changes: 8 additions & 0 deletions src/Compiler/CompilerOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ bool enableONNXHybridPass; // common for both
std::vector<std::string> functionsToDecompose; // common for both
std::string opsForCall; // common for both
bool disableKrnlOpFusion; // common for both
bool disableMemRefPrefetch; // common for both
EmissionTargetType emissionTarget; // onnx-mlir only
bool invokeOnnxVersionConverter; // onnx-mlir only
bool preserveLocations; // onnx-mlir only
Expand Down Expand Up @@ -211,6 +212,13 @@ static llvm::cl::opt<bool, true> disableKrnlOpFusionOpt(
llvm::cl::location(disableKrnlOpFusion), llvm::cl::init(false),
llvm::cl::cat(OnnxMlirCommonOptions));

static llvm::cl::opt<bool, true> disableMemRefPrefetchOpt(
"disable-memref-prefetch",
llvm::cl::desc("disable generation of memref.prefetch (default=false)\n"
"Set to 'true' if you want to disable prefetch."),
llvm::cl::location(disableMemRefPrefetch), llvm::cl::init(false),
llvm::cl::cat(OnnxMlirCommonOptions));

static llvm::cl::opt<bool, true> disableRecomposeOptionOpt("disable-recompose",
llvm::cl::desc("Disable recomposition of ONNX operations."),
llvm::cl::location(disableRecomposeOption), llvm::cl::init(false),
Expand Down
1 change: 1 addition & 0 deletions src/Compiler/CompilerOptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ extern bool enableONNXHybridPass; // common for both
extern std::vector<std::string> functionsToDecompose; // common for both
extern std::string opsForCall; // common for both
extern bool disableKrnlOpFusion; // common for both
extern bool disableMemRefPrefetch; // common for both
extern EmissionTargetType emissionTarget; // onnx-mlir only
extern bool invokeOnnxVersionConverter; // onnx-mlir only
extern bool preserveLocations; // onnx-mlir only
Expand Down
1 change: 1 addition & 0 deletions src/Dialect/Krnl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ add_onnx_mlir_library(OMKrnlOps
OMSpecializedKernelOpInterface

LINK_LIBS PUBLIC
OMCompilerOptions
OMONNXOps
MLIRLLVMCommonConversion
MLIRAffineDialect
Expand Down
5 changes: 5 additions & 0 deletions src/Dialect/Krnl/DialectBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "llvm/ADT/TypeSwitch.h"

#include "src/Compiler/CompilerOptions.hpp"
#include "src/Conversion/ONNXToKrnl/ONNXToKrnlCommon.hpp"
#include "src/Dialect/Krnl/DialectBuilder.hpp"
#include "src/Dialect/ONNX/ONNXOps.hpp"
Expand Down Expand Up @@ -94,12 +95,16 @@ Value KrnlBuilder::getLinearOffsetIndexIE(

void KrnlBuilder::prefetch(Value memref, ValueRange indices, bool isWrite,
unsigned localityHint, bool isDataCache) {
if (disableMemRefPrefetch)
return;
b().create<KrnlPrefetchOp>(
loc(), memref, indices, isWrite, localityHint, isDataCache);
}

void KrnlBuilder::prefetchIE(Value memref, ArrayRef<IndexExpr> indices,
bool isWrite, unsigned localityHint, bool isDataCache) {
if (disableMemRefPrefetch)
return;
SmallVector<Value, 4> indexValues;
IndexExpr::getValues(indices, indexValues);
b().create<KrnlPrefetchOp>(
Expand Down
1 change: 1 addition & 0 deletions src/Dialect/Mlir/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ add_onnx_mlir_library(OMMlirDialects
OMSpecializedKernelOpInterface

LINK_LIBS PUBLIC
OMCompilerOptions
MLIRMathDialect
MLIRAffineDialect
MLIRSCFDialect
Expand Down
5 changes: 5 additions & 0 deletions src/Dialect/Mlir/DialectBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "llvm/Support/Debug.h"

// Please do not add dependences on ONNX or KRNL dialects.
#include "src/Compiler/CompilerOptions.hpp"
#include "src/Dialect/Mlir/DialectBuilder.hpp"
#include "src/Dialect/Mlir/VectorMachineSupport.hpp"

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

void MemRefBuilder::prefetch(Value memref, ValueRange indices, bool isWrite,
unsigned locality, bool isData) {
if (disableMemRefPrefetch)
return;
b().create<memref::PrefetchOp>(
loc(), memref, indices, isWrite, locality, isData);
}

void MemRefBuilder::prefetchIE(Value memref, ArrayRef<IndexExpr> indices,
bool isWrite, unsigned locality, bool isData) {
if (disableMemRefPrefetch)
return;
SmallVector<Value, 4> indexVals;
IndexExpr::getValues(indices, indexVals);
prefetch(memref, indexVals, isWrite, locality, isData);
Expand Down

0 comments on commit 02f45b0

Please sign in to comment.