From ad1b3d7518429e2d16a2695d9b0bbf81b6565ac9 Mon Sep 17 00:00:00 2001 From: Teresa Charlin Date: Tue, 14 Mar 2023 12:10:28 +0000 Subject: IVGCVSW-7555 Restructure Delegate * New folders created: * common is for common code where TfLite API is not used * classic is for existing delegate implementations * opaque is for new opaque delegate implementation, * tests is for shared between existing Delegate and Opaque Delegate which have test utils to work which delegate to use. * Existing delegate is built to libarmnnDelegate.so and opaque delegate is built as libarmnnOpaqueDelegate.so * Opaque structure is introduced but no API is added yet. * CmakeList.txt and delegate/CMakeList.txt have been modified and 2 new CmakeList.txt added * Rename BUILD_ARMNN_TFLITE_DELEGATE as BUILD_CLASSIC_DELEGATE * Rename BUILD_ARMNN_TFLITE_OPAQUE_DELEGATE as BUILD_OPAQUE_DELEGATE Signed-off-by: Teresa Charlin Change-Id: Ib682b9ad0ac8d8acdc4ec6d9099bb0008a9fe8ed --- delegate/include/DelegateOptions.hpp | 302 +---------------------------------- delegate/include/Version.hpp | 29 +--- delegate/include/armnn_delegate.hpp | 141 +--------------- 3 files changed, 10 insertions(+), 462 deletions(-) (limited to 'delegate/include') diff --git a/delegate/include/DelegateOptions.hpp b/delegate/include/DelegateOptions.hpp index a3c1edf82f..1c3ffb62ea 100644 --- a/delegate/include/DelegateOptions.hpp +++ b/delegate/include/DelegateOptions.hpp @@ -3,302 +3,6 @@ // SPDX-License-Identifier: MIT // -#pragma once - -#include -#include - -#include -#include - -namespace armnnDelegate -{ - -class DelegateOptions -{ -public: - DelegateOptions(armnn::Compute computeDevice, - const std::vector& backendOptions = {}, - armnn::Optional logSeverityLevel = armnn::EmptyOptional()); - - DelegateOptions(const std::vector& backends, - const std::vector& backendOptions = {}, - armnn::Optional logSeverityLevel = armnn::EmptyOptional()); - - DelegateOptions(armnn::Compute computeDevice, - const armnn::OptimizerOptions& optimizerOptions, - const armnn::Optional& logSeverityLevel = armnn::EmptyOptional(), - const armnn::Optional& func = armnn::EmptyOptional()); - - DelegateOptions(const std::vector& backends, - const armnn::OptimizerOptions& optimizerOptions, - const armnn::Optional& logSeverityLevel = armnn::EmptyOptional(), - const armnn::Optional& func = armnn::EmptyOptional()); - - - /** - * This constructor processes delegate options in form of command line arguments. - * It works in conjunction with the TfLite external delegate plugin. - * - * Available options: - * - * Option key: "backends" \n - * Possible values: ["EthosNPU"/"GpuAcc"/"CpuAcc"/"CpuRef"] \n - * Descriptions: A comma separated list without whitespaces of - * backends which should be used for execution. Falls - * back to next backend in list if previous doesn't - * provide support for operation. e.g. "GpuAcc,CpuAcc" - * - * Option key: "dynamic-backends-path" \n - * Possible values: [filenameString] \n - * Descriptions: This is the directory that will be searched for any dynamic backends. - * - * Option key: "logging-severity" \n - * Possible values: ["trace"/"debug"/"info"/"warning"/"error"/"fatal"] \n - * Description: Sets the logging severity level for ArmNN. Logging - * is turned off if this option is not provided. - * - * Option key: "gpu-tuning-level" \n - * Possible values: ["0"/"1"/"2"/"3"] \n - * Description: 0=UseOnly(default), 1=RapidTuning, 2=NormalTuning, - * 3=ExhaustiveTuning. Requires option gpu-tuning-file. - * 1,2 and 3 will create a tuning-file, 0 will apply the - * tunings from an existing file - * - * Option key: "gpu-mlgo-tuning-file" \n - * Possible values: [filenameString] \n - * Description: File name for the MLGO tuning file - * - * Option key: "gpu-tuning-file" \n - * Possible values: [filenameString] \n - * Description: File name for the tuning file. - * - * Option key: "gpu-enable-profiling" \n - * Possible values: ["true"/"false"] \n - * Description: Enables GPU profiling - * - * Option key: "gpu-kernel-profiling-enabled" \n - * Possible values: ["true"/"false"] \n - * Description: Enables GPU kernel profiling - * - * Option key: "save-cached-network" \n - * Possible values: ["true"/"false"] \n - * Description: Enables saving of the cached network to a file, - * specified with the cached-network-filepath option - * - * Option key: "cached-network-filepath" \n - * Possible values: [filenameString] \n - * Description: If non-empty, the given file will be used to load/save the cached network. - * If save-cached-network is given then the cached network will be saved to the given file. - * To save the cached network a file must already exist. - * If save-cached-network is not given then the cached network will be loaded from the given file. - * This will remove initial compilation time of kernels and speed up the first execution. - * - * Option key: "enable-fast-math" \n - * Possible values: ["true"/"false"] \n - * Description: Enables fast_math options in backends that support it - * - * Option key: "number-of-threads" \n - * Possible values: ["1"-"64"] \n - * Description: Assign the number of threads used by the CpuAcc backend. - * Default is set to 0 (Backend will decide number of threads to use). - * - * Option key: "reduce-fp32-to-fp16" \n - * Possible values: ["true"/"false"] \n - * Description: Reduce Fp32 data to Fp16 for faster processing - * - * Option key: "reduce-fp32-to-bf16" \n - * Possible values: ["true"/"false"] \n - * Description: This option is currently ignored. Please enable Fast Math in the CpuAcc or GpuAcc backends. - * - * Option key: "debug-data" \n - * Possible values: ["true"/"false"] \n - * Description: Add debug data for easier troubleshooting - * - * Option key: "memory-import" \n - * Possible values: ["true"/"false"] \n - * Description: Enable memory import - * - * Option key: "enable-internal-profiling" \n - * Possible values: ["true"/"false"] \n - * Description: Enable the internal profiling feature. - * - * Option key: "internal-profiling-detail" \n - * Possible values: [1/2] \n - * Description: Set the detail on the internal profiling. 1 = DetailsWithEvents, 2 = DetailsOnly. - * - * Option key: "enable-external-profiling" \n - * Possible values: ["true"/"false"] \n - * Description: Enable the external profiling feature. - * - * Option key: "timeline-profiling" \n - * Possible values: ["true"/"false"] \n - * Description: Indicates whether external timeline profiling is enabled or not. - * - * Option key: "outgoing-capture-file" \n - * Possible values: [filenameString] \n - * Description: Path to a file in which outgoing timeline profiling messages will be stored. - * - * Option key: "incoming-capture-file" \n - * Possible values: [filenameString] \n - * Description: Path to a file in which incoming timeline profiling messages will be stored. - * - * Option key: "file-only-external-profiling" \n - * Possible values: ["true"/"false"] \n - * Description: Enable profiling output to file only. - * - * Option key: "counter-capture-period" \n - * Possible values: Integer, Default is 10000u - * Description: Value in microseconds of the profiling capture period. \n - * - * Option key: "profiling-file-format" \n - * Possible values: String of ["binary"] \n - * Description: The format of the file used for outputting profiling data. Currently on "binary" is supported. - * - * Option key: "serialize-to-dot" \n - * Possible values: [filenameString] \n - * Description: Serialize the optimized network to the file specified in "dot" format. - * - * Option key: "infer-output-shape" \n - * Possible values: ["true"/"false"] \n - * Description: Infers output tensor shape from input tensor shape and validate where applicable. - * - * Option key: "allow-expanded-dims" \n - * Possible values: ["true"/"false"] \n - * Description: If true will disregard dimensions with a size of 1 when validating tensor shapes but tensor - * sizes must still match. \n - * This is an Experimental parameter that is incompatible with "infer-output-shape". \n - * This parameter may be removed in a later update. - * - * Option key: "disable-tflite-runtime-fallback" \n - * Possible values: ["true"/"false"] \n - * Description: Disable TfLite Runtime fallback in the Arm NN TfLite delegate. - * An exception will be thrown if unsupported operators are encountered. - * This option is only for testing purposes. - * - * @param[in] option_keys Delegate option names - * @param[in] options_values Delegate option values - * @param[in] num_options Number of delegate options - * @param[in,out] report_error Error callback function - * - */ - DelegateOptions(char const* const* options_keys, - char const* const* options_values, - size_t num_options, - void (*report_error)(const char*)); - - const std::vector& GetBackends() const { return m_Backends; } - - void SetBackends(const std::vector& backends) { m_Backends = backends; } - - void SetDynamicBackendsPath(const std::string& dynamicBackendsPath) - { - m_RuntimeOptions.m_DynamicBackendsPath = dynamicBackendsPath; - } - const std::string& GetDynamicBackendsPath() const - { - return m_RuntimeOptions.m_DynamicBackendsPath; - } - - void SetGpuProfilingState(bool gpuProfilingState) - { - m_RuntimeOptions.m_EnableGpuProfiling = gpuProfilingState; - } - bool GetGpuProfilingState() - { - return m_RuntimeOptions.m_EnableGpuProfiling; - } - - const std::vector& GetBackendOptions() const - { - return m_RuntimeOptions.m_BackendOptions; - } - - /// Appends a backend option to the list of backend options - void AddBackendOption(const armnn::BackendOptions& option) - { - m_RuntimeOptions.m_BackendOptions.push_back(option); - } - - /// Sets the severity level for logging within ArmNN that will be used on creation of the delegate - void SetLoggingSeverity(const armnn::LogSeverity& level) { m_LoggingSeverity = level; } - void SetLoggingSeverity(const std::string& level) { m_LoggingSeverity = armnn::StringToLogLevel(level); } - - /// Returns the severity level for logging within ArmNN - armnn::LogSeverity GetLoggingSeverity() { return m_LoggingSeverity.value(); } - - bool IsLoggingEnabled() { return m_LoggingSeverity.has_value(); } - - const armnn::OptimizerOptions& GetOptimizerOptions() const { return m_OptimizerOptions; } - - void SetOptimizerOptions(const armnn::OptimizerOptions& optimizerOptions) { m_OptimizerOptions = optimizerOptions; } - - const armnn::Optional& GetDebugCallbackFunction() const - { return m_DebugCallbackFunc; } - - void SetInternalProfilingParams(bool internalProfilingState, - const armnn::ProfilingDetailsMethod& internalProfilingDetail) - { m_InternalProfilingEnabled = internalProfilingState; m_InternalProfilingDetail = internalProfilingDetail; } - - bool GetInternalProfilingState() const { return m_InternalProfilingEnabled; } - const armnn::ProfilingDetailsMethod& GetInternalProfilingDetail() const { return m_InternalProfilingDetail; } - - void SetSerializeToDot(const std::string& serializeToDotFile) { m_SerializeToDot = serializeToDotFile; } - const std::string& GetSerializeToDot() const { return m_SerializeToDot; } - - /// @Note: This might overwrite options that were set with other setter functions of DelegateOptions - void SetRuntimeOptions(const armnn::IRuntime::CreationOptions& runtimeOptions) - { - m_RuntimeOptions = runtimeOptions; - } - - const armnn::IRuntime::CreationOptions& GetRuntimeOptions() - { - return m_RuntimeOptions; - } - - void DisableTfLiteRuntimeFallback(bool fallbackState) - { - m_DisableTfLiteRuntimeFallback = fallbackState; - } - bool TfLiteRuntimeFallbackDisabled() - { - return m_DisableTfLiteRuntimeFallback; - } - -private: - /// Which backend to run Delegate on. - /// Examples of possible values are: CpuRef, CpuAcc, GpuAcc. - /// CpuRef as default. - std::vector m_Backends = { armnn::Compute::CpuRef }; - - /// Creation options for the ArmNN runtime - /// Contains options for global settings that are valid for the whole lifetime of ArmNN - /// i.e. BackendOptions, DynamicBackendPath, ExternalProfilingOptions and more - armnn::IRuntime::CreationOptions m_RuntimeOptions; - - /// Options for the optimization step for the network - armnn::OptimizerOptions m_OptimizerOptions; - - /// Internal profiling options. Written to INetworkProperties during model load. - /// Indicates whether internal profiling is enabled or not. - bool m_InternalProfilingEnabled = false; - /// Sets the level of detail output by the profiling. Options are DetailsWithEvents = 1 and DetailsOnly = 2 - armnn::ProfilingDetailsMethod m_InternalProfilingDetail = armnn::ProfilingDetailsMethod::DetailsWithEvents; - - /// Severity level for logging within ArmNN that will be used on creation of the delegate - armnn::Optional m_LoggingSeverity; - - /// A callback function to debug layers performing custom computations on intermediate tensors. - /// If a function is not registered, and debug is enabled in OptimizerOptions, - /// debug will print information of the intermediate tensors. - armnn::Optional m_DebugCallbackFunc; - - /// If not empty then the optimized model will be serialized to a file with this file name in "dot" format. - std::string m_SerializeToDot = ""; - - /// Option to disable TfLite Runtime fallback for unsupported operators. - bool m_DisableTfLiteRuntimeFallback = false; -}; - -} // namespace armnnDelegate +#include +#pragma message("armnn/delegate/include/DelegateOptions.hpp has been deprecated, it is due for removal in"\ + " 24.02 release. Please use public interface ") \ No newline at end of file diff --git a/delegate/include/Version.hpp b/delegate/include/Version.hpp index 5550278414..687471c8ba 100644 --- a/delegate/include/Version.hpp +++ b/delegate/include/Version.hpp @@ -1,29 +1,8 @@ // -// Copyright © 2021 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2021-2023 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // -#pragma once - -namespace armnnDelegate -{ - -/// Macro utils -#define STRINGIFY_VALUE(s) STRINGIFY_MACRO(s) -#define STRINGIFY_MACRO(s) #s - -// ArmNN Delegate version components -#define DELEGATE_MAJOR_VERSION 28 -#define DELEGATE_MINOR_VERSION 0 -#define DELEGATE_PATCH_VERSION 0 - -/// DELEGATE_VERSION: "X.Y.Z" -/// where: -/// X = Major version number -/// Y = Minor version number -/// Z = Patch version number -#define DELEGATE_VERSION STRINGIFY_VALUE(DELEGATE_MAJOR_VERSION) "." \ - STRINGIFY_VALUE(DELEGATE_MINOR_VERSION) "." \ - STRINGIFY_VALUE(DELEGATE_PATCH_VERSION) - -} //namespace armnnDelegate \ No newline at end of file +#include +#pragma message("armnn/delegate/include/Version.hpp has been deprecated, it is due for removal in"\ + " 24.02 release. Please use public interface ") \ No newline at end of file diff --git a/delegate/include/armnn_delegate.hpp b/delegate/include/armnn_delegate.hpp index 9cfc397550..fd071eb24a 100644 --- a/delegate/include/armnn_delegate.hpp +++ b/delegate/include/armnn_delegate.hpp @@ -3,141 +3,6 @@ // SPDX-License-Identifier: MIT // -#pragma once - -#include "DelegateOptions.hpp" - -#include -#include -#include -#include -#include - -#if TF_MAJOR_VERSION > 2 || (TF_MAJOR_VERSION == 2 && TF_MINOR_VERSION > 3) -#define ARMNN_POST_TFLITE_2_3 -#endif - -#if TF_MAJOR_VERSION > 2 || (TF_MAJOR_VERSION == 2 && TF_MINOR_VERSION > 4) -#define ARMNN_POST_TFLITE_2_4 -#endif - -#if TF_MAJOR_VERSION > 2 || (TF_MAJOR_VERSION == 2 && TF_MINOR_VERSION > 5) -#define ARMNN_POST_TFLITE_2_5 -#endif - -namespace armnnDelegate -{ - -struct DelegateData -{ - DelegateData(const std::vector& backends) - : m_Backends(backends) - , m_Network(nullptr, nullptr) - {} - - const std::vector m_Backends; - armnn::INetworkPtr m_Network; - std::vector m_OutputSlotForNode; -}; - -// Forward decleration for functions initializing the ArmNN Delegate -DelegateOptions TfLiteArmnnDelegateOptionsDefault(); - -TfLiteDelegate* TfLiteArmnnDelegateCreate(armnnDelegate::DelegateOptions options); - -void TfLiteArmnnDelegateDelete(TfLiteDelegate* tfLiteDelegate); - -TfLiteStatus DoPrepare(TfLiteContext* context, TfLiteDelegate* delegate); - -/// ArmNN Delegate -class Delegate -{ - friend class ArmnnSubgraph; -public: - explicit Delegate(armnnDelegate::DelegateOptions options); - - TfLiteIntArray* IdentifyOperatorsToDelegate(TfLiteContext* context); - - TfLiteDelegate* GetDelegate(); - - /// Retrieve version in X.Y.Z form - static const std::string GetVersion(); - -private: - /** - * Returns a pointer to the armnn::IRuntime* this will be shared by all armnn_delegates. - */ - armnn::IRuntime* GetRuntime(const armnn::IRuntime::CreationOptions& options) - { - static armnn::IRuntimePtr instance = armnn::IRuntime::Create(options); - // Instantiated on first use. - return instance.get(); - } - - TfLiteDelegate m_Delegate = { - reinterpret_cast(this), // .data_ - DoPrepare, // .Prepare - nullptr, // .CopyFromBufferHandle - nullptr, // .CopyToBufferHandle - nullptr, // .FreeBufferHandle - kTfLiteDelegateFlagsNone, // .flags - nullptr, // .opaque_delegate_builder - }; - - /// ArmNN Runtime pointer - armnn::IRuntime* m_Runtime; - /// ArmNN Delegate Options - armnnDelegate::DelegateOptions m_Options; -}; - -/// ArmnnSubgraph class where parsing the nodes to ArmNN format and creating the ArmNN Graph -class ArmnnSubgraph -{ -public: - static ArmnnSubgraph* Create(TfLiteContext* tfLiteContext, - const TfLiteDelegateParams* parameters, - const Delegate* delegate); - - TfLiteStatus Prepare(TfLiteContext* tfLiteContext); - - TfLiteStatus Invoke(TfLiteContext* tfLiteContext, TfLiteNode* tfLiteNode); - - static TfLiteStatus VisitNode(DelegateData& delegateData, - TfLiteContext* tfLiteContext, - TfLiteRegistration* tfLiteRegistration, - TfLiteNode* tfLiteNode, - int nodeIndex); - -private: - ArmnnSubgraph(armnn::NetworkId networkId, - armnn::IRuntime* runtime, - std::vector& inputBindings, - std::vector& outputBindings) - : m_NetworkId(networkId), m_Runtime(runtime), m_InputBindings(inputBindings), m_OutputBindings(outputBindings) - {} - - static TfLiteStatus AddInputLayer(DelegateData& delegateData, - TfLiteContext* tfLiteContext, - const TfLiteIntArray* inputs, - std::vector& inputBindings); - - static TfLiteStatus AddOutputLayer(DelegateData& delegateData, - TfLiteContext* tfLiteContext, - const TfLiteIntArray* outputs, - std::vector& outputBindings); - - - /// The Network Id - armnn::NetworkId m_NetworkId; - /// ArmNN Rumtime - armnn::IRuntime* m_Runtime; - - // Binding information for inputs and outputs - std::vector m_InputBindings; - std::vector m_OutputBindings; - -}; - -} // armnnDelegate namespace - - +#include +#pragma message("armnn/delegate/include/armnn_delegate.hpp has been deprecated, it is due for removal in"\ + " 24.02 release. Please use public interface ") \ No newline at end of file -- cgit v1.2.1