1 /* 2 * Copyright (C) 2020 The Android Open Source Project 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 #ifndef ANDROID_PACKAGES_MODULES_NEURALNETWORKS_RUNTIME_TELEMETRY_H 18 #define ANDROID_PACKAGES_MODULES_NEURALNETWORKS_RUNTIME_TELEMETRY_H 19 20 #include <string> 21 22 #include "CompilationBuilder.h" 23 #include "ExecutionBuilder.h" 24 25 namespace android::nn::telemetry { 26 27 // Generate telemetry event on successful compilation 28 void onCompilationFinish(CompilationBuilder* c, int resultCode); 29 30 // Generate telemetry event on successful execution 31 void onExecutionFinish(ExecutionBuilder* e, ExecutionMode executionMode, int resultCode); 32 33 // Data class of inputs and outputs 34 enum class DataClass { 35 UNKNOWN = 0, 36 OTHER = 1, 37 FLOAT32 = 2, 38 FLOAT16 = 3, 39 QUANT = 4, 40 MIXED = 5, 41 }; 42 43 // Infer data class of operand set 44 DataClass evalDataClass(const OperandType& op, DataClass previousDataClass); 45 46 // Get the ID that identifies a single session of client interacting with NNAPI runtime. 47 int32_t getSessionId(); 48 49 struct DiagnosticCompilationInfo { 50 // The hash of the model architecture (without weights). 51 const uint8_t* modelArchHash; 52 // The device IDs as a comma-concatenated string. 53 const std::string deviceId; 54 // The error code during compilation. 55 int32_t errorCode; 56 // Data class of the input to the model. 57 DataClass inputDataClass; 58 // Data class of the output from the model. 59 DataClass outputDataClass; 60 // Duration of the compilation in the runtime. 61 // UINT64_MAX indicates no timing information is available. 62 uint64_t compilationTimeNanos; 63 // Did the compilation fallback to the CPU? 64 bool fallbackToCpuFromError; 65 // Is the client compiling with explicit set of devices? 66 bool introspectionEnabled; 67 // Is caching enabled? 68 bool cacheEnabled; 69 // Is control flow used? 70 bool hasControlFlow; 71 // Are dynamic tensors used? 72 bool hasDynamicTemporaries; 73 }; 74 75 struct DiagnosticExecutionInfo { 76 // The hash of the model architecture (without weights). 77 const uint8_t* modelArchHash; 78 // The device IDs as a comma-concatenated string. 79 const std::string deviceId; 80 // Execution mode (e.g. Sync, Burst) 81 ExecutionMode executionMode; 82 // Data class of the input to the model. 83 DataClass inputDataClass; 84 // Data class of the output from the model. 85 DataClass outputDataClass; 86 // The error code during compilation. 87 int32_t errorCode; 88 // Duration of the execution in the runtime. 89 // UINT64_MAX indicates no timing information is available. 90 uint64_t durationRuntimeNanos; 91 // Duration of the execution in the service driver. 92 // UINT64_MAX indicates no timing information is available. 93 uint64_t durationDriverNanos; 94 // Duration of the execution running on the hardware. 95 // UINT64_MAX indicates no timing information is available. 96 uint64_t durationHardwareNanos; 97 // Is the client compiling with explicit set of devices? 98 bool introspectionEnabled; 99 // Is caching enabled? 100 bool cacheEnabled; 101 // Is control flow used? 102 bool hasControlFlow; 103 // Are dynamic tensors used? 104 bool hasDynamicTemporaries; 105 }; 106 107 void registerTelemetryCallbacks(std::function<void(const DiagnosticCompilationInfo*)> compilation, 108 std::function<void(const DiagnosticExecutionInfo*)> execution); 109 void clearTelemetryCallbacks(); 110 111 } // namespace android::nn::telemetry 112 113 #endif // ANDROID_PACKAGES_MODULES_NEURALNETWORKS_RUNTIME_TELEMETRY_H 114