-
Notifications
You must be signed in to change notification settings - Fork 320
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change lowering of onnx.IF to Krnl (#2932)
* implementation Signed-off-by: chentong319 <[email protected]> * test case change Signed-off-by: chentong319 <[email protected]> * format Signed-off-by: chentong319 <[email protected]> * add test for If back Signed-off-by: chentong319 <[email protected]> * format Signed-off-by: chentong319 <[email protected]> --------- Signed-off-by: chentong319 <[email protected]> Co-authored-by: Tung D. Le <[email protected]>
- Loading branch information
1 parent
ce4e041
commit c5d3e72
Showing
7 changed files
with
72 additions
and
16 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
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,57 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
//===--------------------- Yield.cpp - Lowering Yield Op ------------------===// | ||
// | ||
// Copyright 2019-2023 The IBM Research Authors. | ||
// | ||
// ============================================================================= | ||
// | ||
// This file lowers the ONNX Yield Operator to Krnl dialect. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "mlir/Dialect/SCF/IR/SCF.h" | ||
|
||
#include "src/Conversion/ONNXToKrnl/ONNXToKrnlCommon.hpp" | ||
|
||
using namespace mlir; | ||
|
||
namespace onnx_mlir { | ||
|
||
struct ONNXYieldOpLowering : public OpConversionPattern<ONNXYieldOp> { | ||
ONNXYieldOpLowering(TypeConverter &typeConverter, MLIRContext *ctx) | ||
: OpConversionPattern(typeConverter, ctx) {} | ||
|
||
LogicalResult matchAndRewrite(ONNXYieldOp yieldOp, ONNXYieldOpAdaptor adaptor, | ||
ConversionPatternRewriter &rewriter) const final { | ||
// Gather info. | ||
Operation *op = yieldOp.getOperation(); | ||
Location loc = ONNXLoc<ONNXYieldOp>(op); | ||
|
||
MultiDialectBuilder<KrnlBuilder, MathBuilder, MemRefBuilder> create( | ||
rewriter, loc); | ||
|
||
ValueRange inputs = yieldOp.getOperands(); | ||
llvm::SmallVector<Value> outputs; | ||
for (Value input : inputs) { | ||
Type inputType = input.getType(); | ||
Type outputType = typeConverter->convertType(inputType); | ||
outputs.emplace_back(typeConverter->materializeTargetConversion( | ||
rewriter, loc, outputType, input)); | ||
} | ||
|
||
rewriter.replaceOpWithNewOp<scf::YieldOp>(yieldOp, outputs); | ||
|
||
onnxToKrnlSimdReport(op); | ||
return success(); | ||
} | ||
}; | ||
|
||
void populateLoweringONNXYieldOpPattern(RewritePatternSet &patterns, | ||
TypeConverter &typeConverter, MLIRContext *ctx) { | ||
patterns.insert<ONNXYieldOpLowering>(typeConverter, ctx); | ||
} | ||
|
||
} // namespace onnx_mlir |
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 was deleted.
Oops, something went wrong.