aboutsummaryrefslogtreecommitdiff
path: root/src/armnn
diff options
context:
space:
mode:
Diffstat (limited to 'src/armnn')
-rw-r--r--src/armnn/InternalTypes.cpp1
-rw-r--r--src/armnn/InternalTypes.hpp1
-rw-r--r--src/armnn/LayersFwd.hpp2
-rw-r--r--src/armnn/layers/ConvertBf16ToFp32Layer.hpp1
-rw-r--r--src/armnn/layers/ConvertFp16ToFp32Layer.hpp1
-rw-r--r--src/armnn/layers/ConvertFp32ToBf16Layer.cpp55
-rw-r--r--src/armnn/layers/ConvertFp32ToBf16Layer.hpp41
-rw-r--r--src/armnn/layers/ConvertFp32ToFp16Layer.hpp1
8 files changed, 100 insertions, 3 deletions
diff --git a/src/armnn/InternalTypes.cpp b/src/armnn/InternalTypes.cpp
index 3f3eed56e7..d688257142 100644
--- a/src/armnn/InternalTypes.cpp
+++ b/src/armnn/InternalTypes.cpp
@@ -24,6 +24,7 @@ char const* GetLayerTypeAsCString(LayerType type)
case LayerType::Constant: return "Constant";
case LayerType::ConvertBf16ToFp32: return "ConvertBf16ToFp32";
case LayerType::ConvertFp16ToFp32: return "ConvertFp16ToFp32";
+ case LayerType::ConvertFp32ToBf16: return "ConvertFp32ToBf16";
case LayerType::ConvertFp32ToFp16: return "ConvertFp32ToFp16";
case LayerType::Convolution2d: return "Convolution2d";
case LayerType::Debug: return "Debug";
diff --git a/src/armnn/InternalTypes.hpp b/src/armnn/InternalTypes.hpp
index 9330122246..8dd9a9eb1c 100644
--- a/src/armnn/InternalTypes.hpp
+++ b/src/armnn/InternalTypes.hpp
@@ -24,6 +24,7 @@ enum class LayerType
Constant,
ConvertBf16ToFp32,
ConvertFp16ToFp32,
+ ConvertFp32ToBf16,
ConvertFp32ToFp16,
Convolution2d,
Debug,
diff --git a/src/armnn/LayersFwd.hpp b/src/armnn/LayersFwd.hpp
index 3dde908fc3..4159f488c1 100644
--- a/src/armnn/LayersFwd.hpp
+++ b/src/armnn/LayersFwd.hpp
@@ -16,6 +16,7 @@
#include "layers/ConstantLayer.hpp"
#include "layers/ConvertBf16ToFp32Layer.hpp"
#include "layers/ConvertFp16ToFp32Layer.hpp"
+#include "layers/ConvertFp32ToBf16Layer.hpp"
#include "layers/ConvertFp32ToFp16Layer.hpp"
#include "layers/Convolution2dLayer.hpp"
#include "layers/DebugLayer.hpp"
@@ -102,6 +103,7 @@ DECLARE_LAYER(Concat)
DECLARE_LAYER(Constant)
DECLARE_LAYER(ConvertBf16ToFp32)
DECLARE_LAYER(ConvertFp16ToFp32)
+DECLARE_LAYER(ConvertFp32ToBf16)
DECLARE_LAYER(ConvertFp32ToFp16)
DECLARE_LAYER(Convolution2d)
DECLARE_LAYER(Debug)
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;