• 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 #ifndef MINDSPORE_CCSRC_DEBUG_RDR_MEM_ADDRESS_RECORDER_H_
17 #define MINDSPORE_CCSRC_DEBUG_RDR_MEM_ADDRESS_RECORDER_H_
18 #include <vector>
19 #include <string>
20 #include <map>
21 #include <set>
22 #include <memory>
23 #include <mutex>
24 
25 #include "debug/rdr/base_recorder.h"
26 
27 namespace mindspore {
28 namespace kernel {
29 class Address;
30 struct KernelLaunchInfo;
31 using AddressPtr = std::shared_ptr<Address>;
32 }  // namespace kernel
33 using AddressPtrList = std::vector<kernel::AddressPtr>;
34 struct MemInfo {
35   AddressPtrList *inputs_;
36   AddressPtrList *workspaces_;
37   AddressPtrList *outputs_;
38 };
39 class MemAddressRecorder : public BaseRecorder {
40  public:
MemAddressRecorder()41   MemAddressRecorder() {}
MemAddressRecorder(const std::string & module,const std::string & name)42   MemAddressRecorder(const std::string &module, const std::string &name) : BaseRecorder(module, name) {}
~MemAddressRecorder()43   ~MemAddressRecorder() {}
44 
45   virtual void Export();
46   void SaveMemInfo(const std::string &op_name, const kernel::KernelLaunchInfo &mem_info);
47 
Reset()48   void Reset() {
49     op_names_.clear();
50     mem_info_stream_.str("");
51   }
52   void CleanUp();
53 
54  private:
55   mutable std::mutex mtx_;
56   bool printed_{false};
57 
58   std::set<std::string> op_names_;
59   std::ostringstream mem_info_stream_;
60 };
61 using MemAddressRecorderPtr = std::shared_ptr<MemAddressRecorder>;
62 }  // namespace mindspore
63 #endif  // MINDSPORE_CCSRC_DEBUG_RDR_MEM_ADDRESS_RECORDER_H_
64