1 /**
2 * Copyright 2021 Huawei Technologies Co., Ltd
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "runtime/graph_scheduler/actor/actor_set.h"
18
19 namespace mindspore {
20 namespace runtime {
21 std::unordered_map<std::string, AbstractActor *> kActorNameToActor;
22
23 // The operation of the map of kActorNameToActor.
InsertActor(AbstractActor * actor)24 void InsertActor(AbstractActor *actor) {
25 MS_EXCEPTION_IF_NULL(actor);
26 if (kActorNameToActor.count(actor->GetAID().Name()) > 0) {
27 MS_LOG(EXCEPTION) << "The actor already exists: " << actor->GetAID().Name();
28 }
29 kActorNameToActor[actor->GetAID().Name()] = actor;
30 }
31
FetchActor(const std::string & actor_name)32 AbstractActor *FetchActor(const std::string &actor_name) {
33 const auto &iter = kActorNameToActor.find(actor_name);
34 if (iter == kActorNameToActor.end()) {
35 return nullptr;
36 }
37 return iter->second;
38 }
39
FetchActor(KernelTransformType kernel_type,const std::string & actor_set_name,const AnfNodePtr & node,const KernelGraphPtr & graph)40 AbstractActor *FetchActor(KernelTransformType kernel_type, const std::string &actor_set_name, const AnfNodePtr &node,
41 const KernelGraphPtr &graph) {
42 std::string actor_name = FetchActorName(kernel_type, actor_set_name, node, graph);
43 return FetchActor(actor_name);
44 }
45
EraseActor(const std::string & actor_name)46 void EraseActor(const std::string &actor_name) { (void)kActorNameToActor.erase(actor_name); }
47
ClearAllActors()48 void ClearAllActors() { kActorNameToActor.clear(); }
49 } // namespace runtime
50 } // namespace mindspore
51