Compute Library
 22.05
NEDeviceBackend Class Referencefinal

CPU device backend. More...

#include <NEDeviceBackend.h>

Collaboration diagram for NEDeviceBackend:
[legend]

Public Member Functions

 NEDeviceBackend ()
 
void initialize_backend () override
 Initializes the backend. More...
 
void setup_backend_context (GraphContext &ctx) override
 Setups the given graph context. More...
 
void release_backend_context (GraphContext &ctx) override
 Release the backend specific resources associated to a given graph context. More...
 
bool is_backend_supported () override
 Checks if an instantiated backend is actually supported. More...
 
IAllocatorbackend_allocator () override
 Gets a backend memory allocator. More...
 
std::unique_ptr< ITensorHandlecreate_tensor (const Tensor &tensor) override
 Create a backend Tensor. More...
 
std::unique_ptr< ITensorHandlecreate_subtensor (ITensorHandle *parent, TensorShape shape, Coordinates coords, bool extend_parent) override
 Create a backend Sub-Tensor. More...
 
std::unique_ptr< arm_compute::IFunctionconfigure_node (INode &node, GraphContext &ctx) override
 Configure a backend Node. More...
 
Status validate_node (INode &node) override
 Validate a node. More...
 
std::shared_ptr< arm_compute::IMemoryManagercreate_memory_manager (MemoryManagerAffinity affinity) override
 Create a backend memory manager given its affinity. More...
 
std::shared_ptr< arm_compute::IWeightsManagercreate_weights_manager () override
 Create a backend weights manager. More...
 
void sync () override
 Synchronize kernels execution on the backend. More...
 
- Public Member Functions inherited from IDeviceBackend
virtual ~IDeviceBackend ()=default
 Virtual Destructor. More...
 

Detailed Description

CPU device backend.

Definition at line 38 of file NEDeviceBackend.h.

Constructor & Destructor Documentation

◆ NEDeviceBackend()

Definition at line 58 of file NEDeviceBackend.cpp.

59  : _allocator()
60 {
61 }

Member Function Documentation

◆ backend_allocator()

IAllocator * backend_allocator ( )
overridevirtual

Gets a backend memory allocator.

Returns
Backend memory allocator

Implements IDeviceBackend.

Definition at line 111 of file NEDeviceBackend.cpp.

112 {
113  return &_allocator;
114 }

◆ configure_node()

std::unique_ptr< arm_compute::IFunction > configure_node ( INode node,
GraphContext ctx 
)
overridevirtual

Configure a backend Node.

Note
This creates an appropriate configured backend function for the given node
Parameters
[in]nodeThe node we want to configure
[in]ctxContext to use
Returns
Backend execution function

Implements IDeviceBackend.

Definition at line 139 of file NEDeviceBackend.cpp.

References ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_LOG_GRAPH_VERBOSE, INode::assigned_target(), NEFunctionFactory::create(), INode::id(), and arm_compute::graph::NEON.

140 {
141  ARM_COMPUTE_LOG_GRAPH_VERBOSE("Configuring CPU node with ID : " << node.id() << std::endl);
142  ARM_COMPUTE_ERROR_ON(node.assigned_target() != Target::NEON);
143 
144  // Configure node
145  return NEFunctionFactory::create(&node, ctx);
146 }
Arm® Neon™ capable target device.
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
static std::unique_ptr< arm_compute::IFunction > create(INode *node, GraphContext &ctx)
Create a backend execution function depending on the node type.
#define ARM_COMPUTE_LOG_GRAPH_VERBOSE(x)
Definition: Logger.h:50

◆ create_memory_manager()

std::shared_ptr< arm_compute::IMemoryManager > create_memory_manager ( MemoryManagerAffinity  affinity)
overridevirtual

Create a backend memory manager given its affinity.

Parameters
[in]affinityMemory Manager affinity
Returns
Memory manager

Implements IDeviceBackend.

Definition at line 156 of file NEDeviceBackend.cpp.

References arm_compute::graph::Buffer.

Referenced by NEDeviceBackend::setup_backend_context().

157 {
158  std::shared_ptr<ILifetimeManager> lifetime_mgr = nullptr;
159  if(affinity == MemoryManagerAffinity::Buffer)
160  {
161  lifetime_mgr = std::make_shared<BlobLifetimeManager>();
162  }
163  else
164  {
165  lifetime_mgr = std::make_shared<OffsetLifetimeManager>();
166  }
167  auto pool_mgr = std::make_shared<PoolManager>();
168  auto mm = std::make_shared<MemoryManagerOnDemand>(lifetime_mgr, pool_mgr);
169 
170  return mm;
171 }

◆ create_subtensor()

std::unique_ptr< ITensorHandle > create_subtensor ( ITensorHandle parent,
TensorShape  shape,
Coordinates  coords,
bool  extend_parent 
)
overridevirtual

Create a backend Sub-Tensor.

Parameters
[in]parentParent sub-tensor handle
[in]shapeShape of the sub-tensor
[in]coordsStarting coordinates of the sub-tensor
[in]extend_parentExtends parent shape if true
Returns
Backend sub-tensor handle

Implements IDeviceBackend.

Definition at line 129 of file NEDeviceBackend.cpp.

References arm_compute::test::validation::shape.

130 {
131  if(parent == nullptr)
132  {
133  return nullptr;
134  }
135 
136  return std::make_unique<NESubTensorHandle>(parent, shape, coords, extend_parent);
137 }

◆ create_tensor()

std::unique_ptr< ITensorHandle > create_tensor ( const Tensor tensor)
overridevirtual

Create a backend Tensor.

Parameters
[in]tensorThe tensor we want to create a backend tensor for
Returns
Backend tensor handle

Implements IDeviceBackend.

Definition at line 116 of file NEDeviceBackend.cpp.

References ARM_COMPUTE_ERROR_ON, TensorDescriptor::data_type, Tensor::desc(), arm_compute::test::validation::info, TensorDescriptor::layout, arm_compute::graph::NEON, TensorDescriptor::quant_info, TensorInfo::set_data_layout(), TensorDescriptor::shape, and TensorDescriptor::target.

117 {
118  // Get tensor descriptor
119  const TensorDescriptor &tensor_desc = tensor.desc();
120  ARM_COMPUTE_ERROR_ON(tensor_desc.target != Target::NEON);
121 
122  // Create backend tensor handle
123  TensorInfo info(tensor_desc.shape, 1, tensor_desc.data_type, tensor_desc.quant_info);
124  info.set_data_layout(tensor_desc.layout);
125 
126  return std::make_unique<NETensorHandle>(info);
127 }
Arm® Neon™ capable target device.
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)

◆ create_weights_manager()

std::shared_ptr< arm_compute::IWeightsManager > create_weights_manager ( )
overridevirtual

Create a backend weights manager.

Returns
Weights manager

Implements IDeviceBackend.

Definition at line 173 of file NEDeviceBackend.cpp.

Referenced by NEDeviceBackend::setup_backend_context().

174 {
175  auto weights_mgr = std::make_shared<IWeightsManager>();
176  return weights_mgr;
177 }

◆ initialize_backend()

void initialize_backend ( )
overridevirtual

Initializes the backend.

Implements IDeviceBackend.

Definition at line 63 of file NEDeviceBackend.cpp.

64 {
65  //Nothing to do
66 }

◆ is_backend_supported()

bool is_backend_supported ( )
overridevirtual

Checks if an instantiated backend is actually supported.

Returns
True if the backend is supported else false

Implements IDeviceBackend.

Definition at line 106 of file NEDeviceBackend.cpp.

107 {
108  return true;
109 }

◆ release_backend_context()

void release_backend_context ( GraphContext ctx)
overridevirtual

Release the backend specific resources associated to a given graph context.

Parameters
[in,out]ctxGraph context

Implements IDeviceBackend.

Definition at line 68 of file NEDeviceBackend.cpp.

References ARM_COMPUTE_UNUSED.

69 {
70  //Nothing to do
71  ARM_COMPUTE_UNUSED(ctx);
72 }
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152

◆ setup_backend_context()

void setup_backend_context ( GraphContext ctx)
overridevirtual

Setups the given graph context.

Parameters
[in,out]ctxGraph context

Implements IDeviceBackend.

Definition at line 74 of file NEDeviceBackend.cpp.

References MemoryManagerContext::allocator, GraphContext::config(), NEDeviceBackend::create_memory_manager(), NEDeviceBackend::create_weights_manager(), MemoryManagerContext::cross_group, MemoryManagerContext::cross_mm, Scheduler::get(), GraphContext::insert_memory_management_ctx(), GraphContext::insert_weights_management_ctx(), MemoryManagerContext::intra_mm, GraphContext::memory_management_ctx(), arm_compute::graph::NEON, GraphConfig::num_threads, arm_compute::graph::Offset, IScheduler::set_num_threads(), MemoryManagerContext::target, WeightsManagerContext::target, GraphContext::weights_management_ctx(), and WeightsManagerContext::wm.

75 {
76  // Set number of threads
77  if(ctx.config().num_threads >= 0)
78  {
79  Scheduler::get().set_num_threads(ctx.config().num_threads);
80  }
81 
82  // Create function level memory manager
83  if(ctx.memory_management_ctx(Target::NEON) == nullptr)
84  {
85  MemoryManagerContext mm_ctx;
86  mm_ctx.target = Target::NEON;
89  mm_ctx.cross_group = std::make_shared<MemoryGroup>(mm_ctx.cross_mm);
90  mm_ctx.allocator = &_allocator;
91 
92  ctx.insert_memory_management_ctx(std::move(mm_ctx));
93  }
94 
95  // Create function level weights manager
96  if(ctx.weights_management_ctx(Target::NEON) == nullptr)
97  {
98  WeightsManagerContext wm_ctx;
99  wm_ctx.target = Target::NEON;
100  wm_ctx.wm = create_weights_manager();
101 
102  ctx.insert_weights_management_ctx(std::move(wm_ctx));
103  }
104 }
std::shared_ptr< arm_compute::IMemoryManager > create_memory_manager(MemoryManagerAffinity affinity) override
Create a backend memory manager given its affinity.
Arm® Neon™ capable target device.
virtual void set_num_threads(unsigned int num_threads)=0
Sets the number of threads the scheduler will use to run the kernels.
std::shared_ptr< arm_compute::IWeightsManager > create_weights_manager() override
Create a backend weights manager.
static IScheduler & get()
Access the scheduler singleton.
Definition: Scheduler.cpp:94

◆ sync()

void sync ( )
overridevirtual

Synchronize kernels execution on the backend.

On GPU, this results in a blocking call waiting for all kernels to be completed.

Implements IDeviceBackend.

Definition at line 179 of file NEDeviceBackend.cpp.

180 {
181  // nop
182 }

◆ validate_node()

arm_compute::Status validate_node ( INode node)
overridevirtual

Validate a node.

Parameters
[in]nodeThe node we want to validate
Returns
An error status

Implements IDeviceBackend.

Definition at line 148 of file NEDeviceBackend.cpp.

References ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_LOG_GRAPH_VERBOSE, INode::assigned_target(), INode::id(), arm_compute::graph::NEON, and NENodeValidator::validate().

149 {
150  ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating CPU node with ID : " << node.id() << std::endl);
151  ARM_COMPUTE_ERROR_ON(node.assigned_target() != Target::NEON);
152 
153  return NENodeValidator::validate(&node);
154 }
Arm® Neon™ capable target device.
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
static Status validate(INode *node)
Validate a node.
#define ARM_COMPUTE_LOG_GRAPH_VERBOSE(x)
Definition: Logger.h:50

The documentation for this class was generated from the following files: