ArmNN
 24.08
SampleDynamicAdditionWorkload.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2020 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
7 
9 #include "SampleTensorHandle.hpp"
10 
11 namespace sdb // sample dynamic backend
12 {
13 
14 inline const armnn::TensorInfo& GetTensorInfo(const armnn::ITensorHandle* tensorHandle)
15 {
16  // We know that reference workloads use RefTensorHandles for inputs and outputs
17  const SampleTensorHandle* sampleTensorHandle =
18  static_cast<const SampleTensorHandle*>(tensorHandle);
19  return sampleTensorHandle->GetTensorInfo();
20 }
21 
22 const float* GetInputTensorData(unsigned int idx, const armnn::AdditionQueueDescriptor& data)
23 {
24  const armnn::ITensorHandle* tensorHandle = data.m_Inputs[idx];
25  return reinterpret_cast<const float*>(tensorHandle->Map());
26 }
27 
28 float* GetOutputTensorData(unsigned int idx, const armnn::AdditionQueueDescriptor& data)
29 {
30  armnn::ITensorHandle* tensorHandle = data.m_Outputs[idx];
31  return reinterpret_cast<float*>(tensorHandle->Map());
32 }
33 
35  const armnn::WorkloadInfo& info)
36  : BaseWorkload(descriptor, info)
37 {}
38 
40 {
42  unsigned int num = info.GetNumElements();
43 
44  const float* inputData0 = GetInputTensorData(0, m_Data);
45  const float* inputData1 = GetInputTensorData(1, m_Data);
46  float* outputData = GetOutputTensorData(0, m_Data);
47 
48  for (unsigned int i = 0; i < num; ++i)
49  {
50  outputData[i] = inputData0[i] + inputData1[i];
51  }
52 }
53 
54 } // namespace sdb // sample dynamic backend
SampleTensorHandle.hpp
armnn::TensorInfo
Definition: Tensor.hpp:152
armnn::ITensorHandle
Definition: ITensorHandle.hpp:16
sdb
Definition: SampleDynamicAdditionWorkload.cpp:11
sdb::SampleDynamicAdditionWorkload::Execute
void Execute() const override
Definition: SampleDynamicAdditionWorkload.cpp:39
sdb::GetTensorInfo
const armnn::TensorInfo & GetTensorInfo(const armnn::ITensorHandle *tensorHandle)
Definition: SampleDynamicAdditionWorkload.cpp:14
sdb::SampleDynamicAdditionWorkload::SampleDynamicAdditionWorkload
SampleDynamicAdditionWorkload(const armnn::AdditionQueueDescriptor &descriptor, const armnn::WorkloadInfo &info)
Definition: SampleDynamicAdditionWorkload.cpp:34
ITensorHandle.hpp
armnn::WorkloadInfo
Contains information about TensorInfos of a layer.
Definition: WorkloadInfo.hpp:16
armnn::AdditionQueueDescriptor
Definition: WorkloadData.hpp:258
sdb::SampleTensorHandle
Definition: SampleTensorHandle.hpp:15
armnn::QueueDescriptor::m_Outputs
std::vector< ITensorHandle * > m_Outputs
Definition: WorkloadData.hpp:27
armnn::BaseWorkload< armnn::AdditionQueueDescriptor >::m_Data
armnn::AdditionQueueDescriptor m_Data
Definition: Workload.hpp:89
sdb::SampleTensorHandle::GetTensorInfo
const armnn::TensorInfo & GetTensorInfo() const
Definition: SampleTensorHandle.hpp:49
SampleDynamicAdditionWorkload.hpp
sdb::GetInputTensorData
const float * GetInputTensorData(unsigned int idx, const armnn::AdditionQueueDescriptor &data)
Definition: SampleDynamicAdditionWorkload.cpp:22
armnn::QueueDescriptor::m_Inputs
std::vector< ITensorHandle * > m_Inputs
Definition: WorkloadData.hpp:26
armnn::ITensorHandle::Map
virtual const void * Map(bool blocking=true) const =0
Map the tensor data for access.
sdb::GetOutputTensorData
float * GetOutputTensorData(unsigned int idx, const armnn::AdditionQueueDescriptor &data)
Definition: SampleDynamicAdditionWorkload.cpp:28