From 9acc12cd7f096aa9b634b6117494b5a5b094c28c Mon Sep 17 00:00:00 2001 From: Candy2Tang Date: Wed, 9 Aug 2023 20:01:23 +0800 Subject: [PATCH 1/2] Refine interface of hlir::framework::Instruction --- paddle/cinn/hlir/framework/instruction.cc | 2 +- paddle/cinn/hlir/framework/instruction.h | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/paddle/cinn/hlir/framework/instruction.cc b/paddle/cinn/hlir/framework/instruction.cc index 01fb89aa2ac0d..09d644e8533ab 100644 --- a/paddle/cinn/hlir/framework/instruction.cc +++ b/paddle/cinn/hlir/framework/instruction.cc @@ -365,7 +365,7 @@ void Instruction::Run( // } } -std::string Instruction::DumpInstruction() { +std::string Instruction::DumpInstruction() const { std::stringstream ss; ss << "Instruction {" << std::endl; for (size_t i = 0; i < fn_names_.size(); ++i) { diff --git a/paddle/cinn/hlir/framework/instruction.h b/paddle/cinn/hlir/framework/instruction.h index 23da5c532c4cd..cc64c4e64bbe3 100644 --- a/paddle/cinn/hlir/framework/instruction.h +++ b/paddle/cinn/hlir/framework/instruction.h @@ -132,13 +132,17 @@ class Instruction { int size() { return fn_ptrs_.size(); } - std::string DumpInstruction(); + std::string DumpInstruction() const; - std::vector> GetInArgs() { return in_args_; } - std::vector> GetOutArgs() { return out_args_; } + const std::vector>& GetInArgs() const { + return in_args_; + } + const std::vector>& GetOutArgs() const { + return out_args_; + } void ClearInArgs() { in_args_.clear(); } void ClearOutArgs() { out_args_.clear(); } - std::vector GetFnNames() { return fn_names_; } + const std::vector& GetFnNames() const { return fn_names_; } void AddInArgs(const std::vector& in_args) { in_args_.push_back(in_args); } From 692a5bc8a318db36563775fd4acefcf4e5608819 Mon Sep 17 00:00:00 2001 From: Candy2Tang Date: Wed, 9 Aug 2023 20:26:16 +0800 Subject: [PATCH 2/2] fix client usage --- paddle/cinn/hlir/framework/program.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/paddle/cinn/hlir/framework/program.cc b/paddle/cinn/hlir/framework/program.cc index 95799e05fcca6..eadbfdf4d7d2c 100644 --- a/paddle/cinn/hlir/framework/program.cc +++ b/paddle/cinn/hlir/framework/program.cc @@ -140,9 +140,9 @@ void Program::Export(const std::vector& persistent_vars, int instplaceholder = writeplaceholder(4 * 3, insnum, f); int findex = 0; for (auto& ins : instrs_) { - auto in_args = ins->GetInArgs(); - auto out_args = ins->GetOutArgs(); - auto fn_names = ins->GetFnNames(); + auto& in_args = ins->GetInArgs(); + auto& out_args = ins->GetOutArgs(); + auto& fn_names = ins->GetFnNames(); for (int i = 0; i < fn_names.size(); i++, findex++) { std::vector all_args(in_args[i].begin(), in_args[i].end()); all_args.insert(