1 | /* Copyright 2015 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 | #ifndef TENSORFLOW_CORE_UTIL_UTIL_H_ |
17 | #define TENSORFLOW_CORE_UTIL_UTIL_H_ |
18 | |
19 | #include "tensorflow/core/framework/tensor_shape.h" |
20 | #include "tensorflow/core/lib/core/stringpiece.h" |
21 | |
22 | namespace tensorflow { |
23 | |
24 | // If op_name has '/' in it, then return everything before the first '/'. |
25 | // Otherwise return empty string. |
26 | StringPiece NodeNamePrefix(const StringPiece& op_name); |
27 | |
28 | // If op_name has '/' in it, then return everything before the last '/'. |
29 | // Otherwise return empty string. |
30 | StringPiece NodeNameFullPrefix(const StringPiece& op_name); |
31 | |
32 | class MovingAverage { |
33 | public: |
34 | explicit MovingAverage(int window); |
35 | ~MovingAverage(); |
36 | |
37 | void Clear(); |
38 | |
39 | double GetAverage() const; |
40 | void AddValue(double v); |
41 | |
42 | private: |
43 | const int window_; // Max size of interval |
44 | double sum_; // Sum over interval |
45 | double* data_; // Actual data values |
46 | int head_; // Offset of the newest statistic in data_ |
47 | int count_; // # of valid data elements in window |
48 | }; |
49 | |
50 | // Returns a string printing bytes in ptr[0..n). The output looks |
51 | // like "00 01 ef cd cd ef". |
52 | std::string PrintMemory(const char* ptr, size_t n); |
53 | |
54 | // Given a flattened index into a tensor, computes a string s so that |
55 | // StrAppend("tensor", s) is a Python indexing expression. E.g., |
56 | // "tensor", "tensor[i]", "tensor[i, j]", etc. |
57 | std::string SliceDebugString(const TensorShape& shape, const int64_t flat); |
58 | |
59 | // Check if MKL is enabled in runtime |
60 | bool IsMKLEnabled(); |
61 | |
62 | } // namespace tensorflow |
63 | |
64 | #endif // TENSORFLOW_CORE_UTIL_UTIL_H_ |
65 | |