• 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 #include "runtime/framework/actor/abstract_actor.h"
18 #include "utils/log_adapter.h"
19 
20 namespace mindspore {
21 namespace runtime {
CheckRunningCondition(const OpContext<DeviceTensor> * context) const22 bool AbstractActor::CheckRunningCondition(const OpContext<DeviceTensor> *context) const {
23   MS_EXCEPTION_IF_NULL(context);
24   if (input_datas_num_ != 0) {
25     const auto &data_iter = input_op_datas_.find(context->sequential_num_);
26     if (data_iter == input_op_datas_.end()) {
27       return false;
28     }
29     if (data_iter->second.size() != input_datas_num_) {
30       return false;
31     }
32   }
33 
34   if (input_controls_num_ != 0) {
35     const auto &control_iter = input_op_controls_.find(context->sequential_num_);
36     if (control_iter == input_op_controls_.end()) {
37       return false;
38     }
39     if (control_iter->second.size() != input_controls_num_) {
40       return false;
41     }
42   }
43   return true;
44 }
45 
EraseInput(const OpContext<DeviceTensor> * context)46 void AbstractActor::EraseInput(const OpContext<DeviceTensor> *context) {
47   MS_EXCEPTION_IF_NULL(context);
48   if (input_datas_num_ != 0) {
49     auto ret = input_op_datas_.erase(context->sequential_num_);
50     if (ret == 0) {
51       std::string error_info = "Erase input data failed: " + GetAID().Name();
52       // The sequential num may be invalid, can't set the promise value of context.
53       MS_LOG(ERROR) << error_info << ", sequential_num: " << context->sequential_num_;
54       return;
55     }
56   }
57 
58   if (input_controls_num_ != 0) {
59     auto ret = input_op_controls_.erase(context->sequential_num_);
60     if (ret == 0) {
61       std::string error_info = "Erase input controls failed: " + GetAID().Name();
62       // The sequential num may be invalid, can't set the promise value of context.
63       MS_LOG(ERROR) << error_info << ", sequential_num: " << context->sequential_num_;
64       return;
65     }
66   }
67 }
68 }  // namespace runtime
69 }  // namespace mindspore
70