• 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 #ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_CONNECTOR_SIZE_H
17 #define MINDSPORE_CCSRC_MINDDATA_DATASET_CONNECTOR_SIZE_H
18 
19 #include <string>
20 #include <vector>
21 #include <nlohmann/json.hpp>
22 #include "minddata/dataset/engine/perf/profiling.h"
23 #include "minddata/dataset/engine/datasetops/dataset_op.h"
24 
25 using json = nlohmann::json;
26 
27 namespace mindspore {
28 namespace dataset {
29 class ExecutionTree;
30 
31 // Connector size sampling samples the output connector size of each op in the pipeline.
32 // It support JSON serialization for external usage.
33 class ConnectorSize : public Sampling {
34   // Connector size sampling data is stored as a 2D vector
35   //            op_0            ...         op_m
36   // sample_0   size_0_0        ...         size_m_0
37   // ...        ...             ...         ...
38   // sample_n   size_0_m        ...         size_m_n
39   //
40   // A circular buffer will be implemented in the future to make this table more flexible.
41   using ConnectorSizeSample = std::vector<int>;
42   using ConnectorSizeSampleTable = std::vector<ConnectorSizeSample>;
43 
44  public:
ConnectorSize(ExecutionTree * tree)45   explicit ConnectorSize(ExecutionTree *tree) : tree_(tree) {}
46 
47   ~ConnectorSize() override = default;
48 
49   // Driver function for connector size sampling.
50   // This function samples the connector size of every nodes within the ExecutionTree
51   Status Sample() override;
52 
Name()53   std::string Name() const override { return kConnectorSizeSamplingName; }
54 
55   // Save sampling data to file
56   // @return Status The status code returned
57   Status SaveToFile() override;
58 
59   Status Init(const std::string &dir_path, const std::string &device_id) override;
60 
61   // Parse op information and transform to json format
62   json ParseOpInfo(const DatasetOp &node, const std::vector<int32_t> &size);
63 
64   // Change file mode after save throughput data
ChangeFileMode()65   Status ChangeFileMode() { return Status::OK(); }
66 
67   Status Analyze() override;
68 
69  private:
70   ExecutionTree *tree_ = nullptr;          // ExecutionTree pointer
71   ConnectorSizeSampleTable sample_table_;  // Dataset structure to store all samples of connector size sampling
72 };
73 
74 }  // namespace dataset
75 }  // namespace mindspore
76 
77 #endif  // MINDSPORE_CCSRC_MINDDATA_DATASET_CONNECTOR_SIZE_H
78