• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2020 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_DEVICE_ASCEND_DUMP_DATADUMP_H_
18 #define MINDSPORE_CCSRC_RUNTIME_DEVICE_ASCEND_DUMP_DATADUMP_H_
19 #include <tuple>
20 #include <map>
21 #include <set>
22 #include <memory>
23 #include <string>
24 #include <vector>
25 #include <functional>
26 #include "backend/session/kernel_graph.h"
27 
28 namespace aicpu {
29 namespace dump {
30 class OpMappingInfo;
31 class Task;
32 }  // namespace dump
33 }  // namespace aicpu
34 namespace mindspore {
35 namespace device {
36 namespace ascend {
37 // tuple(op_name, task_id, stream_id, args)
38 using RuntimeInfo = std::tuple<uint32_t, uint32_t, void *>;
39 class DataDumper {
40  public:
DataDumper(const session::KernelGraph * kernel_graph,NotNull<std::function<void * ()>> model_handle)41   DataDumper(const session::KernelGraph *kernel_graph, NotNull<std::function<void *()>> model_handle)
42       : model_handle_(model_handle),
43         debug_task_id_(-1),
44         debug_stream_id_(-1),
45         op_debug_buffer_addr_(nullptr),
46         op_debug_dump_args_(nullptr),
47         load_flag_(false),
48         dev_load_mem_(nullptr),
49         dev_unload_mem_(nullptr),
50         graph_id_(UINT32_MAX),
51         kernel_graph_(kernel_graph) {}
52   ~DataDumper();
set_runtime_info(const std::map<std::string,std::shared_ptr<RuntimeInfo>> & runtime_info)53   void set_runtime_info(const std::map<std::string, std::shared_ptr<RuntimeInfo>> &runtime_info) {
54     runtime_info_map_ = runtime_info;
55   }
56 #ifndef ENABLE_SECURITY
57   void LoadDumpInfo();
58   void OpDebugRegister();
59   void OpDebugUnregister();
60 #endif
61   void UnloadDumpInfo();
62 
63  private:
64   void ReleaseDevMem(void **ptr) const noexcept;
65 #ifndef ENABLE_SECURITY
66   bool KernelNeedDump(const CNodePtr &kernel) const;
67   void SetOpMappingInfo(NotNull<aicpu::dump::OpMappingInfo *> dump_info) const;
68 #endif
69   void SetOpDebugMappingInfo(const NotNull<aicpu::dump::OpMappingInfo *> dump_info) const;
70   void ConstructDumpTask(NotNull<const CNodePtr &> kernel, NotNull<aicpu::dump::Task *> dump_task) const;
71 #ifndef ENABLE_SECURITY
72   void GetNeedDumpKernelList(NotNull<std::map<std::string, CNodePtr> *> kernel_map) const;
73   static void DumpKernelOutput(const CNodePtr &kernel, void *args, NotNull<aicpu::dump::Task *> task);
74   static void DumpKernelInput(const CNodePtr &kernel, void *args, NotNull<aicpu::dump::Task *> task);
75 #endif
76   static std::string StripUniqueId(const std::string node_name);
77   static void RtLoadDumpData(const aicpu::dump::OpMappingInfo &dump_info, void **ptr);
78 
79   std::function<void *()> model_handle_;
80   uint32_t debug_task_id_;
81   uint32_t debug_stream_id_;
82   void *op_debug_buffer_addr_;
83   void *op_debug_dump_args_;
84   bool load_flag_;
85   void *dev_load_mem_;
86   void *dev_unload_mem_;
87   uint32_t graph_id_;
88   std::vector<std::string> dump_kernel_names_;
89   const session::KernelGraph *kernel_graph_;
90   std::map<std::string, std::shared_ptr<RuntimeInfo>> runtime_info_map_;
91 };
92 }  // namespace ascend
93 }  // namespace device
94 }  // namespace mindspore
95 #endif  // MINDSPORE_CCSRC_RUNTIME_DEVICE_ASCEND_DUMP_DATADUMP_H_
96