• 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_CORE_IR_PRIMAL_DEBUG_INFO_H
18 #define MINDSPORE_CORE_IR_PRIMAL_DEBUG_INFO_H
19 #include <string>
20 #include <memory>
21 #include <stack>
22 #include <vector>
23 #include <unordered_map>
24 #include "utils/info.h"
25 
26 namespace mindspore {
27 class PrimalDebugInfoManager {
28  public:
GetInstance()29   static PrimalDebugInfoManager &GetInstance() noexcept {
30     static PrimalDebugInfoManager instance;
31     return instance;
32   }
33   PrimalDebugInfoManager(const PrimalDebugInfoManager &) = delete;
34   PrimalDebugInfoManager &operator=(const PrimalDebugInfoManager &) = delete;
35   ~PrimalDebugInfoManager() = default;
SetPrimalDebugInfo(const std::vector<NodeDebugInfoPtr> & primal_debug_infos)36   void SetPrimalDebugInfo(const std::vector<NodeDebugInfoPtr> &primal_debug_infos) {
37     primal_debug_infos_ = primal_debug_infos;
38   }
ClearPrimalDebugInfo()39   void ClearPrimalDebugInfo() { primal_debug_infos_.clear(); }
GetCurrentPrimalDebugInfo()40   std::vector<NodeDebugInfoPtr> GetCurrentPrimalDebugInfo() { return primal_debug_infos_; }
41 
42  private:
43   PrimalDebugInfoManager() = default;
44   std::vector<NodeDebugInfoPtr> primal_debug_infos_;
45 };
46 
47 // PrimalDebugInfoGuard is a class that help generate the back propagation cnode
48 // with specified primal_debug_infos in the current c++ action scope.
49 class PrimalDebugInfoGuard {
50  public:
PrimalDebugInfoGuard(const std::vector<NodeDebugInfoPtr> & primal_debug_infos)51   explicit PrimalDebugInfoGuard(const std::vector<NodeDebugInfoPtr> &primal_debug_infos) {
52     PrimalDebugInfoManager::GetInstance().SetPrimalDebugInfo(primal_debug_infos);
53   }
~PrimalDebugInfoGuard()54   ~PrimalDebugInfoGuard() { PrimalDebugInfoManager::GetInstance().ClearPrimalDebugInfo(); }
55 };
56 }  // namespace mindspore
57 #endif  // MINDSPORE_CORE_IR_PRIMAL_DEBUG_INFO_H
58