blob: 0fa57a7e07b241dbec49fa66d809360d33ba47d4 [file] [log] [blame]
Narumol Prangnawarat867eba52020-02-03 12:29:56 +00001//
2// Copyright © 2020 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#include <armnn/backends/ITensorHandle.hpp>
7
8#include "SampleDynamicAdditionWorkload.hpp"
9#include "SampleTensorHandle.hpp"
10
11namespace armnn
12{
13
14inline const TensorInfo& GetTensorInfo(const 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
22const float* GetInputTensorData(unsigned int idx, const AdditionQueueDescriptor& data)
23{
24 const ITensorHandle* tensorHandle = data.m_Inputs[idx];
25 return reinterpret_cast<const float*>(tensorHandle->Map());
26}
27
28float* GetOutputTensorData(unsigned int idx, const AdditionQueueDescriptor& data)
29{
30 ITensorHandle* tensorHandle = data.m_Outputs[idx];
31 return reinterpret_cast<float*>(tensorHandle->Map());
32}
33
34SampleDynamicAdditionWorkload::SampleDynamicAdditionWorkload(const AdditionQueueDescriptor& descriptor,
35 const WorkloadInfo& info)
36 : BaseWorkload(descriptor, info)
37{}
38
39void SampleDynamicAdditionWorkload::Execute() const
40{
41 const TensorInfo& info = GetTensorInfo(m_Data.m_Inputs[0]);
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 armnn