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_EXPERIMENTAL_TELEMETRY_TELEMETRY_STATUS_H_ 17 #define TENSORFLOW_LITE_EXPERIMENTAL_TELEMETRY_TELEMETRY_STATUS_H_ 18 19 #include <cstdint> 20 21 #include "tensorflow/lite/c/c_api_types.h" 22 23 namespace tflite { 24 25 // The source of a telemetry event. 26 enum class TelemetrySource : uint32_t { 27 TFLITE_INTERPRETER = 0, 28 29 // For external delegate. 30 // External delegate should identify themselves in telemetry event names by 31 // prefixing the delegame name to it. 32 TFLITE_CUSTOM_DELEGATE = 1, 33 34 TFLITE_GPU = 2, 35 TFLITE_NNAPI = 3, 36 TFLITE_HEXAGON = 4, 37 TFLITE_XNNPACK = 5, 38 TFLITE_COREML = 6, 39 }; 40 41 // A namespaced status code for telemetry events. 42 struct TelemetryStatusCode { 43 TelemetrySource source = TelemetrySource::TFLITE_INTERPRETER; 44 uint32_t status_code = 0; 45 46 // Helper constructors to build the status code from various types. 47 TelemetryStatusCode() = default; TelemetryStatusCodeTelemetryStatusCode48 TelemetryStatusCode(TelemetrySource source, uint32_t status_code) 49 : source(source), status_code(status_code) {} TelemetryStatusCodeTelemetryStatusCode50 explicit TelemetryStatusCode(TfLiteStatus status) 51 : TelemetryStatusCode(TelemetrySource::TFLITE_INTERPRETER, status) {} TelemetryStatusCodeTelemetryStatusCode52 explicit TelemetryStatusCode(uint64_t code) 53 : TelemetryStatusCode(static_cast<TelemetrySource>(code >> 32), 54 static_cast<uint32_t>(code)) {} 55 56 // Returns the uint64_t representation of the status code. codeTelemetryStatusCode57 uint64_t code() const { 58 return (static_cast<uint64_t>(source) << 32 | status_code); 59 } 60 }; 61 62 } // namespace tflite 63 64 #endif // TENSORFLOW_LITE_EXPERIMENTAL_TELEMETRY_TELEMETRY_STATUS_H_ 65