// // Copyright © 2019 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // #include "LogSoftmaxTestImpl.hpp" #include #include #include #include #include #include #include #include #include namespace { template> LayerTestResult LogSoftmaxTestImpl( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory, const armnn::TensorInfo& inputInfo, const armnn::TensorInfo& outputInfo, const std::vector& inputValues, const std::vector& expectedOutputValues, armnn::LogSoftmaxQueueDescriptor descriptor, float qScale = 1.0f, int32_t qOffset = 0) { IgnoreUnused(memoryManager); auto inputTensor = armnnUtils::QuantizedVector(inputValues, qScale, qOffset); std::vector actualOutput(outputInfo.GetNumElements()); std::vector expectedOutput = armnnUtils::QuantizedVector(expectedOutputValues, qScale, qOffset); std::unique_ptr inputHandle = tensorHandleFactory.CreateTensorHandle(inputInfo); std::unique_ptr outputHandle = tensorHandleFactory.CreateTensorHandle(outputInfo); armnn::WorkloadInfo info; AddInputToWorkload(descriptor, info, inputInfo, inputHandle.get()); AddOutputToWorkload(descriptor, info, outputInfo, outputHandle.get()); std::unique_ptr workload = workloadFactory.CreateWorkload(armnn::LayerType::LogSoftmax, descriptor, info); inputHandle->Allocate(); outputHandle->Allocate(); CopyDataToITensorHandle(inputHandle.get(), inputTensor.data()); ExecuteWorkload(*workload, memoryManager); CopyDataFromITensorHandle(actualOutput.data(), outputHandle.get()); return LayerTestResult(actualOutput, expectedOutput, outputHandle->GetShape(), outputInfo.GetShape()); } } // anonymous namespace template LayerTestResult LogSoftmaxTest1( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { const armnn::TensorShape inputOutputShape{1, 1, 2, 4}; armnn::TensorInfo inputTensorInfo(inputOutputShape, ArmnnType); armnn::TensorInfo outputTensorInfo(inputOutputShape, ArmnnType); std::vector inputValues { 0.f, -6.f, 2.f, 4.f, 3.f, -2.f, 10.f, 1.f }; std::vector expectedOutputValues { -4.14297f, -10.14297f, -2.14297f, -0.14297f, -7.00104f, -12.00104f, -0.00105f, -9.00104f }; armnn::LogSoftmaxQueueDescriptor descriptor; descriptor.m_Parameters.m_Beta = 1.0f; // default beta descriptor.m_Parameters.m_Axis = -1; // default axis return LogSoftmaxTestImpl( workloadFactory, memoryManager, tensorHandleFactory, inputTensorInfo, outputTensorInfo, inputValues, expectedOutputValues, descriptor); } template LayerTestResult LogSoftmaxTest2( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { const armnn::TensorShape inputOutputShape{1, 1, 2, 4}; armnn::TensorInfo inputTensorInfo(inputOutputShape, ArmnnType); armnn::TensorInfo outputTensorInfo(inputOutputShape, ArmnnType); std::vector inputValues { 0.f, -6.f, 2.f, 4.f, 3.f, -2.f, 10.f, 1.f }; std::vector expectedOutputValues { -4.14297f, -10.14297f, -2.14297f, -0.14297f, -7.00104f, -12.00104f, -0.00105f, -9.00104f }; armnn::LogSoftmaxQueueDescriptor descriptor; descriptor.m_Parameters.m_Beta = 1.0f; // default beta descriptor.m_Parameters.m_Axis = 3; // positive axis return LogSoftmaxTestImpl( workloadFactory, memoryManager, tensorHandleFactory, inputTensorInfo, outputTensorInfo, inputValues, expectedOutputValues, descriptor); } template LayerTestResult LogSoftmaxTest3( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { const armnn::TensorShape inputOutputShape{1, 1, 2, 4}; armnn::TensorInfo inputTensorInfo(inputOutputShape, ArmnnType); armnn::TensorInfo outputTensorInfo(inputOutputShape, ArmnnType); std::vector inputValues { 0.0f, -0.6f, 0.2f, 0.4f, 0.3f, -0.2f, 1.0f, 0.1f }; std::vector expectedOutputValues { -4.14297f, -10.14297f, -2.14297f, -0.14297f, -7.00104f, -12.00104f, -0.00105f, -9.00104f }; armnn::LogSoftmaxQueueDescriptor descriptor; descriptor.m_Parameters.m_Beta = 10.0f; // non-default beta descriptor.m_Parameters.m_Axis = 3; // positive axis return LogSoftmaxTestImpl( workloadFactory, memoryManager, tensorHandleFactory, inputTensorInfo, outputTensorInfo, inputValues, expectedOutputValues, descriptor); } template LayerTestResult LogSoftmaxTest4( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { const armnn::TensorShape inputOutputShape{1, 1, 2, 4}; armnn::TensorInfo inputTensorInfo(inputOutputShape, ArmnnType); armnn::TensorInfo outputTensorInfo(inputOutputShape, ArmnnType); std::vector inputValues { 0.f, -6.f, 2.f, 4.f, 3.f, -2.f, 10.f, 1.f }; std::vector expectedOutputValues { -3.048587f, -4.018149f, -8.000336f, -0.048587f, -0.048587f, -0.018149f, -0.000335f, -3.048587f }; armnn::LogSoftmaxQueueDescriptor descriptor; descriptor.m_Parameters.m_Beta = 1.0f; // default beta descriptor.m_Parameters.m_Axis = -2; // negative axis return LogSoftmaxTestImpl( workloadFactory, memoryManager, tensorHandleFactory, inputTensorInfo, outputTensorInfo, inputValues, expectedOutputValues, descriptor); } template LayerTestResult, 4> LogSoftmaxTest1( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory); template LayerTestResult, 4> LogSoftmaxTest2( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory); template LayerTestResult, 4> LogSoftmaxTest3( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory); template LayerTestResult, 4> LogSoftmaxTest4( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory); template LayerTestResult, 4> LogSoftmaxTest1( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory); template LayerTestResult, 4> LogSoftmaxTest2( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory); template LayerTestResult, 4> LogSoftmaxTest3( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory); template LayerTestResult, 4> LogSoftmaxTest4( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory);