xref: /aosp_15_r20/external/armnn/src/armnn/layers/DebugLayer.cpp (revision 89c4ff92f2867872bb9e2354d150bf0c8c502810)
1 //
2 // Copyright © 2017 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 #include "DebugLayer.hpp"
6 
7 #include "LayerCloneBase.hpp"
8 
9 #include <armnn/backends/WorkloadData.hpp>
10 #include <armnn/backends/WorkloadFactory.hpp>
11 
12 namespace armnn
13 {
14 
DebugLayer(const char * name)15 DebugLayer::DebugLayer(const char* name)
16     : Layer(1, 1, LayerType::Debug, name),
17       m_ToFile(false)
18 {}
19 
DebugLayer(const char * name,bool toFile)20 DebugLayer::DebugLayer(const char* name, bool toFile)
21     : Layer(1, 1, LayerType::Debug, name),
22       m_ToFile(toFile)
23 {}
24 
CreateWorkload(const IWorkloadFactory & factory) const25 std::unique_ptr<IWorkload> DebugLayer::CreateWorkload(const IWorkloadFactory& factory) const
26 {
27     const Layer& prevLayer = GetInputSlot(0).GetConnectedOutputSlot()->GetOwningLayer();
28 
29     DebugQueueDescriptor descriptor;
30     descriptor.m_Guid = prevLayer.GetGuid();
31     descriptor.m_LayerName = prevLayer.GetNameStr();
32     descriptor.m_SlotIndex = GetInputSlot(0).GetConnectedOutputSlot()->CalculateIndexOnOwner();
33     descriptor.m_LayerOutputToFile = m_ToFile;
34 
35     SetAdditionalInfo(descriptor);
36 
37     return factory.CreateWorkload(LayerType::Debug, descriptor, PrepInfoAndDesc(descriptor));
38 }
39 
Clone(Graph & graph) const40 DebugLayer* DebugLayer::Clone(Graph& graph) const
41 {
42     return CloneBase<DebugLayer>(graph, GetName());
43 }
44 
ValidateTensorShapesFromInputs()45 void DebugLayer::ValidateTensorShapesFromInputs()
46 {
47     VerifyLayerConnections(1, CHECK_LOCATION());
48 
49     const TensorShape& outputShape = GetOutputSlot(0).GetTensorInfo().GetShape();
50 
51     VerifyShapeInferenceType(outputShape, m_ShapeInferenceMethod);
52 
53     std::vector<TensorShape> inferredShapes = InferOutputShapes({
54         GetInputSlot(0).GetConnection()->GetTensorInfo().GetShape() });
55 
56     ARMNN_ASSERT(inferredShapes.size() == 1);
57 
58     ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "DebugLayer");
59 }
60 
ExecuteStrategy(IStrategy & strategy) const61 void DebugLayer::ExecuteStrategy(IStrategy& strategy) const
62 {
63     strategy.ExecuteStrategy(this, GetParameters(), {}, GetName());
64 }
65 
66 } // namespace armnn
67