1 | /* Copyright 2022 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_LITE_TENSORFLOW_PROFILER_LOGGER_H_ |
17 | #define TENSORFLOW_LITE_TENSORFLOW_PROFILER_LOGGER_H_ |
18 | |
19 | #include <cstdint> |
20 | #include <string> |
21 | |
22 | #include "tensorflow/lite/core/macros.h" |
23 | |
24 | struct TfLiteTensor; |
25 | |
26 | namespace tensorflow { |
27 | namespace profiler { |
28 | class TraceMe; |
29 | } // namespace profiler |
30 | } // namespace tensorflow |
31 | |
32 | namespace tflite { |
33 | // Records an op preparation with `op_name` and `node_index`. |
34 | TFLITE_ATTRIBUTE_WEAK void OnTfLiteOpPrepare(const char* op_name, |
35 | int subgraph_index, |
36 | int node_index); |
37 | |
38 | // Returns a `TraceMe` pointer to record a subgraph invocation with |
39 | // `subgraph_name` and `subgraph_index`. |
40 | TFLITE_ATTRIBUTE_WEAK tensorflow::profiler::TraceMe* OnTfLiteSubgraphInvoke( |
41 | const char* subgraph_name, int subgraph_index); |
42 | |
43 | // Records an end of the subgraph invocation with the given `TraceMe` pointer. |
44 | TFLITE_ATTRIBUTE_WEAK void OnTfLiteSubgraphInvokeEnd( |
45 | tensorflow::profiler::TraceMe* trace_me); |
46 | |
47 | // Returns a `TraceMe` pointer to record an op invocation with `op_name` and |
48 | // `node_index`. |
49 | TFLITE_ATTRIBUTE_WEAK tensorflow::profiler::TraceMe* OnTfLiteOpInvoke( |
50 | const char* op_name, int subgraph_index, int node_index); |
51 | |
52 | // Records an end of the op invocation with the given `TraceMe` pointer. |
53 | TFLITE_ATTRIBUTE_WEAK void OnTfLiteOpInvokeEnd( |
54 | tensorflow::profiler::TraceMe* trace_me); |
55 | |
56 | // Records an event of `num_bytes` of memory allocated for `tensor`. |
57 | TFLITE_ATTRIBUTE_WEAK void OnTfLiteTensorAlloc(TfLiteTensor* tensor, |
58 | size_t num_bytes); |
59 | |
60 | // Records an event of memory deallocated for `tensor`. |
61 | TFLITE_ATTRIBUTE_WEAK void OnTfLiteTensorDealloc(TfLiteTensor* tensor); |
62 | |
63 | // Records an event of `num_bytes` of memory allocated for arena. |
64 | TFLITE_ATTRIBUTE_WEAK void OnTfLiteArenaAlloc(int subgraph_index, int arena_id, |
65 | size_t num_bytes); |
66 | |
67 | // Records an event of `num_bytes` of memory deallocated for arena. |
68 | TFLITE_ATTRIBUTE_WEAK void OnTfLiteArenaDealloc(int subgraph_index, |
69 | int arena_id, size_t num_bytes); |
70 | |
71 | } // namespace tflite |
72 | |
73 | #endif // TENSORFLOW_LITE_TENSORFLOW_PROFILER_LOGGER_H_ |
74 | |