From 33753901d4c77c958d006fb8e4a283a9a33c4426 Mon Sep 17 00:00:00 2001 From: John Mcloughlin Date: Wed, 7 Feb 2024 15:00:57 +0000 Subject: IVGCVSW-7624 GpuFsa Op: Add Softmax operator * Added softmax operator support * Added test cases Signed-off-by: John Mcloughlin Change-Id: I51d530b110c4cb812f5aab31ad1ee4022d81d19e --- src/backends/backendsCommon/test/CMakeLists.txt | 3 +- .../test/SoftmaxEndToEndTestImpl.hpp | 80 ++++++++++++++++++++++ 2 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 src/backends/backendsCommon/test/SoftmaxEndToEndTestImpl.hpp (limited to 'src/backends/backendsCommon') diff --git a/src/backends/backendsCommon/test/CMakeLists.txt b/src/backends/backendsCommon/test/CMakeLists.txt index 264381d171..7de150dd1d 100644 --- a/src/backends/backendsCommon/test/CMakeLists.txt +++ b/src/backends/backendsCommon/test/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright © 2017-2023 Arm Ltd and Contributors. All rights reserved. +# Copyright © 2017-2024 Arm Ltd and Contributors. All rights reserved. # SPDX-License-Identifier: MIT # @@ -57,6 +57,7 @@ list(APPEND armnnBackendsCommonUnitTests_sources ResizeEndToEndTestImpl.hpp RuntimeTestImpl.hpp SliceEndToEndTestImpl.hpp + SoftmaxEndToEndTestImpl.hpp SpaceToDepthEndToEndTestImpl.cpp SpaceToDepthEndToEndTestImpl.hpp SplitterEndToEndTestImpl.hpp diff --git a/src/backends/backendsCommon/test/SoftmaxEndToEndTestImpl.hpp b/src/backends/backendsCommon/test/SoftmaxEndToEndTestImpl.hpp new file mode 100644 index 0000000000..f3c71f0817 --- /dev/null +++ b/src/backends/backendsCommon/test/SoftmaxEndToEndTestImpl.hpp @@ -0,0 +1,80 @@ +// +// Copyright © 2024 Arm Ltd and Contributors. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#pragma once + +#include + +#include +#include + +#include + +namespace { + +template +armnn::INetworkPtr CreateSoftmaxNetwork(const armnn::TensorShape& inputShape, + const armnn::TensorShape& outputShape, + const armnn::SoftmaxDescriptor& descriptor, + const float qScale = 1.0f, + const int32_t qOffset = 0) +{ + using namespace armnn; + + // Builds up the structure of the network. + INetworkPtr net(INetwork::Create()); + + TensorInfo inputTensorInfo(inputShape, DataType, qScale, qOffset, true); + + IConnectableLayer* Softmax = net->AddSoftmaxLayer(descriptor, "Softmax"); + IConnectableLayer* input = net->AddInputLayer(0, "input"); + Connect(input, Softmax, inputTensorInfo, 0, 0); + + TensorInfo outputTensorInfo(outputShape, DataType, qScale, qOffset); + IConnectableLayer* output = net->AddOutputLayer(0, "output"); + Connect(Softmax, output, outputTensorInfo, 0, 0); + + return net; +} + +template> +void SoftmaxEndToEnd(const std::vector& backends) +{ + using namespace armnn; + + const TensorShape& inputShape = { 2, 2 }; + const TensorShape& outputShape = { 2, 2 }; + + SoftmaxDescriptor softmaxDesc; + softmaxDesc.m_Beta = 1.0f; + softmaxDesc.m_Axis = 1; + + // Builds up the structure of the network + INetworkPtr net = CreateSoftmaxNetwork(inputShape, + outputShape, + softmaxDesc); + + CHECK(net); + + std::vector inputData + { + 17.0f, 16.0f, 5.0f, 14.0f + }; + + std::vector expectedOutputData + { + 0.731059f, 0.268941f, 0.000123f, 0.999877f + }; + + std::map> inputTensorData = { {0, inputData} }; + std::map> expectedOutputTensorData = { {0, expectedOutputData} }; + + EndToEndLayerTestImpl(std::move(net), + inputTensorData, + expectedOutputTensorData, + backends); +} + +} // anonymous namespace \ No newline at end of file -- cgit v1.2.1