ArmNN
 23.08
WorkloadFactory.hpp
Go to the documentation of this file.
1 //
2 // Copyright © 2021-2023 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 #pragma once
6 
7 #include "ITensorHandle.hpp"
8 #include "Workload.hpp"
9 
10 #include <armnn/Optional.hpp>
11 #include <armnn/INetwork.hpp>
12 #include <armnn/TensorFwd.hpp>
13 
14 #include <memory>
15 
16 namespace armnn
17 {
18 
19 class Layer;
20 
21 // Workload factory interface for compute backends.
23 {
24 public:
25  virtual ~IWorkloadFactory() { }
26 
27  virtual void AfterWorkloadsCreated() {};
28 
29  virtual const BackendId& GetBackendId() const = 0;
30 
31  static bool IsLayerSupported(const BackendId& backendId,
32  const IConnectableLayer& layer,
33  Optional<DataType> dataType,
34  std::string& outReasonIfUnsupported);
35 
36  static bool IsLayerSupported(const IConnectableLayer& layer,
37  Optional<DataType> dataType,
38  std::string& outReasonIfUnsupported);
39 
40  static bool IsLayerSupported(const IConnectableLayer& layer,
41  Optional<DataType> dataType,
42  std::string& outReasonIfUnsupported,
43  const ModelOptions& modelOptions);
44 
45  static bool IsLayerSupported(const BackendId& backendId,
46  const IConnectableLayer& layer,
47  Optional<DataType> dataType,
48  std::string& outReasonIfUnsupported,
49  const ModelOptions& modelOptions);
50 
51  virtual bool SupportsSubTensors() const = 0;
52 
53  ARMNN_DEPRECATED_MSG("Use ITensorHandleFactory::CreateSubTensorHandle instead")
54  virtual std::unique_ptr<ITensorHandle> CreateSubTensorHandle(ITensorHandle& parent,
55  TensorShape const& subTensorShape,
56  unsigned int const* subTensorOrigin
57  ) const = 0;
58 
60  virtual std::unique_ptr<ITensorHandle> CreateTensorHandle(const TensorInfo& tensorInfo,
61  const bool IsMemoryManaged = true) const = 0;
62 
64  virtual std::unique_ptr<ITensorHandle> CreateTensorHandle(const TensorInfo& tensorInfo,
65  DataLayout dataLayout,
66  const bool IsMemoryManaged = true) const = 0;
67 
68  /// Backends should implement their own CreateWorkload function with a switch statement.
69  /// The case for the switch should be the LayerType and based on that they will call their
70  /// specific workload creation functionality.
71  virtual std::unique_ptr<IWorkload> CreateWorkload(LayerType type,
72  const QueueDescriptor& descriptor,
73  const WorkloadInfo& info) const = 0;
74 
75 private:
76  static bool IsLayerConfigurationSupported(const BackendId& backendId,
77  const IConnectableLayer& connectableLayer,
78  Optional<DataType> dataType,
79  std::string& outReasonIfUnsupported,
80  const ModelOptions& modelOptions = {});
81 };
82 
83 } // namespace armnn
armnn::Optional
Definition: Optional.hpp:270
armnn::IWorkloadFactory::CreateTensorHandle
virtual std::unique_ptr< ITensorHandle > CreateTensorHandle(const TensorInfo &tensorInfo, const bool IsMemoryManaged=true) const =0
armnn::DataLayout
DataLayout
Definition: Types.hpp:62
armnn::TensorInfo
Definition: Tensor.hpp:152
armnn::IWorkload
Workload interface to enqueue a layer computation.
Definition: IWorkload.hpp:23
armnn::ITensorHandle
Definition: ITensorHandle.hpp:16
armnn::IWorkloadFactory::GetBackendId
virtual const BackendId & GetBackendId() const =0
armnn::IWorkloadFactory::CreateSubTensorHandle
virtual std::unique_ptr< ITensorHandle > CreateSubTensorHandle(ITensorHandle &parent, TensorShape const &subTensorShape, unsigned int const *subTensorOrigin) const =0
armnn::IWorkloadFactory::~IWorkloadFactory
virtual ~IWorkloadFactory()
Definition: WorkloadFactory.hpp:25
armnn::TensorShape
Definition: Tensor.hpp:20
TensorFwd.hpp
Optional.hpp
INetwork.hpp
ITensorHandle.hpp
armnn::WorkloadInfo
Contains information about TensorInfos of a layer.
Definition: WorkloadInfo.hpp:16
armnn::DataType
DataType
Definition: Types.hpp:48
Workload.hpp
armnn::IWorkloadFactory::SupportsSubTensors
virtual bool SupportsSubTensors() const =0
armnn::IWorkloadFactory
Definition: WorkloadFactory.hpp:22
armnn::QueueDescriptor
Definition: WorkloadData.hpp:24
armnn::ITensorHandleFactory
Definition: ITensorHandleFactory.hpp:46
armnn::IWorkloadFactory::IsLayerSupported
static bool IsLayerSupported(const BackendId &backendId, const IConnectableLayer &layer, Optional< DataType > dataType, std::string &outReasonIfUnsupported)
Definition: WorkloadFactory.cpp:1572
ARMNN_DEPRECATED_MSG
#define ARMNN_DEPRECATED_MSG(message)
Definition: Deprecated.hpp:43
std
Definition: BackendId.hpp:149
armnn::BackendId
Definition: BackendId.hpp:75
armnn
Copyright (c) 2021 ARM Limited and Contributors.
Definition: 01_00_quick_start.dox:6
armnn::IConnectableLayer
Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
Definition: INetwork.hpp:80
armnn::ModelOptions
std::vector< BackendOptions > ModelOptions
Definition: BackendOptions.hpp:18
armnn::IWorkloadFactory::AfterWorkloadsCreated
virtual void AfterWorkloadsCreated()
Definition: WorkloadFactory.hpp:27
armnn::LayerType
LayerType
When adding a new layer, adapt also the LastLayer enum value in the enum class LayerType below.
Definition: Types.hpp:483
armnn::IWorkloadFactory::CreateWorkload
virtual std::unique_ptr< IWorkload > CreateWorkload(LayerType type, const QueueDescriptor &descriptor, const WorkloadInfo &info) const =0
Backends should implement their own CreateWorkload function with a switch statement.