!42656 change GetPrimCMap to return a const-reference hash map
Merge pull request !42656 from DeshiChen/0922_prim_map
This commit is contained in:
commit
903101638c
|
@ -338,7 +338,7 @@ void GkUtils::UpdateFuncGraphManager(const FuncGraphManagerPtr &mng, const FuncG
|
|||
}
|
||||
|
||||
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);
|
||||
if (iter == op_primc_fns.end()) {
|
||||
return nullptr;
|
||||
|
|
|
@ -106,7 +106,7 @@ void PrimOp::SetAbastractsFromAttrs(const PrimitivePtr &primitive, const mindspo
|
|||
|
||||
std::pair<PrimitivePtr, AbstractBasePtrList> PrimOp::GenPrimAndAbstract(const NodePtrList &inputs,
|
||||
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_);
|
||||
if (iter == op_primc_fns.end()) {
|
||||
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;
|
||||
}
|
||||
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_);
|
||||
if (iter == op_primc_fns.end()) {
|
||||
return nullptr;
|
||||
|
|
|
@ -38,7 +38,7 @@ OpPrimCRegister &OpPrimCRegister::GetInstance() {
|
|||
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; }
|
||||
} // namespace ops
|
||||
} // namespace mindspore
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include <memory>
|
||||
#include "ir/primitive.h"
|
||||
#include "ir/value.h"
|
||||
#include "utils/hash_map.h"
|
||||
namespace mindspore {
|
||||
namespace ops {
|
||||
/// \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.
|
||||
///
|
||||
/// \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.
|
||||
///
|
||||
|
@ -71,7 +72,7 @@ class MS_CORE_API OpPrimCRegister {
|
|||
|
||||
private:
|
||||
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.
|
||||
|
|
Loading…
Reference in New Issue