• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2020-2022 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   using Timestamps = std::vector<uint64_t>;
44 
45  public:
ConnectorSize(ExecutionTree * tree)46   explicit ConnectorSize(ExecutionTree *tree) : tree_(tree) {}
47 
48   ~ConnectorSize() override = default;
49 
50   // Driver function for connector size sampling.
51   // This function samples the connector size of every nodes within the ExecutionTree
52   Status Sample() override;
53 
Name()54   std::string Name() const override { return kConnectorSizeSamplingName; }
55 
56   // Save sampling data to file
57   // @return Status The status code returned
58   Status SaveToFile(const std::string &dir_path, const std::string &rank_id) override;
59 
60   Status Init() override;
61 
62   // Parse op information and transform to json format
63   json ParseOpInfo(const DatasetOp &node) const;
64 
65   // Change file mode after save throughput data
ChangeFileMode(const std::string & dir_path,const std::string & rank_id)66   Status ChangeFileMode(const std::string &dir_path, const std::string &rank_id) override { return Status::OK(); }
67 
68   // Get the vector of connector sizes of given op for samples taken between start and end time
69   Status GetOpConnectorSize(int32_t op_id, uint64_t start_time, uint64_t end_time, std::vector<int32_t> *result);
70 
71   // Clear all collected data
72   void Clear() override;
73 
74  protected:
75   Path GetFileName(const std::string &dir_path, const std::string &rank_id) override;
76 
77  private:
78   json initial_nodes_data;  // store data when execution tree is running. (all information for ops except sampled data)
79   ExecutionTree *tree_ = nullptr;          // ExecutionTree pointer
80   ConnectorSizeSampleTable sample_table_;  // Dataset structure to store all samples of connector size sampling
81   Timestamps ts_;                          // time of sample
82 };
83 
84 }  // namespace dataset
85 }  // namespace mindspore
86 
87 #endif  // MINDSPORE_CCSRC_MINDDATA_DATASET_CONNECTOR_SIZE_H
88