| diff --git a/tensorflow/lite/acceleration/configuration/configuration.proto b/tensorflow/lite/acceleration/configuration/configuration.proto |
| index 4456d031970..a2bbd88004f 100644 |
| --- a/tensorflow/lite/acceleration/configuration/configuration.proto |
| +++ b/tensorflow/lite/acceleration/configuration/configuration.proto |
| @@ -99,6 +99,8 @@ enum Delegate { |
| CORE_ML = 7; |
| // Arm NN Delegate. |
| ARMNN = 8; |
| + // MediaTek Neuron Delegate. |
| + MTK_NEURON = 9; |
| } |
| |
| enum NNAPIExecutionPreference { |
| @@ -664,6 +666,111 @@ message ArmNNSettings { |
| optional string additional_parameters = 3; |
| } |
| |
| +// MediaTek Neuron Delegate Settings. |
| +// See https://neuropilot.mediatek.com/ for more information. |
| +message MtkNeuronSettings { |
| + enum ExecutionPreference { |
| + PREFERENCE_UNDEFINED = 0; |
| + |
| + // Prefer execution in a power-efficient mode, optimizing for low power |
| + // consumption. |
| + PREFERENCE_LOW_POWER = 1; |
| + |
| + // Prefer execution that provides shorter single-shot latency, optimizing |
| + // for fast response times. |
| + PREFERENCE_FAST_SINGLE_ANSWER = 2; |
| + |
| + // Prefer execution that provides sustained speed for continuous operation |
| + // and higher throughput, optimizing for overall performance in ongoing or |
| + // repetitive tasks. |
| + PREFERENCE_SUSTAINED_SPEED = 3; |
| + |
| + // Prefer execution in the turbo boost mode, which may boost the frequencies |
| + // of APU and other system components such as CPU and DRAM, to achieve |
| + // maximum performance. If boosting is not supported in the underlying |
| + // system, it falls back to the behavior of PREFERENCE_FAST_SINGLE_ANSWER. |
| + PREFERENCE_TURBO_BOOST = 4; |
| + } |
| + |
| + enum ExecutionPriority { |
| + PRIORITY_UNDEFINED = 0; |
| + PRIORITY_LOW = 90; |
| + PRIORITY_MEDIUM = 100; |
| + PRIORITY_HIGH = 110; |
| + } |
| + |
| + enum OptimizationHint { |
| + OPTIMIZATION_NONE = 0; |
| + |
| + // Optimization hint for reducing latency. This hint may distribute the |
| + // workload across multiple APU cores in the compiled model to achieve |
| + // faster execution. |
| + OPTIMIZATION_LOW_LATENCY = 1; |
| + |
| + // Optimization hint for reducing DRAM access and minimizing memory |
| + // bandwidth usage through kernel fusion and data fusion techniques. |
| + OPTIMIZATION_DEEP_FUSION = 2; |
| + |
| + // Optimization hint for processing multiple input samples in parallel |
| + // across available APU cores in the batch dimension. This optimization is |
| + // effective for models with a batch size greater than 1. |
| + OPTIMIZATION_BATCH_PROCESSING = 3; |
| + } |
| + |
| + // How to check the operator compatibility with the underlying accelerator. |
| + enum OperationCheckMode { |
| + NO_OPERATION_CHECK = 0; |
| + |
| + // Checks each node separately with multiple queries to the backend. |
| + PER_NODE_OPERATION_CHECK = 1; |
| + |
| + // Checks all nodes in the graph at once with a batched query to the |
| + // backend. |
| + PRE_OPERATION_CHECK = 2; |
| + } |
| + |
| + // The preferred execution mode. The system-wide default will be used when |
| + // PREFERENCE_UNDEFINED is passed to the delegate. |
| + optional ExecutionPreference execution_preference = 1; |
| + |
| + // The execution priority of the inference request. The system-wide default |
| + // will be used when PRIORITY_UNDEFINED is passed to the delegate. |
| + optional ExecutionPriority execution_priority = 2; |
| + |
| + // The optimization hints that will instruct the model compiler. |
| + repeated OptimizationHint optimization_hints = 3 [packed = true]; |
| + |
| + // Whether and how to check the operator compatibility with the underlying |
| + // accelerator. |
| + optional OperationCheckMode operation_check_mode = 4; |
| + |
| + // Whether to allow the accelerator to optionally use lower-precision FP16 |
| + // arithmetic when performing calculations on FP32 data. |
| + optional bool allow_fp16_precision_for_fp32 = 5; |
| + |
| + // Whether to use AHardwareBuffer_* API to manage buffers. Requires Android |
| + // API level >= 26, or a dedicated AHardwareBuffer API shim on non-Android |
| + // platforms. |
| + optional bool use_ahwb = 6; |
| + |
| + // Whether to use cachable (consistent / coherent) memory. This will affect |
| + // both buffer allocation and buffer importing behaviors. |
| + optional bool use_cacheable_buffer = 7 [default = true]; |
| + |
| + // Extra options for the Neuron compiler, such as "--opt-bw". |
| + // See docs at https://neuropilot.mediatek.com/ for available options. |
| + repeated string compile_options = 8; |
| + |
| + // Optional list of target accelerator device names. |
| + // If empty, the delegate will automatically select the accelerator. |
| + // See docs at https://neuropilot.mediatek.com/ for available accelerators. |
| + repeated string accelerator_names = 9; |
| + |
| + // Optional path to the platform-dependent Neuron configuration file. |
| + // See docs at https://neuropilot.mediatek.com/ for more details. |
| + optional string neuron_config_path = 10; |
| +} |
| + |
| // How to configure TFLite. |
| message TFLiteSettings { |
| // Which delegate to use. |
| @@ -721,6 +828,9 @@ message TFLiteSettings { |
| |
| // For configuring the Arm NN delegate. |
| optional ArmNNSettings armnn_settings = 16; |
| + |
| + // For configuring MediaTek Neuron delegate. |
| + optional MtkNeuronSettings mtk_neuron_settings = 17; |
| } |
| |
| // Whether to automatically fallback to TFLite CPU path on delegation errors. |
| diff --git a/tensorflow/lite/acceleration/configuration/configuration_generated.h b/tensorflow/lite/acceleration/configuration/configuration_generated.h |
| index 675dfc9d8c9..aa6d94af9e3 100644 |
| --- a/tensorflow/lite/acceleration/configuration/configuration_generated.h |
| +++ b/tensorflow/lite/acceleration/configuration/configuration_generated.h |
| @@ -89,6 +89,10 @@ struct ArmNNSettings; |
| struct ArmNNSettingsBuilder; |
| struct ArmNNSettingsT; |
| |
| +struct MtkNeuronSettings; |
| +struct MtkNeuronSettingsBuilder; |
| +struct MtkNeuronSettingsT; |
| + |
| struct TFLiteSettings; |
| struct TFLiteSettingsBuilder; |
| struct TFLiteSettingsT; |
| @@ -191,6 +195,8 @@ bool operator==(const CPUSettingsT &lhs, const CPUSettingsT &rhs); |
| bool operator!=(const CPUSettingsT &lhs, const CPUSettingsT &rhs); |
| bool operator==(const ArmNNSettingsT &lhs, const ArmNNSettingsT &rhs); |
| bool operator!=(const ArmNNSettingsT &lhs, const ArmNNSettingsT &rhs); |
| +bool operator==(const MtkNeuronSettingsT &lhs, const MtkNeuronSettingsT &rhs); |
| +bool operator!=(const MtkNeuronSettingsT &lhs, const MtkNeuronSettingsT &rhs); |
| bool operator==(const TFLiteSettingsT &lhs, const TFLiteSettingsT &rhs); |
| bool operator!=(const TFLiteSettingsT &lhs, const TFLiteSettingsT &rhs); |
| bool operator==(const FallbackSettingsT &lhs, const FallbackSettingsT &rhs); |
| @@ -276,11 +282,12 @@ enum Delegate : int32_t { |
| Delegate_EDGETPU_CORAL = 6, |
| Delegate_CORE_ML = 7, |
| Delegate_ARMNN = 8, |
| + Delegate_MTK_NEURON = 9, |
| Delegate_MIN = Delegate_NONE, |
| - Delegate_MAX = Delegate_ARMNN |
| + Delegate_MAX = Delegate_MTK_NEURON |
| }; |
| |
| -inline const Delegate (&EnumValuesDelegate())[9] { |
| +inline const Delegate (&EnumValuesDelegate())[10] { |
| static const Delegate values[] = { |
| Delegate_NONE, |
| Delegate_NNAPI, |
| @@ -290,13 +297,14 @@ inline const Delegate (&EnumValuesDelegate())[9] { |
| Delegate_EDGETPU, |
| Delegate_EDGETPU_CORAL, |
| Delegate_CORE_ML, |
| - Delegate_ARMNN |
| + Delegate_ARMNN, |
| + Delegate_MTK_NEURON |
| }; |
| return values; |
| } |
| |
| inline const char * const *EnumNamesDelegate() { |
| - static const char * const names[10] = { |
| + static const char * const names[11] = { |
| "NONE", |
| "NNAPI", |
| "GPU", |
| @@ -306,13 +314,14 @@ inline const char * const *EnumNamesDelegate() { |
| "EDGETPU_CORAL", |
| "CORE_ML", |
| "ARMNN", |
| + "MTK_NEURON", |
| nullptr |
| }; |
| return names; |
| } |
| |
| inline const char *EnumNameDelegate(Delegate e) { |
| - if (::flatbuffers::IsOutRange(e, Delegate_NONE, Delegate_ARMNN)) return ""; |
| + if (::flatbuffers::IsOutRange(e, Delegate_NONE, Delegate_MTK_NEURON)) return ""; |
| const size_t index = static_cast<size_t>(e); |
| return EnumNamesDelegate()[index]; |
| } |
| @@ -874,6 +883,147 @@ inline const char *EnumNamePerformance(Performance e) { |
| |
| } // namespace CoralSettings_ |
| |
| +namespace MtkNeuronSettings_ { |
| + |
| +enum ExecutionPreference : int32_t { |
| + ExecutionPreference_PREFERENCE_UNDEFINED = 0, |
| + ExecutionPreference_PREFERENCE_LOW_POWER = 1, |
| + ExecutionPreference_PREFERENCE_FAST_SINGLE_ANSWER = 2, |
| + ExecutionPreference_PREFERENCE_SUSTAINED_SPEED = 3, |
| + ExecutionPreference_PREFERENCE_TURBO_BOOST = 4, |
| + ExecutionPreference_MIN = ExecutionPreference_PREFERENCE_UNDEFINED, |
| + ExecutionPreference_MAX = ExecutionPreference_PREFERENCE_TURBO_BOOST |
| +}; |
| + |
| +inline const ExecutionPreference (&EnumValuesExecutionPreference())[5] { |
| + static const ExecutionPreference values[] = { |
| + ExecutionPreference_PREFERENCE_UNDEFINED, |
| + ExecutionPreference_PREFERENCE_LOW_POWER, |
| + ExecutionPreference_PREFERENCE_FAST_SINGLE_ANSWER, |
| + ExecutionPreference_PREFERENCE_SUSTAINED_SPEED, |
| + ExecutionPreference_PREFERENCE_TURBO_BOOST |
| + }; |
| + return values; |
| +} |
| + |
| +inline const char * const *EnumNamesExecutionPreference() { |
| + static const char * const names[6] = { |
| + "PREFERENCE_UNDEFINED", |
| + "PREFERENCE_LOW_POWER", |
| + "PREFERENCE_FAST_SINGLE_ANSWER", |
| + "PREFERENCE_SUSTAINED_SPEED", |
| + "PREFERENCE_TURBO_BOOST", |
| + nullptr |
| + }; |
| + return names; |
| +} |
| + |
| +inline const char *EnumNameExecutionPreference(ExecutionPreference e) { |
| + if (::flatbuffers::IsOutRange(e, ExecutionPreference_PREFERENCE_UNDEFINED, ExecutionPreference_PREFERENCE_TURBO_BOOST)) return ""; |
| + const size_t index = static_cast<size_t>(e); |
| + return EnumNamesExecutionPreference()[index]; |
| +} |
| + |
| +enum ExecutionPriority : int32_t { |
| + ExecutionPriority_PRIORITY_UNDEFINED = 0, |
| + ExecutionPriority_PRIORITY_LOW = 90, |
| + ExecutionPriority_PRIORITY_MEDIUM = 100, |
| + ExecutionPriority_PRIORITY_HIGH = 110, |
| + ExecutionPriority_MIN = ExecutionPriority_PRIORITY_UNDEFINED, |
| + ExecutionPriority_MAX = ExecutionPriority_PRIORITY_HIGH |
| +}; |
| + |
| +inline const ExecutionPriority (&EnumValuesExecutionPriority())[4] { |
| + static const ExecutionPriority values[] = { |
| + ExecutionPriority_PRIORITY_UNDEFINED, |
| + ExecutionPriority_PRIORITY_LOW, |
| + ExecutionPriority_PRIORITY_MEDIUM, |
| + ExecutionPriority_PRIORITY_HIGH |
| + }; |
| + return values; |
| +} |
| + |
| +inline const char *EnumNameExecutionPriority(ExecutionPriority e) { |
| + switch (e) { |
| + case ExecutionPriority_PRIORITY_UNDEFINED: return "PRIORITY_UNDEFINED"; |
| + case ExecutionPriority_PRIORITY_LOW: return "PRIORITY_LOW"; |
| + case ExecutionPriority_PRIORITY_MEDIUM: return "PRIORITY_MEDIUM"; |
| + case ExecutionPriority_PRIORITY_HIGH: return "PRIORITY_HIGH"; |
| + default: return ""; |
| + } |
| +} |
| + |
| +enum OptimizationHint : int32_t { |
| + OptimizationHint_OPTIMIZATION_NONE = 0, |
| + OptimizationHint_OPTIMIZATION_LOW_LATENCY = 1, |
| + OptimizationHint_OPTIMIZATION_DEEP_FUSION = 2, |
| + OptimizationHint_OPTIMIZATION_BATCH_PROCESSING = 3, |
| + OptimizationHint_MIN = OptimizationHint_OPTIMIZATION_NONE, |
| + OptimizationHint_MAX = OptimizationHint_OPTIMIZATION_BATCH_PROCESSING |
| +}; |
| + |
| +inline const OptimizationHint (&EnumValuesOptimizationHint())[4] { |
| + static const OptimizationHint values[] = { |
| + OptimizationHint_OPTIMIZATION_NONE, |
| + OptimizationHint_OPTIMIZATION_LOW_LATENCY, |
| + OptimizationHint_OPTIMIZATION_DEEP_FUSION, |
| + OptimizationHint_OPTIMIZATION_BATCH_PROCESSING |
| + }; |
| + return values; |
| +} |
| + |
| +inline const char * const *EnumNamesOptimizationHint() { |
| + static const char * const names[5] = { |
| + "OPTIMIZATION_NONE", |
| + "OPTIMIZATION_LOW_LATENCY", |
| + "OPTIMIZATION_DEEP_FUSION", |
| + "OPTIMIZATION_BATCH_PROCESSING", |
| + nullptr |
| + }; |
| + return names; |
| +} |
| + |
| +inline const char *EnumNameOptimizationHint(OptimizationHint e) { |
| + if (::flatbuffers::IsOutRange(e, OptimizationHint_OPTIMIZATION_NONE, OptimizationHint_OPTIMIZATION_BATCH_PROCESSING)) return ""; |
| + const size_t index = static_cast<size_t>(e); |
| + return EnumNamesOptimizationHint()[index]; |
| +} |
| + |
| +enum OperationCheckMode : int32_t { |
| + OperationCheckMode_NO_OPERATION_CHECK = 0, |
| + OperationCheckMode_PER_NODE_OPERATION_CHECK = 1, |
| + OperationCheckMode_PRE_OPERATION_CHECK = 2, |
| + OperationCheckMode_MIN = OperationCheckMode_NO_OPERATION_CHECK, |
| + OperationCheckMode_MAX = OperationCheckMode_PRE_OPERATION_CHECK |
| +}; |
| + |
| +inline const OperationCheckMode (&EnumValuesOperationCheckMode())[3] { |
| + static const OperationCheckMode values[] = { |
| + OperationCheckMode_NO_OPERATION_CHECK, |
| + OperationCheckMode_PER_NODE_OPERATION_CHECK, |
| + OperationCheckMode_PRE_OPERATION_CHECK |
| + }; |
| + return values; |
| +} |
| + |
| +inline const char * const *EnumNamesOperationCheckMode() { |
| + static const char * const names[4] = { |
| + "NO_OPERATION_CHECK", |
| + "PER_NODE_OPERATION_CHECK", |
| + "PRE_OPERATION_CHECK", |
| + nullptr |
| + }; |
| + return names; |
| +} |
| + |
| +inline const char *EnumNameOperationCheckMode(OperationCheckMode e) { |
| + if (::flatbuffers::IsOutRange(e, OperationCheckMode_NO_OPERATION_CHECK, OperationCheckMode_PRE_OPERATION_CHECK)) return ""; |
| + const size_t index = static_cast<size_t>(e); |
| + return EnumNamesOperationCheckMode()[index]; |
| +} |
| + |
| +} // namespace MtkNeuronSettings_ |
| + |
| enum BenchmarkEventType : int32_t { |
| BenchmarkEventType_UNDEFINED_BENCHMARK_EVENT_TYPE = 0, |
| BenchmarkEventType_START = 1, |
| @@ -2633,6 +2783,193 @@ inline ::flatbuffers::Offset<ArmNNSettings> CreateArmNNSettingsDirect( |
| |
| ::flatbuffers::Offset<ArmNNSettings> CreateArmNNSettings(::flatbuffers::FlatBufferBuilder &_fbb, const ArmNNSettingsT *_o, const ::flatbuffers::rehasher_function_t *_rehasher = nullptr); |
| |
| +struct MtkNeuronSettingsT : public ::flatbuffers::NativeTable { |
| + typedef MtkNeuronSettings TableType; |
| + tflite::MtkNeuronSettings_::ExecutionPreference execution_preference = tflite::MtkNeuronSettings_::ExecutionPreference_PREFERENCE_UNDEFINED; |
| + tflite::MtkNeuronSettings_::ExecutionPriority execution_priority = tflite::MtkNeuronSettings_::ExecutionPriority_PRIORITY_UNDEFINED; |
| + std::vector<tflite::MtkNeuronSettings_::OptimizationHint> optimization_hints{}; |
| + tflite::MtkNeuronSettings_::OperationCheckMode operation_check_mode = tflite::MtkNeuronSettings_::OperationCheckMode_NO_OPERATION_CHECK; |
| + bool allow_fp16_precision_for_fp32 = false; |
| + bool use_ahwb = false; |
| + bool use_cacheable_buffer = true; |
| + std::vector<std::string> compile_options{}; |
| + std::vector<std::string> accelerator_names{}; |
| + std::string neuron_config_path{}; |
| +}; |
| + |
| +struct MtkNeuronSettings FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table { |
| + typedef MtkNeuronSettingsT NativeTableType; |
| + typedef MtkNeuronSettingsBuilder Builder; |
| + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { |
| + VT_EXECUTION_PREFERENCE = 4, |
| + VT_EXECUTION_PRIORITY = 6, |
| + VT_OPTIMIZATION_HINTS = 8, |
| + VT_OPERATION_CHECK_MODE = 10, |
| + VT_ALLOW_FP16_PRECISION_FOR_FP32 = 12, |
| + VT_USE_AHWB = 14, |
| + VT_USE_CACHEABLE_BUFFER = 16, |
| + VT_COMPILE_OPTIONS = 18, |
| + VT_ACCELERATOR_NAMES = 20, |
| + VT_NEURON_CONFIG_PATH = 22 |
| + }; |
| + tflite::MtkNeuronSettings_::ExecutionPreference execution_preference() const { |
| + return static_cast<tflite::MtkNeuronSettings_::ExecutionPreference>(GetField<int32_t>(VT_EXECUTION_PREFERENCE, 0)); |
| + } |
| + tflite::MtkNeuronSettings_::ExecutionPriority execution_priority() const { |
| + return static_cast<tflite::MtkNeuronSettings_::ExecutionPriority>(GetField<int32_t>(VT_EXECUTION_PRIORITY, 0)); |
| + } |
| + const ::flatbuffers::Vector<int32_t> *optimization_hints() const { |
| + return GetPointer<const ::flatbuffers::Vector<int32_t> *>(VT_OPTIMIZATION_HINTS); |
| + } |
| + tflite::MtkNeuronSettings_::OperationCheckMode operation_check_mode() const { |
| + return static_cast<tflite::MtkNeuronSettings_::OperationCheckMode>(GetField<int32_t>(VT_OPERATION_CHECK_MODE, 0)); |
| + } |
| + bool allow_fp16_precision_for_fp32() const { |
| + return GetField<uint8_t>(VT_ALLOW_FP16_PRECISION_FOR_FP32, 0) != 0; |
| + } |
| + bool use_ahwb() const { |
| + return GetField<uint8_t>(VT_USE_AHWB, 0) != 0; |
| + } |
| + bool use_cacheable_buffer() const { |
| + return GetField<uint8_t>(VT_USE_CACHEABLE_BUFFER, 1) != 0; |
| + } |
| + const ::flatbuffers::Vector<::flatbuffers::Offset<::flatbuffers::String>> *compile_options() const { |
| + return GetPointer<const ::flatbuffers::Vector<::flatbuffers::Offset<::flatbuffers::String>> *>(VT_COMPILE_OPTIONS); |
| + } |
| + const ::flatbuffers::Vector<::flatbuffers::Offset<::flatbuffers::String>> *accelerator_names() const { |
| + return GetPointer<const ::flatbuffers::Vector<::flatbuffers::Offset<::flatbuffers::String>> *>(VT_ACCELERATOR_NAMES); |
| + } |
| + const ::flatbuffers::String *neuron_config_path() const { |
| + return GetPointer<const ::flatbuffers::String *>(VT_NEURON_CONFIG_PATH); |
| + } |
| + bool Verify(::flatbuffers::Verifier &verifier) const { |
| + return VerifyTableStart(verifier) && |
| + VerifyField<int32_t>(verifier, VT_EXECUTION_PREFERENCE, 4) && |
| + VerifyField<int32_t>(verifier, VT_EXECUTION_PRIORITY, 4) && |
| + VerifyOffset(verifier, VT_OPTIMIZATION_HINTS) && |
| + verifier.VerifyVector(optimization_hints()) && |
| + VerifyField<int32_t>(verifier, VT_OPERATION_CHECK_MODE, 4) && |
| + VerifyField<uint8_t>(verifier, VT_ALLOW_FP16_PRECISION_FOR_FP32, 1) && |
| + VerifyField<uint8_t>(verifier, VT_USE_AHWB, 1) && |
| + VerifyField<uint8_t>(verifier, VT_USE_CACHEABLE_BUFFER, 1) && |
| + VerifyOffset(verifier, VT_COMPILE_OPTIONS) && |
| + verifier.VerifyVector(compile_options()) && |
| + verifier.VerifyVectorOfStrings(compile_options()) && |
| + VerifyOffset(verifier, VT_ACCELERATOR_NAMES) && |
| + verifier.VerifyVector(accelerator_names()) && |
| + verifier.VerifyVectorOfStrings(accelerator_names()) && |
| + VerifyOffset(verifier, VT_NEURON_CONFIG_PATH) && |
| + verifier.VerifyString(neuron_config_path()) && |
| + verifier.EndTable(); |
| + } |
| + MtkNeuronSettingsT *UnPack(const ::flatbuffers::resolver_function_t *_resolver = nullptr) const; |
| + void UnPackTo(MtkNeuronSettingsT *_o, const ::flatbuffers::resolver_function_t *_resolver = nullptr) const; |
| + static ::flatbuffers::Offset<MtkNeuronSettings> Pack(::flatbuffers::FlatBufferBuilder &_fbb, const MtkNeuronSettingsT* _o, const ::flatbuffers::rehasher_function_t *_rehasher = nullptr); |
| +}; |
| + |
| +struct MtkNeuronSettingsBuilder { |
| + typedef MtkNeuronSettings Table; |
| + ::flatbuffers::FlatBufferBuilder &fbb_; |
| + ::flatbuffers::uoffset_t start_; |
| + void add_execution_preference(tflite::MtkNeuronSettings_::ExecutionPreference execution_preference) { |
| + fbb_.AddElement<int32_t>(MtkNeuronSettings::VT_EXECUTION_PREFERENCE, static_cast<int32_t>(execution_preference), 0); |
| + } |
| + void add_execution_priority(tflite::MtkNeuronSettings_::ExecutionPriority execution_priority) { |
| + fbb_.AddElement<int32_t>(MtkNeuronSettings::VT_EXECUTION_PRIORITY, static_cast<int32_t>(execution_priority), 0); |
| + } |
| + void add_optimization_hints(::flatbuffers::Offset<::flatbuffers::Vector<int32_t>> optimization_hints) { |
| + fbb_.AddOffset(MtkNeuronSettings::VT_OPTIMIZATION_HINTS, optimization_hints); |
| + } |
| + void add_operation_check_mode(tflite::MtkNeuronSettings_::OperationCheckMode operation_check_mode) { |
| + fbb_.AddElement<int32_t>(MtkNeuronSettings::VT_OPERATION_CHECK_MODE, static_cast<int32_t>(operation_check_mode), 0); |
| + } |
| + void add_allow_fp16_precision_for_fp32(bool allow_fp16_precision_for_fp32) { |
| + fbb_.AddElement<uint8_t>(MtkNeuronSettings::VT_ALLOW_FP16_PRECISION_FOR_FP32, static_cast<uint8_t>(allow_fp16_precision_for_fp32), 0); |
| + } |
| + void add_use_ahwb(bool use_ahwb) { |
| + fbb_.AddElement<uint8_t>(MtkNeuronSettings::VT_USE_AHWB, static_cast<uint8_t>(use_ahwb), 0); |
| + } |
| + void add_use_cacheable_buffer(bool use_cacheable_buffer) { |
| + fbb_.AddElement<uint8_t>(MtkNeuronSettings::VT_USE_CACHEABLE_BUFFER, static_cast<uint8_t>(use_cacheable_buffer), 1); |
| + } |
| + void add_compile_options(::flatbuffers::Offset<::flatbuffers::Vector<::flatbuffers::Offset<::flatbuffers::String>>> compile_options) { |
| + fbb_.AddOffset(MtkNeuronSettings::VT_COMPILE_OPTIONS, compile_options); |
| + } |
| + void add_accelerator_names(::flatbuffers::Offset<::flatbuffers::Vector<::flatbuffers::Offset<::flatbuffers::String>>> accelerator_names) { |
| + fbb_.AddOffset(MtkNeuronSettings::VT_ACCELERATOR_NAMES, accelerator_names); |
| + } |
| + void add_neuron_config_path(::flatbuffers::Offset<::flatbuffers::String> neuron_config_path) { |
| + fbb_.AddOffset(MtkNeuronSettings::VT_NEURON_CONFIG_PATH, neuron_config_path); |
| + } |
| + explicit MtkNeuronSettingsBuilder(::flatbuffers::FlatBufferBuilder &_fbb) |
| + : fbb_(_fbb) { |
| + start_ = fbb_.StartTable(); |
| + } |
| + ::flatbuffers::Offset<MtkNeuronSettings> Finish() { |
| + const auto end = fbb_.EndTable(start_); |
| + auto o = ::flatbuffers::Offset<MtkNeuronSettings>(end); |
| + return o; |
| + } |
| +}; |
| + |
| +inline ::flatbuffers::Offset<MtkNeuronSettings> CreateMtkNeuronSettings( |
| + ::flatbuffers::FlatBufferBuilder &_fbb, |
| + tflite::MtkNeuronSettings_::ExecutionPreference execution_preference = tflite::MtkNeuronSettings_::ExecutionPreference_PREFERENCE_UNDEFINED, |
| + tflite::MtkNeuronSettings_::ExecutionPriority execution_priority = tflite::MtkNeuronSettings_::ExecutionPriority_PRIORITY_UNDEFINED, |
| + ::flatbuffers::Offset<::flatbuffers::Vector<int32_t>> optimization_hints = 0, |
| + tflite::MtkNeuronSettings_::OperationCheckMode operation_check_mode = tflite::MtkNeuronSettings_::OperationCheckMode_NO_OPERATION_CHECK, |
| + bool allow_fp16_precision_for_fp32 = false, |
| + bool use_ahwb = false, |
| + bool use_cacheable_buffer = true, |
| + ::flatbuffers::Offset<::flatbuffers::Vector<::flatbuffers::Offset<::flatbuffers::String>>> compile_options = 0, |
| + ::flatbuffers::Offset<::flatbuffers::Vector<::flatbuffers::Offset<::flatbuffers::String>>> accelerator_names = 0, |
| + ::flatbuffers::Offset<::flatbuffers::String> neuron_config_path = 0) { |
| + MtkNeuronSettingsBuilder builder_(_fbb); |
| + builder_.add_neuron_config_path(neuron_config_path); |
| + builder_.add_accelerator_names(accelerator_names); |
| + builder_.add_compile_options(compile_options); |
| + builder_.add_operation_check_mode(operation_check_mode); |
| + builder_.add_optimization_hints(optimization_hints); |
| + builder_.add_execution_priority(execution_priority); |
| + builder_.add_execution_preference(execution_preference); |
| + builder_.add_use_cacheable_buffer(use_cacheable_buffer); |
| + builder_.add_use_ahwb(use_ahwb); |
| + builder_.add_allow_fp16_precision_for_fp32(allow_fp16_precision_for_fp32); |
| + return builder_.Finish(); |
| +} |
| + |
| +inline ::flatbuffers::Offset<MtkNeuronSettings> CreateMtkNeuronSettingsDirect( |
| + ::flatbuffers::FlatBufferBuilder &_fbb, |
| + tflite::MtkNeuronSettings_::ExecutionPreference execution_preference = tflite::MtkNeuronSettings_::ExecutionPreference_PREFERENCE_UNDEFINED, |
| + tflite::MtkNeuronSettings_::ExecutionPriority execution_priority = tflite::MtkNeuronSettings_::ExecutionPriority_PRIORITY_UNDEFINED, |
| + const std::vector<int32_t> *optimization_hints = nullptr, |
| + tflite::MtkNeuronSettings_::OperationCheckMode operation_check_mode = tflite::MtkNeuronSettings_::OperationCheckMode_NO_OPERATION_CHECK, |
| + bool allow_fp16_precision_for_fp32 = false, |
| + bool use_ahwb = false, |
| + bool use_cacheable_buffer = true, |
| + const std::vector<::flatbuffers::Offset<::flatbuffers::String>> *compile_options = nullptr, |
| + const std::vector<::flatbuffers::Offset<::flatbuffers::String>> *accelerator_names = nullptr, |
| + const char *neuron_config_path = nullptr) { |
| + auto optimization_hints__ = optimization_hints ? _fbb.CreateVector<int32_t>(*optimization_hints) : 0; |
| + auto compile_options__ = compile_options ? _fbb.CreateVector<::flatbuffers::Offset<::flatbuffers::String>>(*compile_options) : 0; |
| + auto accelerator_names__ = accelerator_names ? _fbb.CreateVector<::flatbuffers::Offset<::flatbuffers::String>>(*accelerator_names) : 0; |
| + auto neuron_config_path__ = neuron_config_path ? _fbb.CreateString(neuron_config_path) : 0; |
| + return tflite::CreateMtkNeuronSettings( |
| + _fbb, |
| + execution_preference, |
| + execution_priority, |
| + optimization_hints__, |
| + operation_check_mode, |
| + allow_fp16_precision_for_fp32, |
| + use_ahwb, |
| + use_cacheable_buffer, |
| + compile_options__, |
| + accelerator_names__, |
| + neuron_config_path__); |
| +} |
| + |
| +::flatbuffers::Offset<MtkNeuronSettings> CreateMtkNeuronSettings(::flatbuffers::FlatBufferBuilder &_fbb, const MtkNeuronSettingsT *_o, const ::flatbuffers::rehasher_function_t *_rehasher = nullptr); |
| + |
| struct TFLiteSettingsT : public ::flatbuffers::NativeTable { |
| typedef TFLiteSettings TableType; |
| tflite::Delegate delegate = tflite::Delegate_NONE; |
| @@ -2651,6 +2988,7 @@ struct TFLiteSettingsT : public ::flatbuffers::NativeTable { |
| std::unique_ptr<tflite::GoogleEdgeTpuSettingsT> google_edgetpu_settings{}; |
| std::unique_ptr<tflite::CompilationCachingSettingsT> compilation_caching_settings{}; |
| std::unique_ptr<tflite::ArmNNSettingsT> armnn_settings{}; |
| + std::unique_ptr<tflite::MtkNeuronSettingsT> mtk_neuron_settings{}; |
| TFLiteSettingsT() = default; |
| TFLiteSettingsT(const TFLiteSettingsT &o); |
| TFLiteSettingsT(TFLiteSettingsT&&) FLATBUFFERS_NOEXCEPT = default; |
| @@ -2676,7 +3014,8 @@ struct TFLiteSettings FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table { |
| VT_STABLE_DELEGATE_LOADER_SETTINGS = 28, |
| VT_GOOGLE_EDGETPU_SETTINGS = 30, |
| VT_COMPILATION_CACHING_SETTINGS = 32, |
| - VT_ARMNN_SETTINGS = 34 |
| + VT_ARMNN_SETTINGS = 34, |
| + VT_MTK_NEURON_SETTINGS = 36 |
| }; |
| tflite::Delegate delegate() const { |
| return static_cast<tflite::Delegate>(GetField<int32_t>(VT_DELEGATE, 0)); |
| @@ -2726,6 +3065,9 @@ struct TFLiteSettings FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table { |
| const tflite::ArmNNSettings *armnn_settings() const { |
| return GetPointer<const tflite::ArmNNSettings *>(VT_ARMNN_SETTINGS); |
| } |
| + const tflite::MtkNeuronSettings *mtk_neuron_settings() const { |
| + return GetPointer<const tflite::MtkNeuronSettings *>(VT_MTK_NEURON_SETTINGS); |
| + } |
| bool Verify(::flatbuffers::Verifier &verifier) const { |
| return VerifyTableStart(verifier) && |
| VerifyField<int32_t>(verifier, VT_DELEGATE, 4) && |
| @@ -2757,6 +3099,8 @@ struct TFLiteSettings FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table { |
| verifier.VerifyTable(compilation_caching_settings()) && |
| VerifyOffset(verifier, VT_ARMNN_SETTINGS) && |
| verifier.VerifyTable(armnn_settings()) && |
| + VerifyOffset(verifier, VT_MTK_NEURON_SETTINGS) && |
| + verifier.VerifyTable(mtk_neuron_settings()) && |
| verifier.EndTable(); |
| } |
| TFLiteSettingsT *UnPack(const ::flatbuffers::resolver_function_t *_resolver = nullptr) const; |
| @@ -2816,6 +3160,9 @@ struct TFLiteSettingsBuilder { |
| void add_armnn_settings(::flatbuffers::Offset<tflite::ArmNNSettings> armnn_settings) { |
| fbb_.AddOffset(TFLiteSettings::VT_ARMNN_SETTINGS, armnn_settings); |
| } |
| + void add_mtk_neuron_settings(::flatbuffers::Offset<tflite::MtkNeuronSettings> mtk_neuron_settings) { |
| + fbb_.AddOffset(TFLiteSettings::VT_MTK_NEURON_SETTINGS, mtk_neuron_settings); |
| + } |
| explicit TFLiteSettingsBuilder(::flatbuffers::FlatBufferBuilder &_fbb) |
| : fbb_(_fbb) { |
| start_ = fbb_.StartTable(); |
| @@ -2844,8 +3191,10 @@ inline ::flatbuffers::Offset<TFLiteSettings> CreateTFLiteSettings( |
| ::flatbuffers::Offset<tflite::StableDelegateLoaderSettings> stable_delegate_loader_settings = 0, |
| ::flatbuffers::Offset<tflite::GoogleEdgeTpuSettings> google_edgetpu_settings = 0, |
| ::flatbuffers::Offset<tflite::CompilationCachingSettings> compilation_caching_settings = 0, |
| - ::flatbuffers::Offset<tflite::ArmNNSettings> armnn_settings = 0) { |
| + ::flatbuffers::Offset<tflite::ArmNNSettings> armnn_settings = 0, |
| + ::flatbuffers::Offset<tflite::MtkNeuronSettings> mtk_neuron_settings = 0) { |
| TFLiteSettingsBuilder builder_(_fbb); |
| + builder_.add_mtk_neuron_settings(mtk_neuron_settings); |
| builder_.add_armnn_settings(armnn_settings); |
| builder_.add_compilation_caching_settings(compilation_caching_settings); |
| builder_.add_google_edgetpu_settings(google_edgetpu_settings); |
| @@ -5130,6 +5479,79 @@ inline ::flatbuffers::Offset<ArmNNSettings> CreateArmNNSettings(::flatbuffers::F |
| } |
| |
| |
| +inline bool operator==(const MtkNeuronSettingsT &lhs, const MtkNeuronSettingsT &rhs) { |
| + return |
| + (lhs.execution_preference == rhs.execution_preference) && |
| + (lhs.execution_priority == rhs.execution_priority) && |
| + (lhs.optimization_hints == rhs.optimization_hints) && |
| + (lhs.operation_check_mode == rhs.operation_check_mode) && |
| + (lhs.allow_fp16_precision_for_fp32 == rhs.allow_fp16_precision_for_fp32) && |
| + (lhs.use_ahwb == rhs.use_ahwb) && |
| + (lhs.use_cacheable_buffer == rhs.use_cacheable_buffer) && |
| + (lhs.compile_options == rhs.compile_options) && |
| + (lhs.accelerator_names == rhs.accelerator_names) && |
| + (lhs.neuron_config_path == rhs.neuron_config_path); |
| +} |
| + |
| +inline bool operator!=(const MtkNeuronSettingsT &lhs, const MtkNeuronSettingsT &rhs) { |
| + return !(lhs == rhs); |
| +} |
| + |
| + |
| +inline MtkNeuronSettingsT *MtkNeuronSettings::UnPack(const ::flatbuffers::resolver_function_t *_resolver) const { |
| + auto _o = std::unique_ptr<MtkNeuronSettingsT>(new MtkNeuronSettingsT()); |
| + UnPackTo(_o.get(), _resolver); |
| + return _o.release(); |
| +} |
| + |
| +inline void MtkNeuronSettings::UnPackTo(MtkNeuronSettingsT *_o, const ::flatbuffers::resolver_function_t *_resolver) const { |
| + (void)_o; |
| + (void)_resolver; |
| + { auto _e = execution_preference(); _o->execution_preference = _e; } |
| + { auto _e = execution_priority(); _o->execution_priority = _e; } |
| + { auto _e = optimization_hints(); if (_e) { _o->optimization_hints.resize(_e->size()); for (::flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { _o->optimization_hints[_i] = static_cast<tflite::MtkNeuronSettings_::OptimizationHint>(_e->Get(_i)); } } else { _o->optimization_hints.resize(0); } } |
| + { auto _e = operation_check_mode(); _o->operation_check_mode = _e; } |
| + { auto _e = allow_fp16_precision_for_fp32(); _o->allow_fp16_precision_for_fp32 = _e; } |
| + { auto _e = use_ahwb(); _o->use_ahwb = _e; } |
| + { auto _e = use_cacheable_buffer(); _o->use_cacheable_buffer = _e; } |
| + { auto _e = compile_options(); if (_e) { _o->compile_options.resize(_e->size()); for (::flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { _o->compile_options[_i] = _e->Get(_i)->str(); } } else { _o->compile_options.resize(0); } } |
| + { auto _e = accelerator_names(); if (_e) { _o->accelerator_names.resize(_e->size()); for (::flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { _o->accelerator_names[_i] = _e->Get(_i)->str(); } } else { _o->accelerator_names.resize(0); } } |
| + { auto _e = neuron_config_path(); if (_e) _o->neuron_config_path = _e->str(); } |
| +} |
| + |
| +inline ::flatbuffers::Offset<MtkNeuronSettings> MtkNeuronSettings::Pack(::flatbuffers::FlatBufferBuilder &_fbb, const MtkNeuronSettingsT* _o, const ::flatbuffers::rehasher_function_t *_rehasher) { |
| + return CreateMtkNeuronSettings(_fbb, _o, _rehasher); |
| +} |
| + |
| +inline ::flatbuffers::Offset<MtkNeuronSettings> CreateMtkNeuronSettings(::flatbuffers::FlatBufferBuilder &_fbb, const MtkNeuronSettingsT *_o, const ::flatbuffers::rehasher_function_t *_rehasher) { |
| + (void)_rehasher; |
| + (void)_o; |
| + struct _VectorArgs { ::flatbuffers::FlatBufferBuilder *__fbb; const MtkNeuronSettingsT* __o; const ::flatbuffers::rehasher_function_t *__rehasher; } _va = { &_fbb, _o, _rehasher}; (void)_va; |
| + auto _execution_preference = _o->execution_preference; |
| + auto _execution_priority = _o->execution_priority; |
| + auto _optimization_hints = _o->optimization_hints.size() ? _fbb.CreateVectorScalarCast<int32_t>(::flatbuffers::data(_o->optimization_hints), _o->optimization_hints.size()) : 0; |
| + auto _operation_check_mode = _o->operation_check_mode; |
| + auto _allow_fp16_precision_for_fp32 = _o->allow_fp16_precision_for_fp32; |
| + auto _use_ahwb = _o->use_ahwb; |
| + auto _use_cacheable_buffer = _o->use_cacheable_buffer; |
| + auto _compile_options = _o->compile_options.size() ? _fbb.CreateVectorOfStrings(_o->compile_options) : 0; |
| + auto _accelerator_names = _o->accelerator_names.size() ? _fbb.CreateVectorOfStrings(_o->accelerator_names) : 0; |
| + auto _neuron_config_path = _o->neuron_config_path.empty() ? 0 : _fbb.CreateString(_o->neuron_config_path); |
| + return tflite::CreateMtkNeuronSettings( |
| + _fbb, |
| + _execution_preference, |
| + _execution_priority, |
| + _optimization_hints, |
| + _operation_check_mode, |
| + _allow_fp16_precision_for_fp32, |
| + _use_ahwb, |
| + _use_cacheable_buffer, |
| + _compile_options, |
| + _accelerator_names, |
| + _neuron_config_path); |
| +} |
| + |
| + |
| inline bool operator==(const TFLiteSettingsT &lhs, const TFLiteSettingsT &rhs) { |
| return |
| (lhs.delegate == rhs.delegate) && |
| @@ -5147,7 +5569,8 @@ inline bool operator==(const TFLiteSettingsT &lhs, const TFLiteSettingsT &rhs) { |
| ((lhs.stable_delegate_loader_settings == rhs.stable_delegate_loader_settings) || (lhs.stable_delegate_loader_settings && rhs.stable_delegate_loader_settings && *lhs.stable_delegate_loader_settings == *rhs.stable_delegate_loader_settings)) && |
| ((lhs.google_edgetpu_settings == rhs.google_edgetpu_settings) || (lhs.google_edgetpu_settings && rhs.google_edgetpu_settings && *lhs.google_edgetpu_settings == *rhs.google_edgetpu_settings)) && |
| ((lhs.compilation_caching_settings == rhs.compilation_caching_settings) || (lhs.compilation_caching_settings && rhs.compilation_caching_settings && *lhs.compilation_caching_settings == *rhs.compilation_caching_settings)) && |
| - ((lhs.armnn_settings == rhs.armnn_settings) || (lhs.armnn_settings && rhs.armnn_settings && *lhs.armnn_settings == *rhs.armnn_settings)); |
| + ((lhs.armnn_settings == rhs.armnn_settings) || (lhs.armnn_settings && rhs.armnn_settings && *lhs.armnn_settings == *rhs.armnn_settings)) && |
| + ((lhs.mtk_neuron_settings == rhs.mtk_neuron_settings) || (lhs.mtk_neuron_settings && rhs.mtk_neuron_settings && *lhs.mtk_neuron_settings == *rhs.mtk_neuron_settings)); |
| } |
| |
| inline bool operator!=(const TFLiteSettingsT &lhs, const TFLiteSettingsT &rhs) { |
| @@ -5171,7 +5594,8 @@ inline TFLiteSettingsT::TFLiteSettingsT(const TFLiteSettingsT &o) |
| stable_delegate_loader_settings((o.stable_delegate_loader_settings) ? new tflite::StableDelegateLoaderSettingsT(*o.stable_delegate_loader_settings) : nullptr), |
| google_edgetpu_settings((o.google_edgetpu_settings) ? new tflite::GoogleEdgeTpuSettingsT(*o.google_edgetpu_settings) : nullptr), |
| compilation_caching_settings((o.compilation_caching_settings) ? new tflite::CompilationCachingSettingsT(*o.compilation_caching_settings) : nullptr), |
| - armnn_settings((o.armnn_settings) ? new tflite::ArmNNSettingsT(*o.armnn_settings) : nullptr) { |
| + armnn_settings((o.armnn_settings) ? new tflite::ArmNNSettingsT(*o.armnn_settings) : nullptr), |
| + mtk_neuron_settings((o.mtk_neuron_settings) ? new tflite::MtkNeuronSettingsT(*o.mtk_neuron_settings) : nullptr) { |
| } |
| |
| inline TFLiteSettingsT &TFLiteSettingsT::operator=(TFLiteSettingsT o) FLATBUFFERS_NOEXCEPT { |
| @@ -5191,6 +5615,7 @@ inline TFLiteSettingsT &TFLiteSettingsT::operator=(TFLiteSettingsT o) FLATBUFFER |
| std::swap(google_edgetpu_settings, o.google_edgetpu_settings); |
| std::swap(compilation_caching_settings, o.compilation_caching_settings); |
| std::swap(armnn_settings, o.armnn_settings); |
| + std::swap(mtk_neuron_settings, o.mtk_neuron_settings); |
| return *this; |
| } |
| |
| @@ -5219,6 +5644,7 @@ inline void TFLiteSettings::UnPackTo(TFLiteSettingsT *_o, const ::flatbuffers::r |
| { auto _e = google_edgetpu_settings(); if (_e) { if(_o->google_edgetpu_settings) { _e->UnPackTo(_o->google_edgetpu_settings.get(), _resolver); } else { _o->google_edgetpu_settings = std::unique_ptr<tflite::GoogleEdgeTpuSettingsT>(_e->UnPack(_resolver)); } } else if (_o->google_edgetpu_settings) { _o->google_edgetpu_settings.reset(); } } |
| { auto _e = compilation_caching_settings(); if (_e) { if(_o->compilation_caching_settings) { _e->UnPackTo(_o->compilation_caching_settings.get(), _resolver); } else { _o->compilation_caching_settings = std::unique_ptr<tflite::CompilationCachingSettingsT>(_e->UnPack(_resolver)); } } else if (_o->compilation_caching_settings) { _o->compilation_caching_settings.reset(); } } |
| { auto _e = armnn_settings(); if (_e) { if(_o->armnn_settings) { _e->UnPackTo(_o->armnn_settings.get(), _resolver); } else { _o->armnn_settings = std::unique_ptr<tflite::ArmNNSettingsT>(_e->UnPack(_resolver)); } } else if (_o->armnn_settings) { _o->armnn_settings.reset(); } } |
| + { auto _e = mtk_neuron_settings(); if (_e) { if(_o->mtk_neuron_settings) { _e->UnPackTo(_o->mtk_neuron_settings.get(), _resolver); } else { _o->mtk_neuron_settings = std::unique_ptr<tflite::MtkNeuronSettingsT>(_e->UnPack(_resolver)); } } else if (_o->mtk_neuron_settings) { _o->mtk_neuron_settings.reset(); } } |
| } |
| |
| inline ::flatbuffers::Offset<TFLiteSettings> TFLiteSettings::Pack(::flatbuffers::FlatBufferBuilder &_fbb, const TFLiteSettingsT* _o, const ::flatbuffers::rehasher_function_t *_rehasher) { |
| @@ -5245,6 +5671,7 @@ inline ::flatbuffers::Offset<TFLiteSettings> CreateTFLiteSettings(::flatbuffers: |
| auto _google_edgetpu_settings = _o->google_edgetpu_settings ? CreateGoogleEdgeTpuSettings(_fbb, _o->google_edgetpu_settings.get(), _rehasher) : 0; |
| auto _compilation_caching_settings = _o->compilation_caching_settings ? CreateCompilationCachingSettings(_fbb, _o->compilation_caching_settings.get(), _rehasher) : 0; |
| auto _armnn_settings = _o->armnn_settings ? CreateArmNNSettings(_fbb, _o->armnn_settings.get(), _rehasher) : 0; |
| + auto _mtk_neuron_settings = _o->mtk_neuron_settings ? CreateMtkNeuronSettings(_fbb, _o->mtk_neuron_settings.get(), _rehasher) : 0; |
| return tflite::CreateTFLiteSettings( |
| _fbb, |
| _delegate, |
| @@ -5262,7 +5689,8 @@ inline ::flatbuffers::Offset<TFLiteSettings> CreateTFLiteSettings(::flatbuffers: |
| _stable_delegate_loader_settings, |
| _google_edgetpu_settings, |
| _compilation_caching_settings, |
| - _armnn_settings); |
| + _armnn_settings, |
| + _mtk_neuron_settings); |
| } |
| |
| |
| diff --git a/tensorflow/lite/acceleration/configuration/flatbuffer_to_proto.cc b/tensorflow/lite/acceleration/configuration/flatbuffer_to_proto.cc |
| index 0d09bfb01d9..87f822cf40c 100644 |
| --- a/tensorflow/lite/acceleration/configuration/flatbuffer_to_proto.cc |
| +++ b/tensorflow/lite/acceleration/configuration/flatbuffer_to_proto.cc |
| @@ -57,6 +57,8 @@ proto::Delegate ConvertDelegate(Delegate delegate) { |
| return proto::Delegate::CORE_ML; |
| case Delegate_ARMNN: |
| return proto::Delegate::ARMNN; |
| + case Delegate_MTK_NEURON: |
| + return proto::Delegate::MTK_NEURON; |
| } |
| TFLITE_LOG_PROD(TFLITE_LOG_ERROR, "Unexpected value for Delegate: %d", |
| delegate); |
| @@ -423,6 +425,53 @@ proto::CompilationCachingSettings ConvertCompilationCachingSettings( |
| return proto_settings; |
| } |
| |
| +proto::MtkNeuronSettings ConvertMtkNeuronSettings( |
| + const MtkNeuronSettings& settings) { |
| + proto::MtkNeuronSettings proto_settings; |
| + proto_settings.set_execution_preference( |
| + static_cast<proto::MtkNeuronSettings_ExecutionPreference>( |
| + settings.execution_preference())); |
| + proto_settings.set_execution_priority( |
| + static_cast<proto::MtkNeuronSettings_ExecutionPriority>( |
| + settings.execution_priority())); |
| + |
| + auto optimization_hints = settings.optimization_hints(); |
| + if (optimization_hints != nullptr) { |
| + for (auto hint : *optimization_hints) { |
| + proto_settings.add_optimization_hints( |
| + static_cast<proto::MtkNeuronSettings_OptimizationHint>(hint)); |
| + } |
| + } |
| + |
| + proto_settings.set_operation_check_mode( |
| + static_cast<proto::MtkNeuronSettings_OperationCheckMode>( |
| + settings.operation_check_mode())); |
| + proto_settings.set_allow_fp16_precision_for_fp32( |
| + settings.allow_fp16_precision_for_fp32()); |
| + proto_settings.set_use_ahwb(settings.use_ahwb()); |
| + proto_settings.set_use_cacheable_buffer(settings.use_cacheable_buffer()); |
| + |
| + auto compile_options = settings.compile_options(); |
| + if (compile_options != nullptr) { |
| + for (auto option : *compile_options) { |
| + proto_settings.add_compile_options(option->str()); |
| + } |
| + } |
| + |
| + auto accelerator_names = settings.accelerator_names(); |
| + if (accelerator_names != nullptr) { |
| + for (auto name : *accelerator_names) { |
| + proto_settings.add_accelerator_names(name->str()); |
| + } |
| + } |
| + |
| + if (settings.neuron_config_path()) { |
| + proto_settings.set_neuron_config_path(settings.neuron_config_path()->str()); |
| + } |
| + |
| + return proto_settings; |
| +} |
| + |
| proto::TFLiteSettings ConvertTfliteSettings(const TFLiteSettings& settings) { |
| proto::TFLiteSettings proto_settings; |
| proto_settings.set_delegate(ConvertDelegate(settings.delegate())); |
| @@ -490,6 +539,11 @@ proto::TFLiteSettings ConvertTfliteSettings(const TFLiteSettings& settings) { |
| *settings.compilation_caching_settings()); |
| } |
| |
| + if (settings.mtk_neuron_settings() != nullptr) { |
| + *proto_settings.mutable_mtk_neuron_settings() = |
| + ConvertMtkNeuronSettings(*settings.mtk_neuron_settings()); |
| + } |
| + |
| return proto_settings; |
| } |
| |
| diff --git a/tensorflow/lite/acceleration/configuration/flatbuffer_to_proto_test.cc b/tensorflow/lite/acceleration/configuration/flatbuffer_to_proto_test.cc |
| index d194826d97b..bd5ef446b08 100644 |
| --- a/tensorflow/lite/acceleration/configuration/flatbuffer_to_proto_test.cc |
| +++ b/tensorflow/lite/acceleration/configuration/flatbuffer_to_proto_test.cc |
| @@ -550,6 +550,54 @@ TEST_F(ConversionTest, CompilationCachingSettings) { |
| EXPECT_EQ(output_settings.model_token(), "model"); |
| } |
| |
| +TEST_F(ConversionTest, MtkNeuronSettings) { |
| + settings_.tflite_settings = std::make_unique<TFLiteSettingsT>(); |
| + settings_.tflite_settings->mtk_neuron_settings = |
| + std::make_unique<MtkNeuronSettingsT>(); |
| + MtkNeuronSettingsT* input_settings = |
| + settings_.tflite_settings->mtk_neuron_settings.get(); |
| + |
| + input_settings->execution_preference = |
| + MtkNeuronSettings_::ExecutionPreference_PREFERENCE_UNDEFINED; |
| + input_settings->execution_priority = |
| + MtkNeuronSettings_::ExecutionPriority_PRIORITY_MEDIUM; |
| + input_settings->optimization_hints = { |
| + MtkNeuronSettings_::OptimizationHint_OPTIMIZATION_LOW_LATENCY, |
| + MtkNeuronSettings_::OptimizationHint_OPTIMIZATION_BATCH_PROCESSING}; |
| + input_settings->operation_check_mode = |
| + MtkNeuronSettings_::OperationCheckMode_PER_NODE_OPERATION_CHECK; |
| + input_settings->allow_fp16_precision_for_fp32 = true; |
| + input_settings->use_ahwb = false; |
| + input_settings->use_cacheable_buffer = true; |
| + input_settings->compile_options = {"TEST_COMPILE_OPTIONS"}; |
| + input_settings->accelerator_names = {"TEST_ACCELERATOR_NAME"}; |
| + input_settings->neuron_config_path = "TEST_NEURON_CONFIG_PATH"; |
| + |
| + const proto::ComputeSettings compute = ConvertFromFlatbuffer(settings_); |
| + const proto::MtkNeuronSettings& output_settings = |
| + compute.tflite_settings().mtk_neuron_settings(); |
| + |
| + EXPECT_EQ(output_settings.execution_preference(), |
| + proto::MtkNeuronSettings::PREFERENCE_UNDEFINED); |
| + EXPECT_EQ(output_settings.execution_priority(), |
| + proto::MtkNeuronSettings::PRIORITY_MEDIUM); |
| + EXPECT_EQ(output_settings.optimization_hints().size(), 2); |
| + EXPECT_EQ(output_settings.optimization_hints().at(0), |
| + proto::MtkNeuronSettings::OPTIMIZATION_LOW_LATENCY); |
| + EXPECT_EQ(output_settings.optimization_hints().at(1), |
| + proto::MtkNeuronSettings::OPTIMIZATION_BATCH_PROCESSING); |
| + EXPECT_EQ(output_settings.operation_check_mode(), |
| + proto::MtkNeuronSettings::PER_NODE_OPERATION_CHECK); |
| + EXPECT_TRUE(output_settings.allow_fp16_precision_for_fp32()); |
| + EXPECT_FALSE(output_settings.use_ahwb()); |
| + EXPECT_TRUE(output_settings.use_cacheable_buffer()); |
| + EXPECT_EQ(output_settings.compile_options().size(), 1); |
| + EXPECT_EQ(output_settings.compile_options().at(0), "TEST_COMPILE_OPTIONS"); |
| + EXPECT_EQ(output_settings.accelerator_names().size(), 1); |
| + EXPECT_EQ(output_settings.accelerator_names().at(0), "TEST_ACCELERATOR_NAME"); |
| + EXPECT_EQ(output_settings.neuron_config_path(), "TEST_NEURON_CONFIG_PATH"); |
| +} |
| + |
| TEST_F(ConversionTest, MiniBenchmarkSettings) { |
| settings_.tflite_settings = std::make_unique<TFLiteSettingsT>(); |
| settings_.tflite_settings->cpu_settings = std::make_unique<CPUSettingsT>(); |
| diff --git a/tensorflow/lite/acceleration/configuration/proto_to_flatbuffer.cc b/tensorflow/lite/acceleration/configuration/proto_to_flatbuffer.cc |
| index 95109fcf1e5..0e9e4e4d6bf 100644 |
| --- a/tensorflow/lite/acceleration/configuration/proto_to_flatbuffer.cc |
| +++ b/tensorflow/lite/acceleration/configuration/proto_to_flatbuffer.cc |
| @@ -66,6 +66,8 @@ Delegate ConvertDelegate(proto::Delegate delegate) { |
| return Delegate_CORE_ML; |
| case proto::Delegate::ARMNN: |
| return Delegate_ARMNN; |
| + case proto::Delegate::MTK_NEURON: |
| + return Delegate_MTK_NEURON; |
| } |
| TFLITE_LOG_PROD(TFLITE_LOG_ERROR, "Unexpected value for Delegate: %d", |
| delegate); |
| @@ -393,6 +395,42 @@ Offset<EdgeTpuSettings> ConvertEdgeTpuSettings( |
| settings.use_layer_ir_tgc_backend())); |
| } |
| |
| +Offset<CompilationCachingSettings> ConvertCompilationCachingSettings( |
| + const proto::CompilationCachingSettings& settings, |
| + FlatBufferBuilder& builder) { |
| + return CreateCompilationCachingSettings( |
| + builder, builder.CreateString(settings.cache_dir()), |
| + builder.CreateString(settings.model_token())); |
| +} |
| + |
| +Offset<ArmNNSettings> ConvertArmNNSettings(const proto::ArmNNSettings& settings, |
| + FlatBufferBuilder& builder) { |
| + return CreateArmNNSettings( |
| + builder, builder.CreateString(settings.backends()), settings.fastmath(), |
| + builder.CreateString(settings.additional_parameters())); |
| +} |
| + |
| +Offset<MtkNeuronSettings> ConvertMtkNeuronSettings( |
| + const proto::MtkNeuronSettings& settings, FlatBufferBuilder& builder) { |
| + return CreateMtkNeuronSettings( |
| + builder, |
| + static_cast<MtkNeuronSettings_::ExecutionPreference>( |
| + settings.execution_preference()), |
| + static_cast<MtkNeuronSettings_::ExecutionPriority>( |
| + settings.execution_priority()), |
| + builder.CreateVector(settings.optimization_hints().data(), |
| + settings.optimization_hints().size()), |
| + static_cast<MtkNeuronSettings_::OperationCheckMode>( |
| + settings.operation_check_mode()), |
| + settings.allow_fp16_precision_for_fp32(), settings.use_ahwb(), |
| + settings.use_cacheable_buffer(), |
| + builder.CreateVectorOfStrings(settings.compile_options().begin(), |
| + settings.compile_options().end()), |
| + builder.CreateVectorOfStrings(settings.accelerator_names().begin(), |
| + settings.accelerator_names().end()), |
| + builder.CreateString(settings.neuron_config_path())); |
| +} |
| + |
| Offset<CoralSettings> ConvertCoralSettings(const proto::CoralSettings& settings, |
| FlatBufferBuilder& builder) { |
| return CreateCoralSettings( |
| @@ -418,8 +456,11 @@ Offset<TFLiteSettings> ConvertTfliteSettings( |
| settings.disable_default_delegates(), |
| ConvertStableDelegateLoaderSettings( |
| settings.stable_delegate_loader_settings(), builder), |
| - ConvertGoogleEdgeTpuSettings(settings.google_edgetpu_settings(), |
| - builder)); |
| + ConvertGoogleEdgeTpuSettings(settings.google_edgetpu_settings(), builder), |
| + ConvertCompilationCachingSettings(settings.compilation_caching_settings(), |
| + builder), |
| + ConvertArmNNSettings(settings.armnn_settings(), builder), |
| + ConvertMtkNeuronSettings(settings.mtk_neuron_settings(), builder)); |
| } |
| |
| Offset<ModelFile> ConvertModelFile(const proto::ModelFile& model_file, |
| @@ -459,7 +500,7 @@ const TFLiteSettings* ConvertFromProto( |
| const proto::TFLiteSettings& proto_settings, FlatBufferBuilder* builder) { |
| Offset<TFLiteSettings> settings = |
| ConvertTfliteSettings(proto_settings, *builder); |
| - return flatbuffers::GetTemporaryPointer(*builder, settings); |
| + return flatbuffers::GetMutableTemporaryPointer(*builder, settings); |
| } |
| |
| const ComputeSettings* ConvertFromProto( |
| @@ -471,14 +512,14 @@ const ComputeSettings* ConvertFromProto( |
| builder->CreateString(proto_settings.model_identifier_for_statistics()), |
| ConvertMinibenchmarkSettings(proto_settings.settings_to_test_locally(), |
| *builder)); |
| - return flatbuffers::GetTemporaryPointer(*builder, settings); |
| + return flatbuffers::GetMutableTemporaryPointer(*builder, settings); |
| } |
| |
| const MinibenchmarkSettings* ConvertFromProto( |
| const proto::MinibenchmarkSettings& proto_settings, |
| flatbuffers::FlatBufferBuilder* builder) { |
| auto settings = ConvertMinibenchmarkSettings(proto_settings, *builder); |
| - return flatbuffers::GetTemporaryPointer(*builder, settings); |
| + return flatbuffers::GetMutableTemporaryPointer(*builder, settings); |
| } |
| |
| } // namespace tflite |
| diff --git a/tensorflow/lite/acceleration/configuration/proto_to_flatbuffer_test.cc b/tensorflow/lite/acceleration/configuration/proto_to_flatbuffer_test.cc |
| index c59ec771cab..e504f09c682 100644 |
| --- a/tensorflow/lite/acceleration/configuration/proto_to_flatbuffer_test.cc |
| +++ b/tensorflow/lite/acceleration/configuration/proto_to_flatbuffer_test.cc |
| @@ -14,6 +14,7 @@ limitations under the License. |
| ==============================================================================*/ |
| #include "tensorflow/lite/acceleration/configuration/proto_to_flatbuffer.h" |
| |
| +#include <cstdint> |
| #include <string> |
| #include <vector> |
| |
| @@ -116,5 +117,121 @@ TEST(ConversionTest, StableDelegateLoaderSettings) { |
| kDelegateName); |
| } |
| |
| +TEST(ConversionTest, CompilationCachingSettings) { |
| + // Define the fields to be tested. |
| + const std::string kCacheDir = "TEST_CACHE_DIR"; |
| + const std::string kModelToken = "TEST_MODEL_TOKEN"; |
| + |
| + // Create the proto settings. |
| + proto::TFLiteSettings input_settings; |
| + auto* compilation_caching_settings = |
| + input_settings.mutable_compilation_caching_settings(); |
| + compilation_caching_settings->set_cache_dir(kCacheDir); |
| + compilation_caching_settings->set_model_token(kModelToken); |
| + flatbuffers::FlatBufferBuilder flatbuffers_builder; |
| + |
| + // Convert. |
| + auto output_settings = ConvertFromProto(input_settings, &flatbuffers_builder); |
| + |
| + // Verify the conversion results. |
| + const auto* output_compilation_caching_settings = |
| + output_settings->compilation_caching_settings(); |
| + ASSERT_NE(output_compilation_caching_settings, nullptr); |
| + EXPECT_EQ(output_compilation_caching_settings->cache_dir()->str(), kCacheDir); |
| + EXPECT_EQ(output_compilation_caching_settings->model_token()->str(), |
| + kModelToken); |
| +} |
| + |
| +TEST(ConversionTest, ArmNNSettings) { |
| + // Define the fields to be tested. |
| + const std::string kBackends = "TEST_BACKENDS"; |
| + const bool kFastmath = true; |
| + const std::string kAdditionalParameters = "TEST_ADDITIONAL_PARAMETERS"; |
| + |
| + // Create the proto settings. |
| + proto::TFLiteSettings input_settings; |
| + auto* armnn_settings = input_settings.mutable_armnn_settings(); |
| + armnn_settings->set_backends(kBackends); |
| + armnn_settings->set_fastmath(kFastmath); |
| + armnn_settings->set_additional_parameters(kAdditionalParameters); |
| + flatbuffers::FlatBufferBuilder flatbuffers_builder; |
| + |
| + // Convert. |
| + auto output_settings = ConvertFromProto(input_settings, &flatbuffers_builder); |
| + |
| + // Verify the conversion results. |
| + const auto* output_armnn_settings = output_settings->armnn_settings(); |
| + ASSERT_NE(output_armnn_settings, nullptr); |
| + EXPECT_EQ(output_armnn_settings->backends()->str(), kBackends); |
| + EXPECT_EQ(output_armnn_settings->fastmath(), kFastmath); |
| + EXPECT_EQ(output_armnn_settings->additional_parameters()->str(), |
| + kAdditionalParameters); |
| +} |
| + |
| +TEST(ConversionTest, MtkNeuronSettings) { |
| + // Define the fields to be tested. |
| + const proto::MtkNeuronSettings_ExecutionPreference kExecutionPreference = |
| + proto::MtkNeuronSettings::PREFERENCE_FAST_SINGLE_ANSWER; |
| + const proto::MtkNeuronSettings_ExecutionPriority kExecutionPriority = |
| + proto::MtkNeuronSettings::PRIORITY_MEDIUM; |
| + const proto::MtkNeuronSettings_OptimizationHint kOptimizationHint = |
| + proto::MtkNeuronSettings::OPTIMIZATION_LOW_LATENCY; |
| + const proto::MtkNeuronSettings_OperationCheckMode kOperationCheckMode = |
| + proto::MtkNeuronSettings::PER_NODE_OPERATION_CHECK; |
| + const bool kAllowFp16 = true; |
| + const bool kUseAhwb = false; |
| + const bool kUseCacheableBuffer = true; |
| + const std::string kCompileOptions = "TEST_COMPILE_OPTIONS"; |
| + const std::string kAcceleratorName = "TEST_ACCELERATOR_NAME"; |
| + const std::string kNeuronConfigPath = "TEST_NEURON_CONFIG_PATH"; |
| + |
| + // Create the proto settings. |
| + proto::TFLiteSettings input_settings; |
| + auto* mtk_neuron_settings = input_settings.mutable_mtk_neuron_settings(); |
| + mtk_neuron_settings->set_execution_preference(kExecutionPreference); |
| + mtk_neuron_settings->set_execution_priority(kExecutionPriority); |
| + mtk_neuron_settings->add_optimization_hints(kOptimizationHint); |
| + mtk_neuron_settings->set_operation_check_mode(kOperationCheckMode); |
| + mtk_neuron_settings->set_allow_fp16_precision_for_fp32(kAllowFp16); |
| + mtk_neuron_settings->set_use_ahwb(kUseAhwb); |
| + mtk_neuron_settings->set_use_cacheable_buffer(kUseCacheableBuffer); |
| + mtk_neuron_settings->add_compile_options(kCompileOptions); |
| + mtk_neuron_settings->add_accelerator_names(kAcceleratorName); |
| + mtk_neuron_settings->set_neuron_config_path(kNeuronConfigPath); |
| + flatbuffers::FlatBufferBuilder flatbuffers_builder; |
| + |
| + // Convert. |
| + auto output_settings = ConvertFromProto(input_settings, &flatbuffers_builder); |
| + |
| + // Verify the conversion results. |
| + const auto* output_mtk_neuron_settings = |
| + output_settings->mtk_neuron_settings(); |
| + ASSERT_NE(output_mtk_neuron_settings, nullptr); |
| + EXPECT_EQ( |
| + output_mtk_neuron_settings->execution_preference(), |
| + MtkNeuronSettings_::ExecutionPreference_PREFERENCE_FAST_SINGLE_ANSWER); |
| + EXPECT_EQ(output_mtk_neuron_settings->execution_priority(), |
| + MtkNeuronSettings_::ExecutionPriority_PRIORITY_MEDIUM); |
| + |
| + EXPECT_EQ(output_mtk_neuron_settings->optimization_hints()->size(), 1); |
| + EXPECT_EQ(output_mtk_neuron_settings->optimization_hints()->Get(0), |
| + kOptimizationHint); |
| + EXPECT_EQ(output_mtk_neuron_settings->operation_check_mode(), |
| + MtkNeuronSettings_::OperationCheckMode_PER_NODE_OPERATION_CHECK); |
| + EXPECT_EQ(output_mtk_neuron_settings->allow_fp16_precision_for_fp32(), |
| + kAllowFp16); |
| + EXPECT_EQ(output_mtk_neuron_settings->use_ahwb(), kUseAhwb); |
| + EXPECT_EQ(output_mtk_neuron_settings->use_cacheable_buffer(), |
| + kUseCacheableBuffer); |
| + EXPECT_EQ(output_mtk_neuron_settings->compile_options()->size(), 1); |
| + EXPECT_EQ(output_mtk_neuron_settings->compile_options()->Get(0)->str(), |
| + kCompileOptions); |
| + EXPECT_EQ(output_mtk_neuron_settings->accelerator_names()->size(), 1); |
| + EXPECT_EQ(output_mtk_neuron_settings->accelerator_names()->Get(0)->str(), |
| + kAcceleratorName); |
| + EXPECT_EQ(output_mtk_neuron_settings->neuron_config_path()->str(), |
| + kNeuronConfigPath); |
| +} |
| + |
| } // namespace |
| } // namespace tflite |
| diff --git a/tensorflow/lite/acceleration/configuration/testdata/configuration.proto_prev b/tensorflow/lite/acceleration/configuration/testdata/configuration.proto_prev |
| index 9d930646ebf..655d95f5990 100644 |
| --- a/tensorflow/lite/acceleration/configuration/testdata/configuration.proto_prev |
| +++ b/tensorflow/lite/acceleration/configuration/testdata/configuration.proto_prev |
| @@ -510,6 +510,22 @@ message EdgeTpuSettings { |
| // 4. Please try to use a unique name so that it's easier to identify the |
| // model during debugging. |
| optional string public_model_id = 9; |
| + |
| + // Layer IR (intermediate representation) TGC (tensor graph in C++) backend |
| + // options. |
| + // * If set to YES, compile as per layer IR -> TGC -> codegen flow. |
| + // * If set to NO, compile as per layer IR -> layer IR -> codegen flow. |
| + // * If set to AUTO, we try to run as per layer IR -> TGC -> codegen flow. If |
| + // not successful, we will fallback to layer IR -> layer IR -> codegen flow. |
| + // * If UNSPECIFIED, it is same as NO for now. |
| + enum UseLayerIrTgcBackend { |
| + USE_LAYER_IR_TGC_BACKEND_UNSPECIFIED = 0; |
| + USE_LAYER_IR_TGC_BACKEND_NO = 1; |
| + USE_LAYER_IR_TGC_BACKEND_YES = 2; |
| + USE_LAYER_IR_TGC_BACKEND_AUTO = 3; |
| + } |
| + optional UseLayerIrTgcBackend use_layer_ir_tgc_backend = 10 |
| + [default = USE_LAYER_IR_TGC_BACKEND_UNSPECIFIED]; |
| } |
| |
| // Google EdgeTPU delegate settings. |