• 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 #include "runtime/device/ascend/profiling/reporter/profiling_desc.h"
18 #include <iterator>
19 #include <sstream>
20 
21 namespace mindspore {
22 namespace device {
23 namespace ascend {
ToString()24 std::string TaskDesc::ToString() {
25   std::string out = op_name_;
26   out.append(" ")
27     .append(std::to_string(block_dim_))
28     .append(" ")
29     .append(std::to_string(task_id_))
30     .append(" ")
31     .append(std::to_string(stream_id_))
32     .append("\n");
33   return out;
34 }
35 
ToString()36 std::string GraphDesc::ToString() {
37   std::string desc;
38   desc.append("op_name:").append(op_name_).append(" op_type:").append(op_type_);
39   int input_id = 0;
40   for (const auto &element : input_data_list_) {
41     desc.append(" input_id:")
42       .append(std::to_string(input_id++))
43       .append(" input_format:")
44       .append(element.data_format_)
45       .append(" input_data_type:")
46       .append(std::to_string(element.data_type_))
47       .append(" input_shape:")
48       .append(DataShapeToString(element.data_shape_));
49   }
50 
51   input_id = 0;
52   for (const auto &element : output_data_list_) {
53     desc.append(" output_id:")
54       .append(std::to_string(input_id++))
55       .append(" output_format:")
56       .append(element.data_format_)
57       .append(" output_data_type:")
58       .append(std::to_string(element.data_type_))
59       .append(" output_shape:")
60       .append((DataShapeToString(element.data_shape_)));
61   }
62 
63   desc.append("\n");
64 
65   return desc;
66 }
67 
ToString()68 std::string PointDesc::ToString() {
69   std::string desc;
70   desc.append(std::to_string(point_id_)).append(" ").append(op_name_).append("\n");
71   return desc;
72 }
73 
DataShapeToString(const std::vector<size_t> & shape)74 std::string GraphDesc::DataShapeToString(const std::vector<size_t> &shape) {
75   std::ostringstream oss;
76   oss << "\"";
77   if (!shape.empty()) {
78     std::copy(shape.begin(), shape.end() - 1, std::ostream_iterator<size_t>(oss, ","));
79     oss << shape.back();
80   }
81   oss << "\"";
82   return oss.str();
83 }
84 
ToString()85 std::string TaskStreamOpNameDesc::ToString() {
86   std::string desc = op_name_;
87   // op_name "task_id stream_id" "task_id stream_id"
88   for (auto pair : stream_id_task_id_pairs_) {
89     desc.append(" ");
90     desc.append(std::to_string(pair.first));
91     desc.append("_");
92     desc.append(std::to_string(pair.second));
93   }
94   desc.append("\n");
95   return desc;
96 }
97 }  // namespace ascend
98 }  // namespace device
99 }  // namespace mindspore
100