}
}
-inline unsigned int ComputeSoftmaxAclAxis(const SoftmaxDescriptor& softmaxDesc, const armnn::TensorInfo& tensor)
+template<typename T>
+inline T ComputeSoftmaxAclAxis(const SoftmaxDescriptor& softmaxDesc, const armnn::TensorInfo& tensor)
{
// Detect the Android default value of -1 and return the ACL default value of 1.
if (softmaxDesc.m_Axis == -1)
ARMNN_ASSERT(dim != 0);
// Currently ArmNN support axis 1.
- return dim - 1;
+ return static_cast<T>(dim) - 1;
}
inline std::set<unsigned int> ComputeSplitAxis(const armnn::SplitterDescriptor& desc, const TensorShape& input)
#include "workloads/ClQuantizedLstmWorkload.hpp"
#include "workloads/ClQuantizeWorkload.hpp"
#include "workloads/ClSliceWorkload.hpp"
-#include "workloads/ClSoftmaxBaseWorkload.hpp"
+#include "workloads/ClSoftmaxWorkload.hpp"
#include "workloads/ClSpaceToBatchNdWorkload.hpp"
#include "workloads/ClSpaceToDepthWorkload.hpp"
#include "workloads/ClSplitterWorkload.hpp"
std::unique_ptr<IWorkload> ClWorkloadFactory::CreateSoftmax(const SoftmaxQueueDescriptor& descriptor,
const WorkloadInfo& info) const
{
- return MakeWorkload<ClSoftmaxFloatWorkload, ClSoftmaxUint8Workload>(descriptor, info,
- m_MemoryManager->GetIntraLayerManager());
+ return std::make_unique<ClSoftmaxWorkload>(descriptor, info, m_MemoryManager->GetIntraLayerManager());
}
std::unique_ptr<IWorkload> ClWorkloadFactory::CreateSpaceToBatchNd(const SpaceToBatchNdQueueDescriptor& descriptor,
workloads/ClResizeWorkload.cpp \
workloads/ClRsqrtWorkload.cpp \
workloads/ClSliceWorkload.cpp \
- workloads/ClSoftmaxBaseWorkload.cpp \
- workloads/ClSoftmaxFloatWorkload.cpp \
- workloads/ClSoftmaxUint8Workload.cpp \
+ workloads/ClSoftmaxWorkload.cpp \
workloads/ClSpaceToBatchNdWorkload.cpp \
workloads/ClSpaceToDepthWorkload.cpp \
workloads/ClSplitterWorkload.cpp \
auto inputHandle = PolymorphicDowncast<IClTensorHandle*>(queueDescriptor.m_Inputs[0]);
auto outputHandle = PolymorphicDowncast<IClTensorHandle*>(queueDescriptor.m_Outputs[0]);
+ armnn::TensorInfo tensorInfo({4, 1}, DataType);
+ if (DataType == armnn::DataType::QAsymmU8)
+ {
+ tensorInfo.SetQuantizationOffset(0);
+ tensorInfo.SetQuantizationScale(1.f / 256);
+ }
+ else if (DataType == armnn::DataType::QAsymmS8)
+ {
+ tensorInfo.SetQuantizationOffset(-128);
+ tensorInfo.SetQuantizationScale(1.f / 256);
+ }
+
BOOST_TEST(CompareIClTensorHandleShape(inputHandle, {4, 1}));
BOOST_TEST(CompareIClTensorHandleShape(outputHandle, {4, 1}));
}
-BOOST_AUTO_TEST_CASE(CreateSoftmaxFloatWorkloadTest)
+BOOST_AUTO_TEST_CASE(CreateSoftmaxFloat32WorkloadTest)
{
- ClSoftmaxWorkloadTest<ClSoftmaxFloatWorkload, armnn::DataType::Float32>();
+ ClSoftmaxWorkloadTest<ClSoftmaxWorkload, armnn::DataType::Float32>();
}
BOOST_AUTO_TEST_CASE(CreateSoftmaxFloat16WorkloadTest)
{
- ClSoftmaxWorkloadTest<ClSoftmaxFloatWorkload, armnn::DataType::Float16>();
+ ClSoftmaxWorkloadTest<ClSoftmaxWorkload, armnn::DataType::Float16>();
+}
+
+BOOST_AUTO_TEST_CASE(CreateSoftmaxQAsymmU8Workload)
+{
+ ClSoftmaxWorkloadTest<ClSoftmaxWorkload, armnn::DataType::QAsymmU8>();
+}
+
+BOOST_AUTO_TEST_CASE(CreateSoftmaxQAsymmS8Workload)
+{
+ ClSoftmaxWorkloadTest<ClSoftmaxWorkload, armnn::DataType::QAsymmS8>();
}
template <typename armnn::DataType DataType>
ClRsqrtWorkload.hpp
ClSliceWorkload.cpp
ClSliceWorkload.hpp
- ClSoftmaxBaseWorkload.cpp
- ClSoftmaxBaseWorkload.hpp
- ClSoftmaxFloatWorkload.cpp
- ClSoftmaxFloatWorkload.hpp
- ClSoftmaxUint8Workload.cpp
- ClSoftmaxUint8Workload.hpp
+ ClSoftmaxWorkload.cpp
+ ClSoftmaxWorkload.hpp
ClSpaceToBatchNdWorkload.hpp
ClSpaceToBatchNdWorkload.cpp
ClSpaceToDepthWorkload.cpp
+++ /dev/null
-//
-// Copyright © 2017 Arm Ltd. All rights reserved.
-// SPDX-License-Identifier: MIT
-//
-
-#include "ClSoftmaxBaseWorkload.hpp"
-
-#include <aclCommon/ArmComputeTensorUtils.hpp>
-#include <aclCommon/ArmComputeUtils.hpp>
-
-#include <arm_compute/runtime/CL/functions/CLSoftmaxLayer.h>
-
-namespace armnn
-{
-
-arm_compute::Status ClSoftmaxWorkloadValidate(const TensorInfo& input,
- const TensorInfo& output,
- const SoftmaxDescriptor& descriptor)
-{
- const arm_compute::TensorInfo aclInputInfo = armcomputetensorutils::BuildArmComputeTensorInfo(input);
- const arm_compute::TensorInfo aclOutputInfo = armcomputetensorutils::BuildArmComputeTensorInfo(output);
-
- unsigned int aclAxis = ComputeSoftmaxAclAxis(descriptor, input);
- return arm_compute::CLSoftmaxLayer::validate(&aclInputInfo, &aclOutputInfo, descriptor.m_Beta, aclAxis);
-}
-
-}
+++ /dev/null
-//
-// Copyright © 2017 Arm Ltd. All rights reserved.
-// SPDX-License-Identifier: MIT
-//
-
-#pragma once
-
-#include <armnn/Descriptors.hpp>
-#include <armnn/Tensor.hpp>
-#include <arm_compute/core/Error.h>
-
-namespace armnn
-{
-
-arm_compute::Status ClSoftmaxWorkloadValidate(const TensorInfo& input,
- const TensorInfo& output,
- const SoftmaxDescriptor& descriptor);
-
-} // namespace armnn
+++ /dev/null
-//
-// Copyright © 2017 Arm Ltd. All rights reserved.
-// SPDX-License-Identifier: MIT
-//
-
-#include "ClSoftmaxFloatWorkload.hpp"
-#include "ClWorkloadUtils.hpp"
-
-#include <aclCommon/ArmComputeUtils.hpp>
-#include <cl/ClTensorHandle.hpp>
-#include <backendsCommon/CpuTensorHandle.hpp>
-
-namespace armnn
-{
-
-ClSoftmaxFloatWorkload::ClSoftmaxFloatWorkload(const SoftmaxQueueDescriptor& descriptor, const WorkloadInfo& info,
- std::shared_ptr<arm_compute::MemoryManagerOnDemand>& memoryManager)
- : FloatWorkload<SoftmaxQueueDescriptor>(descriptor, info)
- , m_SoftmaxLayer(memoryManager)
-{
- m_Data.ValidateInputsOutputs("ClSoftmaxFloatWorkload", 1, 1);
-
- arm_compute::ICLTensor& input = static_cast<ClTensorHandle*>(m_Data.m_Inputs[0])->GetTensor();
- arm_compute::ICLTensor& output = static_cast<ClTensorHandle*>(m_Data.m_Outputs[0])->GetTensor();
-
- unsigned int aclAxis = ComputeSoftmaxAclAxis(m_Data.m_Parameters, info.m_InputTensorInfos[0]);
- m_SoftmaxLayer.configure(&input, &output, m_Data.m_Parameters.m_Beta, aclAxis);
-}
-
-void ClSoftmaxFloatWorkload::Execute() const
-{
- ARMNN_SCOPED_PROFILING_EVENT_CL("ClSoftmaxFloatWorkload_Execute");
- RunClFunction(m_SoftmaxLayer, CHECK_LOCATION());
-}
-
-} //namespace armnn
+++ /dev/null
-//
-// Copyright © 2017 Arm Ltd. All rights reserved.
-// SPDX-License-Identifier: MIT
-//
-
-#pragma once
-
-#include <backendsCommon/Workload.hpp>
-
-#include <arm_compute/runtime/CL/functions/CLSoftmaxLayer.h>
-#include <arm_compute/runtime/MemoryManagerOnDemand.h>
-
-#include <memory>
-
-namespace armnn
-{
-
-class ClSoftmaxFloatWorkload : public FloatWorkload<SoftmaxQueueDescriptor>
-{
-public:
- ClSoftmaxFloatWorkload(const SoftmaxQueueDescriptor& descriptor, const WorkloadInfo& info,
- std::shared_ptr<arm_compute::MemoryManagerOnDemand>& memoryManager);
- void Execute() const override;
-
-private:
- mutable arm_compute::CLSoftmaxLayer m_SoftmaxLayer;
-};
-
-} //namespace armnn
-
+++ /dev/null
-//
-// Copyright © 2017 Arm Ltd. All rights reserved.
-// SPDX-License-Identifier: MIT
-//
-
-#include "ClSoftmaxUint8Workload.hpp"
-#include "ClWorkloadUtils.hpp"
-
-#include <aclCommon/ArmComputeUtils.hpp>
-#include <cl/ClTensorHandle.hpp>
-#include <backendsCommon/CpuTensorHandle.hpp>
-
-namespace armnn
-{
-
-ClSoftmaxUint8Workload::ClSoftmaxUint8Workload(const SoftmaxQueueDescriptor& descriptor, const WorkloadInfo& info,
- std::shared_ptr<arm_compute::MemoryManagerOnDemand>& memoryManager)
- : Uint8Workload<SoftmaxQueueDescriptor>(descriptor, info)
- , m_SoftmaxLayer(memoryManager)
-{
- m_Data.ValidateInputsOutputs("ClSoftmaxUint8Workload", 1, 1);
-
- arm_compute::ICLTensor& input = static_cast<ClTensorHandle*>(m_Data.m_Inputs[0])->GetTensor();
- arm_compute::ICLTensor& output = static_cast<ClTensorHandle*>(m_Data.m_Outputs[0])->GetTensor();
-
- const auto outputQuantization = output.info()->quantization_info();
-
- if ((!outputQuantization.scale().empty() && outputQuantization.scale()[0] != (1.0f / 256.0f)) ||
- (!outputQuantization.offset().empty() && outputQuantization.offset()[0] != 0) ||
- outputQuantization.scale().empty() || outputQuantization.offset().empty())
- {
- throw InvalidArgumentException(
- "Invalid quantization for output. Only scale = 1.0f / 256.0f and offset = 0 supported");
- }
-
- unsigned int aclAxis = ComputeSoftmaxAclAxis(m_Data.m_Parameters, info.m_InputTensorInfos[0]);
- m_SoftmaxLayer.configure(&input, &output, descriptor.m_Parameters.m_Beta, aclAxis);
-}
-
-void ClSoftmaxUint8Workload::Execute() const
-{
- ARMNN_SCOPED_PROFILING_EVENT_CL("ClSoftmaxUint8Workload_Execute");
- RunClFunction(m_SoftmaxLayer, CHECK_LOCATION());
-}
-
-} //namespace armnn
+++ /dev/null
-//
-// Copyright © 2017 Arm Ltd. All rights reserved.
-// SPDX-License-Identifier: MIT
-//
-
-#pragma once
-
-#include <backendsCommon/Workload.hpp>
-
-#include <arm_compute/runtime/CL/functions/CLSoftmaxLayer.h>
-#include <arm_compute/runtime/MemoryManagerOnDemand.h>
-
-#include <memory>
-
-namespace armnn
-{
-// Softmax
-class ClSoftmaxUint8Workload : public Uint8Workload<SoftmaxQueueDescriptor>
-{
-public:
- ClSoftmaxUint8Workload(const SoftmaxQueueDescriptor& descriptor, const WorkloadInfo& info,
- std::shared_ptr<arm_compute::MemoryManagerOnDemand>& memoryManager);
-
- void Execute() const override;
-private:
-
- mutable arm_compute::CLSoftmaxLayer m_SoftmaxLayer;
-};
-
-} //namespace armnn
-
--- /dev/null
+//
+// Copyright © 2020 Arm Ltd. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#include "ClSoftmaxWorkload.hpp"
+#include "ClWorkloadUtils.hpp"
+
+#include <aclCommon/ArmComputeTensorUtils.hpp>
+#include <aclCommon/ArmComputeUtils.hpp>
+
+#include <cl/ClTensorHandle.hpp>
+
+namespace armnn
+{
+
+arm_compute::Status ClSoftmaxWorkloadValidate(const TensorInfo& input,
+ const TensorInfo& output,
+ const SoftmaxDescriptor& descriptor)
+{
+ const arm_compute::TensorInfo aclInputInfo = armcomputetensorutils::BuildArmComputeTensorInfo(input);
+ const arm_compute::TensorInfo aclOutputInfo = armcomputetensorutils::BuildArmComputeTensorInfo(output);
+
+ unsigned int aclAxis = ComputeSoftmaxAclAxis<unsigned int>(descriptor, input);
+ return arm_compute::CLSoftmaxLayer::validate(&aclInputInfo, &aclOutputInfo, descriptor.m_Beta, aclAxis);
+}
+
+ClSoftmaxWorkload::ClSoftmaxWorkload(const SoftmaxQueueDescriptor& descriptor, const WorkloadInfo& info,
+ std::shared_ptr<arm_compute::MemoryManagerOnDemand>& memoryManager)
+ : BaseWorkload<SoftmaxQueueDescriptor>(descriptor, info)
+ , m_SoftmaxLayer(memoryManager)
+{
+ m_Data.ValidateInputsOutputs("ClSoftmaxWorkload", 1, 1);
+
+ arm_compute::ICLTensor& input = static_cast<ClTensorHandle*>(m_Data.m_Inputs[0])->GetTensor();
+ arm_compute::ICLTensor& output = static_cast<ClTensorHandle*>(m_Data.m_Outputs[0])->GetTensor();
+
+ unsigned int aclAxis = ComputeSoftmaxAclAxis<unsigned int>(m_Data.m_Parameters, info.m_InputTensorInfos[0]);
+ m_SoftmaxLayer.configure(&input, &output, m_Data.m_Parameters.m_Beta, aclAxis);
+}
+
+void ClSoftmaxWorkload::Execute() const
+{
+ ARMNN_SCOPED_PROFILING_EVENT_CL("ClSoftmaxWorkload_Execute");
+ RunClFunction(m_SoftmaxLayer, CHECK_LOCATION());
+}
+
+} // namespace armnn
--- /dev/null
+//
+// Copyright © 2020 Arm Ltd. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#pragma once
+
+#include <armnn/Descriptors.hpp>
+
+#include <arm_compute/core/Error.h>
+#include <arm_compute/runtime/MemoryManagerOnDemand.h>
+#include <arm_compute/runtime/CL/functions/CLSoftmaxLayer.h>
+
+#include <backendsCommon/Workload.hpp>
+
+namespace armnn
+{
+
+arm_compute::Status ClSoftmaxWorkloadValidate(const TensorInfo& input,
+ const TensorInfo& output,
+ const SoftmaxDescriptor& descriptor);
+
+class ClSoftmaxWorkload : public BaseWorkload<SoftmaxQueueDescriptor>
+{
+public:
+ ClSoftmaxWorkload(const SoftmaxQueueDescriptor& descriptor, const WorkloadInfo& info,
+ std::shared_ptr<arm_compute::MemoryManagerOnDemand>& memoryManager);
+ void Execute() const override;
+
+private:
+ mutable arm_compute::CLSoftmaxLayer m_SoftmaxLayer;
+};
+
+} // namespace armnn
#include "ClResizeWorkload.hpp"
#include "ClRsqrtWorkload.hpp"
#include "ClSliceWorkload.hpp"
-#include "ClSoftmaxFloatWorkload.hpp"
-#include "ClSoftmaxUint8Workload.hpp"
+#include "ClSoftmaxWorkload.hpp"
#include "ClSpaceToBatchNdWorkload.hpp"
#include "ClSpaceToDepthWorkload.hpp"
#include "ClSplitterWorkload.hpp"
const arm_compute::TensorInfo aclInputInfo = armcomputetensorutils::BuildArmComputeTensorInfo(input);
const arm_compute::TensorInfo aclOutputInfo = armcomputetensorutils::BuildArmComputeTensorInfo(output);
- unsigned int aclAxis = ComputeSoftmaxAclAxis(descriptor, input);
+ unsigned int aclAxis = ComputeSoftmaxAclAxis<unsigned int>(descriptor, input);
return arm_compute::NESoftmaxLayer::validate(&aclInputInfo, &aclOutputInfo, descriptor.m_Beta, aclAxis);
}
arm_compute::ITensor& output = PolymorphicDowncast<IAclTensorHandle*>(m_Data.m_Outputs[0])->GetTensor();
auto layer = std::make_unique<arm_compute::NESoftmaxLayer>(memoryManager);
- unsigned int aclAxis = ComputeSoftmaxAclAxis(m_Data.m_Parameters, info.m_InputTensorInfos[0]);
+ unsigned int aclAxis = ComputeSoftmaxAclAxis<unsigned int>(m_Data.m_Parameters, info.m_InputTensorInfos[0]);
layer->configure(&input, &output, m_Data.m_Parameters.m_Beta, aclAxis);
m_SoftmaxLayer.reset(layer.release());
}