• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2016 The TensorFlow Authors All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7     http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 
16 #include "tensorflow/core/profiler/internal/tfprof_tensor.h"
17 
18 namespace tensorflow {
19 namespace tfprof {
Display(string * formatted_str,TFProfTensorProto * tfprof_tensor_pb)20 void TFProfTensor::Display(string* formatted_str,
21                            TFProfTensorProto* tfprof_tensor_pb) {
22   if (formatted_str) {
23     if (formatted_str_.length() >= kTFProfTenosrMaxDisplayLen) {
24       *formatted_str =
25           strings::StrCat(formatted_str_, "...omitted from display\n\n");
26     } else {
27       *formatted_str = formatted_str_;
28     }
29   }
30   if (tfprof_tensor_pb) {
31     tfprof_tensor_pb->MergeFrom(tfprof_tensor_pb_);
32   }
33 }
34 
Build()35 void TFProfTensor::Build() {
36   tfprof_tensor_pb_.set_dtype(tensor_->dtype());
37 
38   switch (tensor_->dtype()) {
39     // Double for all floats.
40     case DataType::DT_FLOAT:
41     case DataType::DT_DOUBLE: {
42       std::vector<double> values_vec;
43       if (tensor_->dtype() == DataType::DT_FLOAT) {
44         GetValueVec<float, double>(&values_vec);
45       } else if (tensor_->dtype() == DataType::DT_DOUBLE) {
46         GetValueVec<double, double>(&values_vec);
47       }
48       BuildOutput<double>(0, 0, values_vec, &tfprof_tensor_pb_);
49       break;
50     }
51     // Int64 for all integers.
52     case DataType::DT_INT32:
53     case DataType::DT_INT64: {
54       std::vector<int64> values_vec;
55       if (tensor_->dtype() == DataType::DT_INT32) {
56         GetValueVec<int32, int64>(&values_vec);
57       } else if (tensor_->dtype() == DataType::DT_INT64) {
58         GetValueVec<int64, int64>(&values_vec);
59       }
60       BuildOutput<int64>(0, 0, values_vec, &tfprof_tensor_pb_);
61       break;
62     }
63     case DataType::DT_STRING: {
64       // Not supported by TensorFlow.
65       std::vector<string> values_vec;
66       GetValueVec<string, string>(&values_vec);
67       BuildOutput<string>(0, 0, values_vec, &tfprof_tensor_pb_);
68       break;
69     }
70     default: {
71       fprintf(stderr, "Not Supported type %d\n", tensor_->dtype());
72       break;
73     }
74   }
75 }
76 
77 }  // namespace tfprof
78 }  // namespace tensorflow
79