chore: import upstream snapshot with attribution
cffconvert / validate (push) Has been skipped
License Check / license-check (push) Failing after 2s

This commit is contained in:
wehub-resource-sync
2026-07-13 12:14:16 +08:00
commit 8a852e4b4e
36502 changed files with 9277225 additions and 0 deletions
@@ -0,0 +1,51 @@
load("@rules_cc//cc:cc_library.bzl", "cc_library")
load("//tensorflow:tensorflow.default.bzl", "get_compatible_with_portable")
load(
"//tensorflow/lite:build_def.bzl",
"tflite_cc_library_with_c_headers_test",
"tflite_copts",
)
package(
# copybara:uncomment default_applicable_licenses = ["//tensorflow:LICENSE"],
default_visibility = ["//visibility:public"],
licenses = ["notice"],
)
exports_files(
srcs = [
"profiler.h",
"telemetry_setting.h",
],
visibility = [
"//tensorflow/lite:__subpackages__",
],
)
tflite_cc_library_with_c_headers_test(
name = "profiler",
hdrs = ["profiler.h"],
compatible_with = get_compatible_with_portable(),
copts = tflite_copts(),
deps = [":telemetry_setting"],
)
tflite_cc_library_with_c_headers_test(
name = "telemetry_setting",
hdrs = ["telemetry_setting.h"],
compatible_with = get_compatible_with_portable(),
copts = tflite_copts(),
deps = [
":telemetry_setting_internal",
"//tensorflow/lite/core/c:common",
],
)
cc_library(
name = "telemetry_setting_internal",
srcs = ["telemetry_setting_internal.cc"],
hdrs = ["telemetry_setting_internal.h"],
compatible_with = get_compatible_with_portable(),
copts = tflite_copts(),
deps = ["//tensorflow/lite/core/c:common"],
)
@@ -0,0 +1,85 @@
/* Copyright 2022 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#ifndef TENSORFLOW_LITE_PROFILING_TELEMETRY_C_PROFILER_H_
#define TENSORFLOW_LITE_PROFILING_TELEMETRY_C_PROFILER_H_
#include <stdint.h>
#include "tensorflow/lite/profiling/telemetry/c/telemetry_setting.h"
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
// C API for TFLite telemetry profiler.
// See C++ interface in tflite::telemetry::TelemetryProfiler.
// Note: This struct does not comply with ABI stability.
typedef struct TfLiteTelemetryProfilerStruct {
// Data that profiler needs to identify itself. This data is owned by the
// profiler. The profiler is owned in the user code, so the profiler is
// responsible for deallocating this when it is destroyed.
void* data;
// Reports a telemetry event with status.
// `event_name` indicates the name of the event (e.g. "Invoke") and should not
// be nullptr.
// `status`: uint64_t representation of TelemetryStatusCode.
void (*ReportTelemetryEvent)( // NOLINT
struct TfLiteTelemetryProfilerStruct* profiler, const char* event_name,
uint64_t status);
// Reports an op telemetry event with status.
// Same as `ReportTelemetryEvent`, with additional args `op_idx` and
// `subgraph_idx`.
// `status`: uint64_t representation of TelemetryStatusCode.
void (*ReportTelemetryOpEvent)( // NOLINT
struct TfLiteTelemetryProfilerStruct* profiler, const char* event_name,
int64_t op_idx, int64_t subgraph_idx, uint64_t status);
// Reports the model and interpreter settings.
// `setting_name` indicates the name of the setting and should not be nullptr.
// `settings`'s lifespan is not guaranteed outside the scope of
// `ReportSettings` call.
void (*ReportSettings)( // NOLINT
struct TfLiteTelemetryProfilerStruct* profiler, const char* setting_name,
const TfLiteTelemetrySettings* settings);
// Signals the beginning of an operator invocation.
// `op_name` is the name of the operator and should not be nullptr.
// Op invoke event are triggered with OPERATOR_INVOKE_EVENT type for TfLite
// ops and delegate kernels, and DELEGATE_OPERATOR_INVOKE_EVENT for delegate
// ops within a delegate kernels, if the instrumentation is in place.
// Returns event handle which can be passed to `EndOpInvokeEvent` later.
uint32_t (*ReportBeginOpInvokeEvent)( // NOLINT
struct TfLiteTelemetryProfilerStruct* profiler, const char* op_name,
int64_t op_idx, int64_t subgraph_idx);
// Signals the end to the event specified by `event_handle`.
void (*ReportEndOpInvokeEvent)( // NOLINT
struct TfLiteTelemetryProfilerStruct* profiler, uint32_t event_handle);
// For op / delegate op with built-in performance measurements, they
// are able to report the elapsed time directly.
// `elapsed_time` is in microsecond.
void (*ReportOpInvokeEvent)( // NOLINT
struct TfLiteTelemetryProfilerStruct* profiler, const char* op_name,
uint64_t elapsed_time, int64_t op_idx, int64_t subgraph_idx);
} TfLiteTelemetryProfilerStruct;
#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
#endif // TENSORFLOW_LITE_PROFILING_TELEMETRY_C_PROFILER_H_
@@ -0,0 +1,91 @@
/* Copyright 2022 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#ifndef TENSORFLOW_LITE_PROFILING_TELEMETRY_C_TELEMETRY_SETTING_H_
#define TENSORFLOW_LITE_PROFILING_TELEMETRY_C_TELEMETRY_SETTING_H_
#include <stddef.h>
#include <stdint.h>
#include "tensorflow/lite/core/c/common.h"
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
// TFLite model, interpreter or delegate settings that will be reported by
// telemetry.
// Note: This struct does not comply with ABI stability.
typedef struct TfLiteTelemetrySettings {
// Source of the settings. Determines how `data` is interpreted.
// See tflite::telemetry::TelemetrySource for definition.
uint32_t source;
// Settings data. Interpretation based on `source`.
// If `source` is TFLITE_INTERPRETER, the type of `data` will
// be `TelemetryInterpreterSettings`.
// Otherwise, the data is provided by the individual delegate.
// Owned by the caller that exports TelemetrySettings (e.g. Interpreter).
const void* data;
} TfLiteTelemetrySettings;
typedef struct TfLiteTelemetryConversionMetadata
TfLiteTelemetryConversionMetadata;
const int32_t* TfLiteTelemetryConversionMetadataGetModelOptimizationModes(
const TfLiteTelemetryConversionMetadata* metadata);
size_t TfLiteTelemetryConversionMetadataGetNumModelOptimizationModes(
const TfLiteTelemetryConversionMetadata* metadata);
// TfLite model information and settings of the interpreter.
// Note: This struct does not comply with ABI stability.
typedef struct TfLiteTelemetryInterpreterSettings
TfLiteTelemetryInterpreterSettings;
const TfLiteTelemetryConversionMetadata*
TfLiteTelemetryInterpreterSettingsGetConversionMetadata(
const TfLiteTelemetryInterpreterSettings* settings);
// Telemetry data for a specific TFLite subgraph.
typedef struct TfLiteTelemetrySubgraphInfo TfLiteTelemetrySubgraphInfo;
size_t TfLiteTelemetryInterpreterSettingsGetNumSubgraphInfo(
const TfLiteTelemetryInterpreterSettings* settings);
const TfLiteTelemetrySubgraphInfo*
TfLiteTelemetryInterpreterSettingsGetSubgraphInfo(
const TfLiteTelemetryInterpreterSettings* settings);
size_t TfLiteTelemetrySubgraphInfoGetNumQuantizations(
TfLiteTelemetrySubgraphInfo* subgraph_info);
const TfLiteQuantization* TfLiteTelemetrySubgraphInfoGetQuantizations(
TfLiteTelemetrySubgraphInfo* subgraph_info);
// Telemetry information for GPU delegate.
typedef struct TfLiteTelemetryGpuDelegateSettings
TfLiteTelemetryGpuDelegateSettings;
size_t TfLiteTelemetryGpuDelegateSettingsGetNumNodesDelegated(
const TfLiteTelemetryGpuDelegateSettings* settings);
int TfLiteTelemetryGpuDelegateSettingsGetBackend(
const TfLiteTelemetryGpuDelegateSettings* settings);
#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
#endif // TENSORFLOW_LITE_PROFILING_TELEMETRY_C_TELEMETRY_SETTING_H_
@@ -0,0 +1,78 @@
/* Copyright 2022 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#include "tensorflow/lite/profiling/telemetry/c/telemetry_setting_internal.h"
#include <cstddef>
#include <cstdint>
extern "C" {
const TfLiteTelemetryConversionMetadata*
TfLiteTelemetryInterpreterSettingsGetConversionMetadata(
const TfLiteTelemetryInterpreterSettings* settings) {
if (settings == nullptr) return nullptr;
return settings->conversion_metadata.get();
}
const int32_t* TfLiteTelemetryConversionMetadataGetModelOptimizationModes(
const TfLiteTelemetryConversionMetadata* metadata) {
if (metadata == nullptr) return nullptr;
return metadata->model_optimization_modes.data();
}
size_t TfLiteTelemetryConversionMetadataGetNumModelOptimizationModes(
const TfLiteTelemetryConversionMetadata* metadata) {
if (metadata == nullptr) return 0;
return metadata->model_optimization_modes.size();
}
size_t TfLiteTelemetryInterpreterSettingsGetNumSubgraphInfo(
const TfLiteTelemetryInterpreterSettings* settings) {
if (settings == nullptr) return 0;
return settings->subgraph_infos.size();
}
const TfLiteTelemetrySubgraphInfo*
TfLiteTelemetryInterpreterSettingsGetSubgraphInfo(
const TfLiteTelemetryInterpreterSettings* settings) {
if (settings == nullptr) return nullptr;
return settings->subgraph_infos.data();
}
size_t TfLiteTelemetrySubgraphInfoGetNumQuantizations(
TfLiteTelemetrySubgraphInfo* subgraph_info) {
if (subgraph_info == nullptr) return 0;
return subgraph_info->quantizations.size();
}
const TfLiteQuantization* TfLiteTelemetrySubgraphInfoGetQuantizations(
TfLiteTelemetrySubgraphInfo* subgraph_info) {
if (subgraph_info == nullptr) return nullptr;
return subgraph_info->quantizations.data();
}
size_t TfLiteTelemetryGpuDelegateSettingsGetNumNodesDelegated(
const TfLiteTelemetryGpuDelegateSettings* settings) {
if (settings == nullptr) return 0;
return settings->num_nodes_delegated;
}
int TfLiteTelemetryGpuDelegateSettingsGetBackend(
const TfLiteTelemetryGpuDelegateSettings* settings) {
if (settings == nullptr) return 0;
return settings->backend;
}
} // extern "C"
@@ -0,0 +1,58 @@
/* Copyright 2022 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#ifndef TENSORFLOW_LITE_PROFILING_TELEMETRY_C_TELEMETRY_SETTING_INTERNAL_H_
#define TENSORFLOW_LITE_PROFILING_TELEMETRY_C_TELEMETRY_SETTING_INTERNAL_H_
#include <cstdint>
#include <memory>
#include <vector>
#include "tensorflow/lite/core/c/common.h"
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
struct TfLiteTelemetryConversionMetadata {
std::vector<int32_t> model_optimization_modes;
};
struct TfLiteTelemetrySubgraphInfo {
std::vector<TfLiteQuantization> quantizations;
};
struct TfLiteTelemetryInterpreterSettings {
std::unique_ptr<TfLiteTelemetryConversionMetadata> conversion_metadata;
std::vector<TfLiteTelemetrySubgraphInfo> subgraph_infos;
};
struct TfLiteTelemetryGpuDelegateSettings {
// Reported by "GpuDelegate::DelegatePrepare" event.
size_t num_nodes_delegated;
// Reported by "GpuDelegateKernel::Prepare" event.
enum Backend : int {
UNKNOWN = 0,
OPENCL = 1,
OPENGL = 2,
};
Backend backend;
};
#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
#endif // TENSORFLOW_LITE_PROFILING_TELEMETRY_C_TELEMETRY_SETTING_INTERNAL_H_