-
Notifications
You must be signed in to change notification settings - Fork 328
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use DisposableElementsAttr for ZHigh constant propagation (#3013)
* Revert "[NNPA] Memory reduction of stickified constant by stickifying at file writing (#2917)" This reverts commit 33b466e. Signed-off-by: Tung D. Le <[email protected]> * Use DisposableElementsAttr for ZHigh Constant Propagation Signed-off-by: Tung D. Le <[email protected]> --------- Signed-off-by: Tung D. Le <[email protected]>
- Loading branch information
Showing
50 changed files
with
781 additions
and
849 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/Accelerators/NNPA/Compiler/ZHighDisposableGarbageCollector.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
//===---------------- ZHighDisposableGarbageCollector.cpp -----------------===// | ||
// | ||
// Garbage collects DisposableElementsAttr attributes. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "src/Accelerators/NNPA/Compiler/ZHighDisposableGarbageCollector.hpp" | ||
#include "src/Accelerators/NNPA/Dialect/ZHigh/ZHighOps.hpp" | ||
#include "src/Dialect/ONNX/ElementsAttr/DisposablePool.hpp" | ||
#include "src/Dialect/ONNX/ONNXDialect.hpp" | ||
#include "src/Dialect/ONNX/ONNXOps.hpp" | ||
|
||
#include "mlir/IR/BuiltinOps.h" | ||
|
||
using namespace mlir; | ||
|
||
namespace onnx_mlir { | ||
namespace zhigh { | ||
|
||
ZHighDisposableGarbageCollector::ZHighDisposableGarbageCollector( | ||
MLIRContext *context) | ||
: disposablePool(*DisposablePool::get<ONNXDialect>(context)) {} | ||
|
||
ZHighDisposableGarbageCollector::~ZHighDisposableGarbageCollector() {} | ||
|
||
void ZHighDisposableGarbageCollector::runAfterPass(Pass *pass, Operation *op) { | ||
if (!disposablePool.isActive()) | ||
return; | ||
ModuleOp moduleOp = mlir::dyn_cast<ModuleOp>(op); | ||
if (!moduleOp) | ||
return; | ||
disposablePool.garbageCollectUnreachable( | ||
moduleOp, {{ONNXConstantOp::getOperationName(), "value"}, | ||
{ONNXConstantOfShapeOp::getOperationName(), "value"}, | ||
{ZHighStickifiedConstantOp::getOperationName(), "value"}}); | ||
} | ||
|
||
} // namespace zhigh | ||
} // namespace onnx_mlir |
37 changes: 37 additions & 0 deletions
37
src/Accelerators/NNPA/Compiler/ZHighDisposableGarbageCollector.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
//===---------------- ZHighDisposableGarbageCollector.hpp -----------------===// | ||
// | ||
// Garbage collects DisposableElementsAttr attributes. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef ONNX_MLIR_ZHIGH_GARBAGE_COLLECTOR_H | ||
#define ONNX_MLIR_ZHIGH_GARBAGE_COLLECTOR_H | ||
|
||
#include "mlir/Pass/PassInstrumentation.h" | ||
|
||
namespace mlir { | ||
class MLIRContext; | ||
} | ||
|
||
namespace onnx_mlir { | ||
class DisposablePool; | ||
|
||
namespace zhigh { | ||
|
||
struct ZHighDisposableGarbageCollector : public mlir::PassInstrumentation { | ||
ZHighDisposableGarbageCollector(mlir::MLIRContext *context); | ||
~ZHighDisposableGarbageCollector() override; | ||
|
||
void runAfterPass(mlir::Pass *pass, mlir::Operation *op) override; | ||
|
||
private: | ||
DisposablePool &disposablePool; | ||
}; | ||
|
||
} // namespace zhigh | ||
} // namespace onnx_mlir | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.