• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2024 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_DEBUG_TENSOR_STATISTIC_H_
18 #define MINDSPORE_CCSRC_DEBUG_TENSOR_STATISTIC_H_
19 
20 #include <map>
21 #include <memory>
22 #include <set>
23 #include <string>
24 #include <vector>
25 #include "debug/debug_services.h"
26 #include "runtime/hardware/device_context.h"
27 #include "utils/log_adapter.h"
28 
29 namespace mindspore {
30 
31 namespace datadump {
32 using device::DeviceAddressPtr;
33 using kernel::KernelTensor;
34 using kernel::KernelTensorPtr;
35 using mindspore::device::DeviceContext;
36 using TensorPtr = tensor::TensorPtr;
37 
38 class TensorStat {
39  public:
TensorStat(const string & type,const string & name,size_t task_id,size_t stream_id,uint64_t timestamp,const string & io,size_t slot,size_t data_size,const string & data_type,const string & shape,const string & max_value,const string & min_value,const string & avg_value,const string & norm_value,size_t count)40   TensorStat(const string &type, const string &name, size_t task_id, size_t stream_id, uint64_t timestamp,
41              const string &io, size_t slot, size_t data_size, const string &data_type, const string &shape,
42              const string &max_value, const string &min_value, const string &avg_value, const string &norm_value,
43              size_t count)
44       : type_(type),
45         name_(name),
46         task_id_(task_id),
47         stream_id_(stream_id),
48         timestamp_(timestamp),
49         io_(io),
50         slot_(slot),
51         data_size_(data_size),
52         data_type_(data_type),
53         shape_(shape),
54         max_value_(max_value),
55         min_value_(min_value),
56         avg_value_(avg_value),
57         norm_value_(norm_value),
58         count_(count) {}
59   TensorStat() = default;
60   std::map<std::string, std::string> header_item_map;
UpdateHeaderItemMap()61   void UpdateHeaderItemMap() {
62     header_item_map = {{"max", max_value_}, {"min", min_value_}, {"avg", avg_value_}, {"l2norm", norm_value_}};
63   }
64 
65  public:
66   string type_;
67   string name_;
68   size_t task_id_;
69   size_t stream_id_;
70   uint64_t timestamp_;
71   string io_;
72   size_t slot_;
73   size_t data_size_;
74   string data_type_;
75   string shape_;
76   string max_value_;
77   string min_value_;
78   string avg_value_;
79   string norm_value_;
80   size_t count_;
81 };
82 
83 class DumpTensorInfo {
84  public:
DumpTensorInfo(const DeviceContext * dc,KernelTensor * t,bool in,size_t s,const string & name,const string & type)85   DumpTensorInfo(const DeviceContext *dc, KernelTensor *t, bool in, size_t s, const string &name, const string &type)
86       : device_context(dc), tensor(t), is_input(in), slot(s), op_name(name), op_type(type) {}
87   const DeviceContext *device_context;
88   KernelTensor *tensor;
89   bool is_input;
90   size_t slot;
91   string op_name;
92   string op_type;
93 };
94 
95 TensorStat GetKernelTensorStats(const DumpTensorInfo &, const std::set<std::string> &stat_name_list);
96 void DumpKernelTensorStats(const DeviceContext *device_context, vector<device::DeviceAddress *> tensors, bool is_input,
97                            const CNodePtr &node, uint32_t graph_id);
98 
99 }  // namespace datadump
100 
101 }  // namespace mindspore
102 
103 #endif  // MINDSPORE_CCSRC_DEBUG_TENSOR_STATISTIC_H_
104