1 /** 2 * Copyright 2019 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_CORE_EFFECT_INFO_H_ 18 #define MINDSPORE_CORE_EFFECT_INFO_H_ 19 20 namespace mindspore { 21 22 struct EffectInfo { 23 enum State : unsigned char { 24 kUnknown = 0, 25 kDetecting = 1, 26 kDetected = 2, 27 }; 28 State state = kUnknown; // effect info state. 29 bool memory = false; // memory side effects, e.g., access global variable. 30 bool io = false; // IO side effects, e.g., print message. 31 bool load = false; // load value from global variable, e.g. add(self.para, x). 32 MergeEffectInfo33 void Merge(const EffectInfo &info) { 34 if (info.state != EffectInfo::kDetected) { 35 state = EffectInfo::kDetecting; 36 } 37 memory = memory || info.memory; 38 io = io || info.io; 39 load = load || info.load; 40 } 41 }; 42 43 // EffectInfoHolder as base class for effect info holders, such as CNode, FuncGraph, etc. 44 class EffectInfoHolder { 45 public: 46 // Gets effect info. GetEffectInfo()47 const EffectInfo &GetEffectInfo() const { return effect_info_; } 48 49 // Set effect info. SetEffectInfo(const EffectInfo & info)50 void SetEffectInfo(const EffectInfo &info) { effect_info_ = info; } 51 52 // Unset effect info. UnsetEffectInfo()53 void UnsetEffectInfo() { effect_info_ = {EffectInfo::kUnknown, false, false}; } 54 55 protected: 56 EffectInfo effect_info_; 57 }; 58 59 } // namespace mindspore 60 61 #endif // MINDSPORE_CORE_EFFECT_INFO_H_ 62