!42656 change GetPrimCMap to return a const-reference hash map

Merge pull request !42656 from DeshiChen/0922_prim_map
This commit is contained in:
i-robot 2022-09-26 08:41:44 +00:00 committed by Gitee
commit 903101638c
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
4 changed files with 7 additions and 6 deletions

View File

@ -338,7 +338,7 @@ void GkUtils::UpdateFuncGraphManager(const FuncGraphManagerPtr &mng, const FuncG
} }
PrimitivePtr GkUtils::GetOpsPrim(const std::string &name) { PrimitivePtr GkUtils::GetOpsPrim(const std::string &name) {
auto op_primc_fns = ops::OpPrimCRegister::GetInstance().GetPrimCMap(); const auto &op_primc_fns = ops::OpPrimCRegister::GetInstance().GetPrimCMap();
auto const iter = op_primc_fns.find(name); auto const iter = op_primc_fns.find(name);
if (iter == op_primc_fns.end()) { if (iter == op_primc_fns.end()) {
return nullptr; return nullptr;

View File

@ -106,7 +106,7 @@ void PrimOp::SetAbastractsFromAttrs(const PrimitivePtr &primitive, const mindspo
std::pair<PrimitivePtr, AbstractBasePtrList> PrimOp::GenPrimAndAbstract(const NodePtrList &inputs, std::pair<PrimitivePtr, AbstractBasePtrList> PrimOp::GenPrimAndAbstract(const NodePtrList &inputs,
const DAttrs &attrs) const { const DAttrs &attrs) const {
auto op_primc_fns = ops::OpPrimCRegister::GetInstance().GetPrimCMap(); const auto &op_primc_fns = ops::OpPrimCRegister::GetInstance().GetPrimCMap();
const auto iter = op_primc_fns.find(op_); const auto iter = op_primc_fns.find(op_);
if (iter == op_primc_fns.end()) { if (iter == op_primc_fns.end()) {
MS_LOG(EXCEPTION) << "The PrimitiveC of [" << op_ << "] is not defined."; MS_LOG(EXCEPTION) << "The PrimitiveC of [" << op_ << "] is not defined.";
@ -330,7 +330,7 @@ NodePtr PrimOp::InferValue(const NodePtrList &inputs, const DAttrs &attrs) {
return nullptr; return nullptr;
} }
if (res == nullptr) { if (res == nullptr) {
auto op_primc_fns = ops::OpPrimCRegister::GetInstance().GetPrimCMap(); const auto &op_primc_fns = ops::OpPrimCRegister::GetInstance().GetPrimCMap();
const auto iter = op_primc_fns.find(op_); const auto iter = op_primc_fns.find(op_);
if (iter == op_primc_fns.end()) { if (iter == op_primc_fns.end()) {
return nullptr; return nullptr;

View File

@ -38,7 +38,7 @@ OpPrimCRegister &OpPrimCRegister::GetInstance() {
return instance; return instance;
} }
std::map<std::string, OpPrimCDefineFunc> OpPrimCRegister::GetPrimCMap() { return op_primc_fns_; } const HashMap<std::string, OpPrimCDefineFunc> &OpPrimCRegister::GetPrimCMap() { return op_primc_fns_; }
void OpPrimCRegister::SetPrimCMap(const std::string &kname, const OpPrimCDefineFunc &fn) { op_primc_fns_[kname] = fn; } void OpPrimCRegister::SetPrimCMap(const std::string &kname, const OpPrimCDefineFunc &fn) { op_primc_fns_[kname] = fn; }
} // namespace ops } // namespace ops
} // namespace mindspore } // namespace mindspore

View File

@ -22,6 +22,7 @@
#include <memory> #include <memory>
#include "ir/primitive.h" #include "ir/primitive.h"
#include "ir/value.h" #include "ir/value.h"
#include "utils/hash_map.h"
namespace mindspore { namespace mindspore {
namespace ops { namespace ops {
/// \brief PrimitiveC defines the base class for end side operators. /// \brief PrimitiveC defines the base class for end side operators.
@ -61,7 +62,7 @@ class MS_CORE_API OpPrimCRegister {
/// \brief Get PrimCMap of the OpPrimCRegister singleton. /// \brief Get PrimCMap of the OpPrimCRegister singleton.
/// ///
/// \return The PrimCMap of the OpPrimCRegister singleton. /// \return The PrimCMap of the OpPrimCRegister singleton.
std::map<std::string, OpPrimCDefineFunc> GetPrimCMap(); const HashMap<std::string, OpPrimCDefineFunc> &GetPrimCMap();
/// \brief Add an element into the PrimCMap of the OpPrimCRegister singleton. /// \brief Add an element into the PrimCMap of the OpPrimCRegister singleton.
/// ///
@ -71,7 +72,7 @@ class MS_CORE_API OpPrimCRegister {
private: private:
OpPrimCRegister() {} OpPrimCRegister() {}
std::map<std::string, OpPrimCDefineFunc> op_primc_fns_; HashMap<std::string, OpPrimCDefineFunc> op_primc_fns_;
}; };
/// \brief OpPrimCRegisterHelper defines the helper class for the OpPrimCRegister singleton. /// \brief OpPrimCRegisterHelper defines the helper class for the OpPrimCRegister singleton.