From c4fb0dd4145e05123c546458ba5d281abfcc2b28 Mon Sep 17 00:00:00 2001 From: Francis Murtagh Date: Thu, 16 Mar 2023 17:01:56 +0000 Subject: IVGCVSW-7556 Introduce Opaque Delegate API * Also added cmake for the new layers to reduce merge conflicts. Signed-off-by: Francis Murtagh Change-Id: Ieb59aa2b7e2a18c57c9357b8d5b5cd63d8211c85 --- delegate/opaque/src/armnn_delegate.cpp | 136 +++++++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 delegate/opaque/src/armnn_delegate.cpp (limited to 'delegate/opaque/src/armnn_delegate.cpp') diff --git a/delegate/opaque/src/armnn_delegate.cpp b/delegate/opaque/src/armnn_delegate.cpp new file mode 100644 index 0000000000..190c386666 --- /dev/null +++ b/delegate/opaque/src/armnn_delegate.cpp @@ -0,0 +1,136 @@ +// +// Copyright © 2023 Arm Ltd and Contributors. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#include + +#include + +#include "Activation.hpp" +#include "ArgMinMax.hpp" +#include "BatchMatMul.hpp" +#include "BatchSpace.hpp" +#include "Comparison.hpp" +#include "Convolution.hpp" +#include "Control.hpp" +#include "ElementwiseBinary.hpp" +#include "ElementwiseUnary.hpp" +#include "Fill.hpp" +#include "FullyConnected.hpp" +#include "Gather.hpp" +#include "GatherNd.hpp" +#include "LogicalBinary.hpp" +#include "Lstm.hpp" +#include "Normalization.hpp" +#include "Pack.hpp" +#include "Pad.hpp" +#include "Pooling.hpp" +#include "Prelu.hpp" +#include "Quantization.hpp" +#include "Redefine.hpp" +#include "Reduce.hpp" +#include "Resize.hpp" +#include "Round.hpp" +#include "Shape.hpp" +#include "Slice.hpp" +#include "StridedSlice.hpp" +#include "Softmax.hpp" +#include "SpaceDepth.hpp" +#include "Split.hpp" +#include "Transpose.hpp" +#include "UnidirectionalSequenceLstm.hpp" +#include "Unpack.hpp" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +namespace armnnOpaqueDelegate +{ + +ArmnnOpaqueDelegate::ArmnnOpaqueDelegate(armnnDelegate::DelegateOptions options) + : m_Options(std::move(options)) +{ + // Configures logging for ARMNN + if (m_Options.IsLoggingEnabled()) + { + armnn::ConfigureLogging(true, true, m_Options.GetLoggingSeverity()); + } + // Create/Get the static ArmNN Runtime. Note that the m_Runtime will be shared by all armnn_delegate + // instances so the RuntimeOptions cannot be altered for different armnn_delegate instances. + m_Runtime = GetRuntime(m_Options.GetRuntimeOptions()); + std::vector backends; + if (m_Runtime) + { + const armnn::BackendIdSet supportedDevices = m_Runtime->GetDeviceSpec().GetSupportedBackends(); + for (auto& backend : m_Options.GetBackends()) + { + if (std::find(supportedDevices.cbegin(), supportedDevices.cend(), backend) == supportedDevices.cend()) + { + TFLITE_LOG_PROD(tflite::TFLITE_LOG_INFO, + "TfLiteArmnnDelegate: Requested unknown backend %s", backend.Get().c_str()); + } + else + { + backends.push_back(backend); + } + } + } + + if (backends.empty()) + { + // No known backend specified + throw armnn::InvalidArgumentException("TfLiteArmnnOpaqueDelegate: No known backend specified."); + } + m_Options.SetBackends(backends); + + TFLITE_LOG_PROD_ONCE(tflite::TFLITE_LOG_INFO, "TfLiteArmnnOpaqueDelegate: Created TfLite ArmNN delegate."); +} + +TfLiteOpaqueDelegate* TfLiteArmnnOpaqueDelegateCreate(const void* settings) +{ + // This method will always create Opaque Delegate with default settings until + // we have a DelegateOptions Constructor which can parse the void* settings + armnn::IgnoreUnused(settings); + auto options = TfLiteArmnnDelegateOptionsDefault(); + auto* armnnDelegate = new ::armnnOpaqueDelegate::ArmnnOpaqueDelegate(options); + return TfLiteOpaqueDelegateCreate(armnnDelegate->GetDelegateBuilder()); +} + +::armnnDelegate::DelegateOptions TfLiteArmnnDelegateOptionsDefault() +{ + ::armnnDelegate::DelegateOptions options(armnn::Compute::CpuRef); + return options; +} + +void TfLiteArmnnOpaqueDelegateDelete(TfLiteOpaqueDelegate* tfLiteDelegate) +{ + if (tfLiteDelegate != nullptr) + { + delete static_cast<::armnnOpaqueDelegate::ArmnnOpaqueDelegate*>(TfLiteOpaqueDelegateGetData(tfLiteDelegate)); + TfLiteOpaqueDelegateDelete(tfLiteDelegate); + } +} + +const TfLiteOpaqueDelegatePlugin* GetArmnnDelegatePluginApi() +{ + static constexpr TfLiteOpaqueDelegatePlugin armnnPlugin{ + TfLiteArmnnOpaqueDelegateCreate, TfLiteArmnnOpaqueDelegateDelete, TfLiteArmnnOpaqueDelegateErrno}; + return &armnnPlugin; +} + +const std::string ArmnnOpaqueDelegate::GetVersion() { + return OPAQUE_DELEGATE_VERSION; +} + +} // armnnOpaqueDelegate namespace \ No newline at end of file -- cgit v1.2.1