diff --git a/paddle/infrt/dialect/infrt/infrt_ops.td b/paddle/infrt/dialect/infrt/infrt_ops.td index ecd7093e72b8ad41a6385acb81dacfb6a0c4197b..e07a598d9bc631f416f6bcc0362b577267c5616a 100644 --- a/paddle/infrt/dialect/infrt/infrt_ops.td +++ b/paddle/infrt/dialect/infrt/infrt_ops.td @@ -18,6 +18,22 @@ def Infrt_KernelOp : Infrt_Op<"kernel", [NoSideEffect]> { let results = (outs Variadic); } +def Infrt_ReturnOp : Infrt_Op<"return", [Terminator]> { + let summary = "host executor return operation"; + let description = [{ + The "infrt.return" operation represents a return operation within a function. + + func @foo() : (i32, f8) { + infrt.return %0, %1 : i32, f8 + } + }]; + + let arguments = (ins Variadic:$operands); + + let builders = [OpBuilder<(ins), + [{ build($_builder, $_state, llvm::None); }]>]; +} + def Infrt_CvtTensorOp : Infrt_Op<"cvt_tensor", [NoSideEffect]> { let summary = "convert tensor type op"; let description = [{convert tensor type op!}]; diff --git a/paddle/infrt/dialect/pd_ops.cc b/paddle/infrt/dialect/pd_ops.cc index 338b04e001320289b71f6127318e7a073cefcacf..55ab174fcaf059d81f83e54e8f1e5864ef25b7e3 100644 --- a/paddle/infrt/dialect/pd_ops.cc +++ b/paddle/infrt/dialect/pd_ops.cc @@ -16,7 +16,6 @@ #include #include -#include "paddle/infrt/dialect/infrt/infrt_dialect.h" #include "paddle/infrt/dialect/infrt_base.h" #define GET_OP_CLASSES diff --git a/paddle/infrt/dialect/pd_ops.h b/paddle/infrt/dialect/pd_ops.h index b48c68060d42efdeecccd68abc5efb3045643370..41dd2ddd94eb161735568170a9a8bdc2ec259cdf 100644 --- a/paddle/infrt/dialect/pd_ops.h +++ b/paddle/infrt/dialect/pd_ops.h @@ -28,6 +28,7 @@ #include #include #include +#include "paddle/infrt/dialect/infrt/infrt_dialect.h" namespace mlir { namespace pd { diff --git a/paddle/infrt/dialect/tensorrt/trt_dilaect_types.h b/paddle/infrt/dialect/tensorrt/trt_dialect_types.h similarity index 91% rename from paddle/infrt/dialect/tensorrt/trt_dilaect_types.h rename to paddle/infrt/dialect/tensorrt/trt_dialect_types.h index efcf7dd5be19524293c8b58db26f35b9c11afb3d..0c3edcec1edb2d7774038e638f8c20f94a3e7166 100644 --- a/paddle/infrt/dialect/tensorrt/trt_dilaect_types.h +++ b/paddle/infrt/dialect/tensorrt/trt_dialect_types.h @@ -23,6 +23,8 @@ class EngineType : public mlir::Type::TypeBase { public: using Base::Base; + static EngineType get(); + static EngineType get(mlir::MLIRContext *context); }; } // namespace trt diff --git a/paddle/infrt/dialect/tensorrt/trt_graph_fuse_pass.cc b/paddle/infrt/dialect/tensorrt/trt_graph_fuse_pass.cc index fa0095363c5fd34778162fb4e3204450ef1e7815..ad6b136463a71dcc2fcd9ce2b4e2da6f68e88dd2 100644 --- a/paddle/infrt/dialect/tensorrt/trt_graph_fuse_pass.cc +++ b/paddle/infrt/dialect/tensorrt/trt_graph_fuse_pass.cc @@ -53,9 +53,9 @@ bool reverseDfs(std::vector source, } // merge the first&second graph op to a new graph op. -void mergeTwoAdjacentCreateEngineOp(mlir::OpBuilder &builder, // NOLINT - CreateEngineOp first, - CreateEngineOp second) { +void mergeTwoAdjacentGraphOp(mlir::OpBuilder &builder, // NOLINT + mlir::pd::GraphOp first, + mlir::pd::GraphOp second) { // comput inputs and outputs ::llvm::SmallVector inputs(first.getOperands()), outputs; for (mlir::Value input : second.getOperands()) { @@ -84,8 +84,7 @@ void mergeTwoAdjacentCreateEngineOp(mlir::OpBuilder &builder, // NOLINT // create the new graph op builder.setInsertionPoint(first); auto loc = first.getLoc(); - auto graph_op = - builder.create(loc, return_types, inputs, true); + auto graph_op = builder.create(loc, return_types, inputs); mlir::Block *block = new mlir::Block; auto copy_range = second.getBody()->without_terminator(); block->getOperations().splice(block->begin(), @@ -98,7 +97,7 @@ void mergeTwoAdjacentCreateEngineOp(mlir::OpBuilder &builder, // NOLINT copy_range.begin(), copy_range.end()); builder.setInsertionPointToEnd(block); - builder.create<::infrt::dialect::ReturnOp>(loc, outputs); + builder.create<::infrt::ReturnOp>(loc, outputs); graph_op.body().push_back(block); // mapping the output @@ -150,12 +149,13 @@ void TRTGraphFusePass::runOnFunction() { do { changed = false; for (auto &op : body) { - CreateEngineOp graph_op = ::llvm::dyn_cast_or_null(&op); + mlir::pd::GraphOp graph_op = + ::llvm::dyn_cast_or_null(&op); if (nullptr == graph_op) continue; for (auto user_op : op.getUsers()) { - CreateEngineOp user_graph_op = - ::llvm::dyn_cast_or_null(user_op); + mlir::pd::GraphOp user_graph_op = + ::llvm::dyn_cast_or_null(user_op); if (nullptr == user_graph_op) continue; // get all dst input nodes except src. std::vector source_nodes; @@ -168,7 +168,7 @@ void TRTGraphFusePass::runOnFunction() { // Reverse DFS from the source_nodes. if (!reverseDfs(source_nodes, [&op](const mlir::Operation *n) { return n == &op; })) { - mergeTwoAdjacentCreateEngineOp(builder, graph_op, user_graph_op); + mergeTwoAdjacentGraphOp(builder, graph_op, user_graph_op); changed = true; break; } diff --git a/paddle/infrt/dialect/tensorrt/trt_graph_fuse_pass.h b/paddle/infrt/dialect/tensorrt/trt_graph_fuse_pass.h index 350add905aac75c0ba8527aa6e9bc1510fab876c..803e53e3244f92134928e1105a8248e9f49e5432 100644 --- a/paddle/infrt/dialect/tensorrt/trt_graph_fuse_pass.h +++ b/paddle/infrt/dialect/tensorrt/trt_graph_fuse_pass.h @@ -15,7 +15,6 @@ #pragma once #include #include "paddle/infrt/dialect/infrt_base.h" -#include "paddle/infrt/dialect/tensorrt/trt_ops.h" namespace infrt { namespace trt { @@ -26,40 +25,37 @@ namespace trt { * * source func: * - * func @main() -> tensor { - * %a = "pd.feed"()... - * %c = "trt.create_engine"(%a) { + * func @main(%a : tensor) -> tensor { + * %c = "pd.graph"(%a) { * %m = "pd.conv2d"(%a)... - * "Infrt.return" %m + * "infrt.return" (%m) * } ... - * %d = "trt.create_engine"(%c) { + * %d = "pd.graph"(%c) { * %m = "pd.conv3d"(%c)... - * "Infrt.return" %m + * "infrt.return" (%m) * } ... - * %f = "trt.create_engine"(%a) { + * %f = "pd.graph"(%a) { * %m = "pd.conv2d"(%a)... - * "Infrt.return" %m + * "infrt.return" (%m) * } ... - * "pd.fetch" %d, %f + * "infrt.return" (%d, %f).. + * } * * destination func: - * func @main() -> tensor { - * %a = "pd.feed"()... - * %d, %f = "trt.create_engine"(%a) { + * func @main(%a : tensor) -> tensor { + * %d, %f = "pd.graph"(%a) { * %m = "pd.conv2d"(%a)... * %n = "pd.conv3d"(%m)... * %s = "pd.conv2d"(%a)... - * "Infrt.return" %n, %s + * "infrt.return" (%n, %s) * } ... - * "pd.fetch" %d, %f + * "infrt.return" (%d, %f) * } */ class TRTGraphFusePass : public mlir::PassWrapper { public: - void getDependentDialects(mlir::DialectRegistry ®istry) const override { - registry.insert(); - } + void getDependentDialects(mlir::DialectRegistry ®istry) const override {} ::llvm::StringRef getName() const override { return "trtGraphFusePass"; } void runOnFunction() override; }; diff --git a/paddle/infrt/dialect/tensorrt/trt_graph_split_pass.cc b/paddle/infrt/dialect/tensorrt/trt_graph_split_pass.cc index 5ee7b23213a0106d3491712c37d34940f7c15c58..e3a7b455024c65d40ccbafb28fba9e9b0ead0369 100644 --- a/paddle/infrt/dialect/tensorrt/trt_graph_split_pass.cc +++ b/paddle/infrt/dialect/tensorrt/trt_graph_split_pass.cc @@ -16,23 +16,23 @@ #include #include "paddle/infrt/dialect/pd_ops.h" -#include "paddle/infrt/dialect/tensorrt/trt_ops.h" namespace infrt { namespace trt { // Implementation of the trtGraphSplitPass。 void TRTGraphSplitPass::runOnFunction() { - std::vector worklist; + std::vector worklist; mlir::Block& block = getFunction().front(); for (auto& op : block) { - CreateEngineOp graph_op = ::llvm::dyn_cast_or_null(&op); + mlir::pd::GraphOp graph_op = + ::llvm::dyn_cast_or_null(&op); if (nullptr != graph_op && graph_op.getBody()->getOperations().size() <= min_subgraph_size_) { worklist.push_back(graph_op); } } while (!worklist.empty()) { - CreateEngineOp graph_op = worklist.back(); + mlir::pd::GraphOp graph_op = worklist.back(); worklist.pop_back(); mlir::Block* body = graph_op.getBody(); auto return_op = body->getTerminator(); diff --git a/paddle/infrt/dialect/tensorrt/trt_graph_split_pass.h b/paddle/infrt/dialect/tensorrt/trt_graph_split_pass.h index 28078e2bc2dbff46d6a9eaf5522b949f68785898..1c44a13cf9dfb65a1747a596dc1012e7f54d792e 100644 --- a/paddle/infrt/dialect/tensorrt/trt_graph_split_pass.h +++ b/paddle/infrt/dialect/tensorrt/trt_graph_split_pass.h @@ -15,7 +15,6 @@ #pragma once #include #include "paddle/infrt/dialect/infrt_base.h" -#include "paddle/infrt/dialect/tensorrt/trt_ops.h" namespace infrt { namespace trt { @@ -27,33 +26,29 @@ namespace trt { * * source func: * - * func @main() -> tensor { - * %a = "pd.feed"()... - * %d, %f = "trt.create_engine"(%a) { + * func @main(%a : tensor) -> tensor { + * %d, %f = "pd.graph"(%a) { * %m = "pd.conv2d"(%a)... * %n = "pd.conv3d"(%m)... * %s = "pd.conv2d"(%a)... - * "Infrt.return" (%n, %s) + * "infrt.return" (%n, %s)... * } ... - * "pd.fetch" (%d, %f) + * "infrt.return" (%d, %f)... * } * * destination func: - * func @main() -> tensor { - * %a = "pd.feed"()... + * func @main(%a : tensor) -> tensor { * %c = "pd.conv2d"(%a) ... * %d = "pd.conv3d"(%c) ... * %f = "pd.conv2d"(%a) ... - * "pd.fetch" (%d, %f) + * "infrt.return" (%d, %f)... * } */ class TRTGraphSplitPass : public mlir::PassWrapper { public: ::llvm::StringRef getName() const override { return "trtGraphSplitPass"; } - void getDependentDialects(mlir::DialectRegistry ®istry) const override { - registry.insert(); - } + void getDependentDialects(mlir::DialectRegistry ®istry) const override {} void runOnFunction() override; explicit TRTGraphSplitPass(size_t min_subgraph_size = 3) : min_subgraph_size_(min_subgraph_size) {} diff --git a/paddle/infrt/dialect/tensorrt/trt_op_converter_pass.cc b/paddle/infrt/dialect/tensorrt/trt_op_converter_pass.cc index 8d81e739d9c72ebcaa57b927a360864db59d7e97..1be5f4dbc39d7699b6d8a36cfb3e164694e908c1 100644 --- a/paddle/infrt/dialect/tensorrt/trt_op_converter_pass.cc +++ b/paddle/infrt/dialect/tensorrt/trt_op_converter_pass.cc @@ -16,12 +16,64 @@ #include #include "paddle/infrt/dialect/infrt_base.h" #include "paddle/infrt/dialect/pd_ops.h" +#include "paddle/infrt/dialect/tensorrt/trt_dialect_types.h" namespace infrt { namespace trt { #include "paddle/infrt/dialect/tensorrt/pd_lower_to_trt.cpp.inc" // NOLINT +struct PD2TRT_GraphLower : public ::mlir::RewritePattern { + PD2TRT_GraphLower(::mlir::MLIRContext *context) + : ::mlir::RewritePattern("pd.graph", 1, context, {"trt.create_engine"}) {} + ::mlir::LogicalResult matchAndRewrite( + ::mlir::Operation *op, ::mlir::PatternRewriter &rewriter) const override { + auto casted_op = ::llvm::dyn_cast(op); + ::mlir::Operation::operand_range inputs = casted_op.inputs(); + auto ods_loc = rewriter.getFusedLoc(op->getLoc()); + CreateEngineOp create_engine_op; + // inputs + ::mlir::SmallVector<::mlir::Value, 4> trt_inputs; + for (auto v : inputs) { + trt_inputs.push_back(v); + } + create_engine_op = rewriter.create( + ods_loc, + ::llvm::SmallVector(1, EngineType::get()), + trt_inputs, + true /*run_once*/); + ::mlir::Block *block = new ::mlir::Block; + block->getOperations().splice(block->begin(), + casted_op.getBody()->getOperations(), + casted_op.getBody()->begin(), + casted_op.getBody()->end()); + create_engine_op.body().push_back(block); + + // trt.execute + // outputs + ::llvm::SmallVector<::mlir::Type, 4> execute_outputs_types; + for (auto v : casted_op.getODSResults(0)) { + execute_outputs_types.push_back(v.getType()); + } + // inputs + ::mlir::SmallVector<::mlir::Value, 4> execute_inputs( + create_engine_op.getODSResults(0)); + for (auto v : inputs) { + execute_inputs.push_back(v); + } + auto execute_op = rewriter.create( + ods_loc, execute_outputs_types, execute_inputs); + + ::llvm::SmallVector<::mlir::Value, 4> replace_values; + for (auto v : + ::llvm::SmallVector<::mlir::Value, 4>{execute_op.getODSResults(0)}) { + replace_values.push_back(v); + } + rewriter.replaceOp(op, replace_values); + return ::mlir::success(); + } +}; + void TRTOpConverterPass::runOnOperation() { // The first thing to define is the conversion target. This will define the // final target for this lowering. @@ -36,6 +88,7 @@ void TRTOpConverterPass::runOnOperation() { // the set of patterns that will lower the TensorRT operations. ::mlir::RewritePatternSet patterns(&getContext()); populateWithGenerated(patterns); + patterns.add(&getContext()); // With the target and rewrite patterns defined, we can now attempt the // conversion. The conversion will signal failure if any of our `illegal` diff --git a/paddle/infrt/dialect/tensorrt/trt_op_converter_pass.h b/paddle/infrt/dialect/tensorrt/trt_op_converter_pass.h index a8128a585ee82dc60811c65b1105beb33e8c3b18..7550d8c84e19504fc0f41067c1194703a55410ba 100644 --- a/paddle/infrt/dialect/tensorrt/trt_op_converter_pass.h +++ b/paddle/infrt/dialect/tensorrt/trt_op_converter_pass.h @@ -15,6 +15,7 @@ #pragma once #include "mlir/IR/Dialect.h" #include "mlir/Pass/Pass.h" +#include "paddle/infrt/dialect/infrt/infrt_dialect.h" #include "paddle/infrt/dialect/tensorrt/trt_ops.h" namespace infrt { @@ -23,27 +24,26 @@ namespace trt { * trtOpConverterPass. * * source ir: - * func @main() -> tensor { - * %a = "pd.feed"()... - * %d, %f = "trt.create_engine"(%a) { + * func @main(%a : tensor) -> tensor { + * %d, %f = "pd.graph"(%a) { * %m = "pd.conv2d"(%a)... * %n = "pd.conv3d"(%m)... * %s = "pd.conv2d"(%a)... - * "Infrt.return" %n, %s + * "infrt.return" (%n, %s)... * } ... - * "pd.fetch" %d, %f + * "infrt.return" (%d, %f)... * } * * destination ir: - * func @main() -> tensor { - * %a = "pd.feed"()... - * %d, %f = "trt.create_engine"(%a) { + * func @main(%a : tensor) -> tensor { + * %engine = "trt.create_engine"(%a) ({ * %m = "trt.Convolution"(%a)... * %n = "trt.Convolution"(%m)... * %s = "trt.Convolution"(%a)... - * "Infrt.return" %n, %s - * } ... - * "pd.fetch" %d, %f + * "infrt.return" (%n, %s)... + * }){run_once = true} ... + * %d, %f = "trt.execute"(%engine, %a)... + * "infrt.return" (%d, %f)... * } */ struct TRTOpConverterPass diff --git a/paddle/infrt/dialect/tensorrt/trt_op_teller_pass.cc b/paddle/infrt/dialect/tensorrt/trt_op_teller_pass.cc index 17e893a383a9cd3f893e80181858dc3cc2b0552b..13b7f1aee55d2a2d30822a878bbd50d385411f43 100644 --- a/paddle/infrt/dialect/tensorrt/trt_op_teller_pass.cc +++ b/paddle/infrt/dialect/tensorrt/trt_op_teller_pass.cc @@ -16,6 +16,7 @@ #include #include "paddle/infrt/dialect/basic_kernels.h" +#include "paddle/infrt/dialect/infrt/infrt_dialect.h" #include "paddle/infrt/dialect/pd_ops.h" namespace infrt { @@ -37,11 +38,11 @@ void TRTOpTellerPass::runOnFunction() { if (::llvm::dyn_cast_or_null(op)) continue; if (::llvm::dyn_cast_or_null(op)) continue; if (::llvm::dyn_cast_or_null(op)) continue; - if (::llvm::dyn_cast_or_null(op)) continue; + if (::llvm::dyn_cast_or_null<::infrt::ReturnOp>(op)) continue; builder.setInsertionPoint(op); auto loc = getFunction().getLoc(); - auto graph_op = builder.create( - loc, op->getResultTypes(), op->getOperands(), true); + auto graph_op = builder.create( + loc, op->getResultTypes(), op->getOperands()); ::llvm::SmallVector tblgen_repl_values; for (auto v : @@ -54,7 +55,7 @@ void TRTOpTellerPass::runOnFunction() { graph_op.body().push_back(block); op->moveBefore(block, block->begin()); builder.setInsertionPointToEnd(block); - builder.create<::infrt::dialect::ReturnOp>(loc, op->getResults()); + builder.create<::infrt::ReturnOp>(loc, op->getResults()); } } } // namespace trt diff --git a/paddle/infrt/dialect/tensorrt/trt_op_teller_pass.h b/paddle/infrt/dialect/tensorrt/trt_op_teller_pass.h index 471eafa9f9ba33dad4182ba7da55a607c2bf8f0d..b9e461c8633d906fd46e9f7d6799e8a157915048 100644 --- a/paddle/infrt/dialect/tensorrt/trt_op_teller_pass.h +++ b/paddle/infrt/dialect/tensorrt/trt_op_teller_pass.h @@ -15,7 +15,6 @@ #pragma once #include #include "paddle/infrt/dialect/infrt_base.h" -#include "paddle/infrt/dialect/tensorrt/trt_ops.h" namespace infrt { namespace trt { @@ -26,30 +25,28 @@ namespace trt { * * source func: * - * func @main() -> tensor { - * %a = "pd.feed"()... + * func @main(%a : tensor) -> tensor { * %c = "pd.conv2d"(%a) ... * %d = "pd.conv3d"(%c) ... * %f = "pd.conv2d"(%a) ... - * "pd.fetch" (%d, %f) + * "infrt.return"(%d, %f) ... * } * * destination func: - * func @main() -> tensor { - * %a = "pd.feed"()... - * %c = "trt.create_engine"(%a) { + * func @main(%a : tensor) -> tensor { + * %c = "pd.graph"(%a) { * %m = "pd.conv2d"(%a)... - * "Infrt.return" (%m) + * "infrt.return" (%m) * } ... - * %d = "trt.create_engine"(%c) { + * %d = "pd.graph"(%c) { * %m = "pd.conv3d"(%c)... - * "Infrt.return" (%m) + * "infrt.return" (%m) * } ... - * %f = "trt.create_engine"(%a) { + * %f = "pd.graph"(%a) { * %m = "pd.conv2d"(%a)... - * "Infrt.return" (%m) + * "infrt.return" (%m) * } ... - * "pd.fetch" (%d, %f) + * "infrt.return" (%d, %f) * } * TODO(winter-wang): Supplementary how to judge the operators can be supported * by tensorrt. @@ -57,9 +54,7 @@ namespace trt { class TRTOpTellerPass : public mlir::PassWrapper { public: - void getDependentDialects(mlir::DialectRegistry ®istry) const override { - registry.insert(); - } + void getDependentDialects(mlir::DialectRegistry ®istry) const override {} ::llvm::StringRef getName() const override { return "trtOpTellerPass"; } void runOnFunction() override; }; diff --git a/paddle/infrt/dialect/tensorrt/trt_ops.cc b/paddle/infrt/dialect/tensorrt/trt_ops.cc index f179939e2320613bb5ce3ebd0f21e01f7abff2f0..d5222976625a2adece9a87c8952dba10137ae9ba 100644 --- a/paddle/infrt/dialect/tensorrt/trt_ops.cc +++ b/paddle/infrt/dialect/tensorrt/trt_ops.cc @@ -11,7 +11,6 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. - #include "paddle/infrt/dialect/tensorrt/trt_ops.h" #include #include @@ -19,11 +18,20 @@ #include #include #include -#include "paddle/infrt/dialect/tensorrt/trt_dilaect_types.h" +#include "paddle/infrt/common/global.h" +#include "paddle/infrt/dialect/tensorrt/trt_dialect_types.h" namespace infrt { namespace trt { +EngineType EngineType::get() { + return Base::get(::infrt::Global::getMLIRContext()); +} + +EngineType EngineType::get(mlir::MLIRContext *context) { + return Base::get(context); +} + TensorRTDialect::TensorRTDialect(mlir::MLIRContext *context) : mlir::Dialect("trt", context, mlir::TypeID::get()) { addTypes(); diff --git a/paddle/infrt/dialect/tensorrt/trt_ops.h b/paddle/infrt/dialect/tensorrt/trt_ops.h index 978b9906e5f52b69565673eae270c658b5232bd8..44444232915bad7d25b0ecedfa8e8427f4567e49 100644 --- a/paddle/infrt/dialect/tensorrt/trt_ops.h +++ b/paddle/infrt/dialect/tensorrt/trt_ops.h @@ -29,6 +29,8 @@ #include #include #include "paddle/infrt/dialect/basic_kernels.h" +#include "paddle/infrt/dialect/infrt/infrt_dialect.h" +#include "paddle/infrt/dialect/pd_ops.h" namespace infrt { namespace trt { diff --git a/paddle/infrt/dialect/tensorrt/trt_ops.td b/paddle/infrt/dialect/tensorrt/trt_ops.td index 31142a5157bfcd544128671fbdf22a993f1cc646..132a1d7805bdb85af8716e384ec29357a6ff68ad 100755 --- a/paddle/infrt/dialect/tensorrt/trt_ops.td +++ b/paddle/infrt/dialect/tensorrt/trt_ops.td @@ -7,14 +7,24 @@ include "mlir/Interfaces/CallInterfaces.td" include "mlir/IR/OpBase.td" include "paddle/infrt/dialect/tensorrt/trt_op_base.td" -def TRT_CreateEngineOp : TRT_Op<"create_engine", [SingleBlockImplicitTerminator<"::infrt::dialect::ReturnOp">]> { - let summary = "trt Graph Op"; + +def TRT_CreateEngineOp : TRT_Op<"create_engine", [SingleBlockImplicitTerminator<"::infrt::ReturnOp">]> { + let summary = "trt CreateEngine Op"; let description = [{ Describe a tensorrt subgraph. }]; let regions = (region SizedRegion<1>:$body); let arguments = (ins Variadic:$inputs, DefaultValuedAttr:$run_once); - let results = (outs Variadic:$outputs); + let results = (outs TRT_EngineType:$output); +} + +def TRT_ExecuteOp : TRT_Op<"execute", [NoSideEffect]> { + let summary = "trt execute Op"; + let description = [{ + Describe a tensorrt runtime. + }]; + let arguments = (ins TRT_EngineType:$engine, Variadic:$inputs); + let results = (outs Variadic:$output); } def TRT_ActivationOp : TRT_Op<"Activation", [NoSideEffect]> { diff --git a/paddle/infrt/tests/dialect/trt_ops.mlir b/paddle/infrt/tests/dialect/trt_ops.mlir index 49510bc542dc0409067b5d61cb189dfab8b6601f..6d25044d139f32c0a29adefb44c8fd2640cadd82 100644 --- a/paddle/infrt/tests/dialect/trt_ops.mlir +++ b/paddle/infrt/tests/dialect/trt_ops.mlir @@ -1,13 +1,6 @@ // RUN: trt-exec %s // CHECK-LABEL: @main -func @main() -> tensor { - %bias = "pd.feed"() {name="input0"} : () -> tensor - %c = "pd.feed"() {name="input1"} : () -> tensor - %b1 = "pd.feed"() {name="input2"} : () -> tensor - %b2 = "pd.feed"() {name="input3"} : () -> tensor - %bias1 = "pd.feed"() {name="input4"} : () -> tensor - %bias2 = "pd.feed"() {name="input5"} : () -> tensor - +func @main(%bias:tensor, %c:tensor, %b1:tensor, %b2:tensor, %bias1:tensor, %bias2:tensor) -> tensor { %d = "pd.elementwise_add"(%c, %bias) {axis=-1:si32} : (tensor, tensor) -> tensor %e = "pd.relu6"(%d) {} : (tensor) -> tensor @@ -19,5 +12,5 @@ func @main() -> tensor { %d2 = "pd.elementwise_add"(%c2, %bias2) {axis=-1:si32} : (tensor, tensor) -> tensor %e2 = "pd.relu"(%d2) {} : (tensor) -> tensor - "pd.fetch"(%e2) {name="output"} :(tensor)->() + "infrt.return"(%e2) : (tensor)->() } diff --git a/tools/infrt/custom_pdop.td b/tools/infrt/custom_pdop.td index 2139fbd8155bb067c542f1e54f135c828e06cc58..f754767259563f2cd64bac92adf76249b18af11f 100644 --- a/tools/infrt/custom_pdop.td +++ b/tools/infrt/custom_pdop.td @@ -33,7 +33,7 @@ def PD_ReturnOp : PD_Op<"return", [Terminator]> { let arguments = (ins Variadic:$inputs); } -def PD_GraphOp : PD_Op<"graph", [SingleBlockImplicitTerminator<"ReturnOp">]> { +def PD_GraphOp : PD_Op<"graph", [SingleBlockImplicitTerminator<"::infrt::ReturnOp">]> { let summary = "paddle graph Op"; let description = [{ Describe a paddle graph or subgraph.