diff options
Diffstat (limited to 'src/armnn/layers')
-rw-r--r-- | src/armnn/layers/ConvertBf16ToFp32Layer.hpp | 1 | ||||
-rw-r--r-- | src/armnn/layers/ConvertFp16ToFp32Layer.hpp | 1 | ||||
-rw-r--r-- | src/armnn/layers/ConvertFp32ToBf16Layer.cpp | 55 | ||||
-rw-r--r-- | src/armnn/layers/ConvertFp32ToBf16Layer.hpp | 41 | ||||
-rw-r--r-- | src/armnn/layers/ConvertFp32ToFp16Layer.hpp | 1 |
5 files changed, 96 insertions, 3 deletions
diff --git a/src/armnn/layers/ConvertBf16ToFp32Layer.hpp b/src/armnn/layers/ConvertBf16ToFp32Layer.hpp index 2a79a1cb65..b419e5c2a3 100644 --- a/src/armnn/layers/ConvertBf16ToFp32Layer.hpp +++ b/src/armnn/layers/ConvertBf16ToFp32Layer.hpp @@ -15,7 +15,6 @@ class ConvertBf16ToFp32Layer : public Layer { public: /// Makes a workload for the ConvertBf16ToFp32 type. - /// @param [in] graph The graph where this layer can be found. /// @param [in] factory The workload factory which will create the workload. /// @return A pointer to the created workload, or nullptr if not created. virtual std::unique_ptr<IWorkload> CreateWorkload(const IWorkloadFactory& factory) const override; diff --git a/src/armnn/layers/ConvertFp16ToFp32Layer.hpp b/src/armnn/layers/ConvertFp16ToFp32Layer.hpp index 03d7dfa568..e3b798beec 100644 --- a/src/armnn/layers/ConvertFp16ToFp32Layer.hpp +++ b/src/armnn/layers/ConvertFp16ToFp32Layer.hpp @@ -15,7 +15,6 @@ class ConvertFp16ToFp32Layer : public Layer { public: /// Makes a workload for the ConvertFp16ToFp32 type. - /// @param [in] graph The graph where this layer can be found. /// @param [in] factory The workload factory which will create the workload. /// @return A pointer to the created workload, or nullptr if not created. virtual std::unique_ptr<IWorkload> CreateWorkload(const IWorkloadFactory& factory) const override; diff --git a/src/armnn/layers/ConvertFp32ToBf16Layer.cpp b/src/armnn/layers/ConvertFp32ToBf16Layer.cpp new file mode 100644 index 0000000000..936acf61ab --- /dev/null +++ b/src/armnn/layers/ConvertFp32ToBf16Layer.cpp @@ -0,0 +1,55 @@ +// +// Copyright © 2020 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#include "ConvertFp32ToBf16Layer.hpp" +#include "LayerCloneBase.hpp" + +#include <armnn/TypesUtils.hpp> + +#include <backendsCommon/WorkloadData.hpp> +#include <backendsCommon/WorkloadFactory.hpp> + +namespace armnn +{ + +ConvertFp32ToBf16Layer::ConvertFp32ToBf16Layer(const char* name) + : Layer(1, 1, LayerType::ConvertFp32ToBf16, name) +{ +} + +std::unique_ptr<IWorkload> ConvertFp32ToBf16Layer::CreateWorkload(const IWorkloadFactory& factory) const +{ + ConvertFp32ToBf16QueueDescriptor descriptor; + return factory.CreateConvertFp32ToBf16(descriptor, PrepInfoAndDesc(descriptor)); +} + +ConvertFp32ToBf16Layer* ConvertFp32ToBf16Layer::Clone(Graph& graph) const +{ + return CloneBase<ConvertFp32ToBf16Layer>(graph, GetName()); +} + +void ConvertFp32ToBf16Layer::ValidateTensorShapesFromInputs() +{ + VerifyLayerConnections(1, CHECK_LOCATION()); + + auto inferredShapes = InferOutputShapes({ GetInputSlot(0).GetConnection()->GetTensorInfo().GetShape() }); + + BOOST_ASSERT(inferredShapes.size() == 1); + + ConditionalThrowIfNotEqual<LayerValidationException>( + "ConvertFp32ToBf16Layer: TensorShape set on OutputSlot[0] does not match the inferred shape.", + GetOutputSlot(0).GetTensorInfo().GetShape(), + inferredShapes[0]); +} + +void ConvertFp32ToBf16Layer::Accept(ILayerVisitor& visitor) const +{ + // these conversion layers are only inserted by the + // optimizer and so will never be in an input graph. + IgnoreUnused(visitor); + throw armnn::Exception("ConvertFp32ToBf16Layer should never appear in an input graph"); +} + +} // namespace armnn diff --git a/src/armnn/layers/ConvertFp32ToBf16Layer.hpp b/src/armnn/layers/ConvertFp32ToBf16Layer.hpp new file mode 100644 index 0000000000..225b03314e --- /dev/null +++ b/src/armnn/layers/ConvertFp32ToBf16Layer.hpp @@ -0,0 +1,41 @@ +// +// Copyright © 2020 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#pragma once + +#include <Layer.hpp> + +namespace armnn +{ + +/// This layer converts data type Float32 to BFloat16. +class ConvertFp32ToBf16Layer : public Layer +{ +public: + /// Makes a workload for the ConvertFp32ToBf16Layer type. + /// @param [in] factory The workload factory which will create the workload. + /// @return A pointer to the created workload, or nullptr if not created. + virtual std::unique_ptr<IWorkload> CreateWorkload(const IWorkloadFactory& factory) const override; + + /// Creates a dynamically-allocated copy of this layer. + /// @param [in] graph The graph into which this layer is being cloned. + ConvertFp32ToBf16Layer* Clone(Graph& graph) const override; + + /// Check if the input tensor shape(s) + /// will lead to a valid configuration of @ref ConvertFp32ToBf16Layer. + void ValidateTensorShapesFromInputs() override; + + void Accept(ILayerVisitor& visitor) const override; + +protected: + /// Constructor to create a ConvertFp32ToBf16Layer. + /// @param [in] name Optional name for the layer. + ConvertFp32ToBf16Layer(const char* name); + + /// Default destructor + ~ConvertFp32ToBf16Layer() = default; +}; + +} // namespace diff --git a/src/armnn/layers/ConvertFp32ToFp16Layer.hpp b/src/armnn/layers/ConvertFp32ToFp16Layer.hpp index 907a55f084..8bb28f84ad 100644 --- a/src/armnn/layers/ConvertFp32ToFp16Layer.hpp +++ b/src/armnn/layers/ConvertFp32ToFp16Layer.hpp @@ -14,7 +14,6 @@ class ConvertFp32ToFp16Layer : public Layer { public: /// Makes a workload for the ConvertFp32ToFp16 type. - /// @param [in] graph The graph where this layer can be found. /// @param [in] factory The workload factory which will create the workload. /// @return A pointer to the created workload, or nullptr if not created. virtual std::unique_ptr<IWorkload> CreateWorkload(const IWorkloadFactory& factory) const override; |