• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef MINDSPORE_CCSRC_RUNTIME_FRAMEWORK_ACTOR_CONTROLFLOW_SWITCH_ACTOR_H_
18 #define MINDSPORE_CCSRC_RUNTIME_FRAMEWORK_ACTOR_CONTROLFLOW_SWITCH_ACTOR_H_
19 
20 #include <vector>
21 #include <string>
22 #include <memory>
23 #include <utility>
24 #include "runtime/graph_scheduler/actor/actor_common.h"
25 #include "runtime/graph_scheduler/actor/control_flow/control_actor.h"
26 
27 namespace mindspore {
28 namespace runtime {
29 using mindspore::device::DeviceContext;
30 using mindspore::session::KernelWithIndex;
31 
32 // Switch actor is used to execute the branch according to the input condition.
33 // Switch and SwitchLayer node will be converted to switch actor.
34 class SwitchActor : public ControlActor {
35  public:
36   SwitchActor(const std::string &name, const AID &memory_manager_aid, const std::vector<KernelWithIndex> &parameters,
37               const AnfNodePtr &node);
38   ~SwitchActor() override = default;
39 
40  protected:
41   void FetchInput(OpContext<DeviceTensor> *const context) override;
42 
43  private:
44   friend class ControlNodeScheduler;
45   // Get the output branch index of the switch actor.
46   size_t GetIndex(const OpContext<DeviceTensor> *const context) const;
47   size_t index_{0};
48 };
49 
50 using SwitchActorPtr = std::shared_ptr<SwitchActor>;
51 }  // namespace runtime
52 }  // namespace mindspore
53 
54 #endif  // MINDSPORE_CCSRC_RUNTIME_FRAMEWORK_ACTOR_CONTROLFLOW_SWITCH_ACTOR_H_
55