ArmNN
 22.08
EthosnRefWorkloadUtils.hpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #pragma once
7 
8 #include <backendsCommon/CpuTensorHandle.hpp>
9 
10 #include <armnn/Tensor.hpp>
11 #include <armnn/Types.hpp>
12 
15 
16 #include <Half.hpp>
17 
19 #include <Profiling.hpp>
20 
21 #define ARMNN_SCOPED_PROFILING_EVENT_ETHOSN(name) ARMNN_SCOPED_PROFILING_EVENT(armnn::EthosnRefBackendId(), name)
22 
23 namespace armnn
24 {
25 
26 namespace ethosnref
27 {
28 
29 inline const TensorInfo& GetTensorInfo(const ITensorHandle* tensorHandle)
30 {
31  // We know that ethosn workloads use EthosnRefTensorHandles for inputs and outputs
32  const EthosnRefTensorHandle* refTensorHandle =
33  PolymorphicDowncast<const EthosnRefTensorHandle*>(tensorHandle);
34  return refTensorHandle->GetTensorInfo();
35 }
36 
37 template <typename DataType, typename PayloadType>
38 const DataType* GetInputTensorData(unsigned int idx, const PayloadType& data)
39 {
40  const ITensorHandle* tensorHandle = data.m_Inputs[idx];
41  return reinterpret_cast<const DataType*>(tensorHandle->Map());
42 }
43 
44 template <typename DataType, typename PayloadType>
45 DataType* GetOutputTensorData(unsigned int idx, const PayloadType& data)
46 {
47  ITensorHandle* tensorHandle = data.m_Outputs[idx];
48  return reinterpret_cast<DataType*>(tensorHandle->Map());
49 }
50 
51 inline uint32_t DivideRoundUp(uint32_t numerator, uint32_t denominator)
52 {
53  return (numerator + denominator - 1) / denominator;
54 }
55 
56 inline bool CheckDataType(DataType type, DataType inputType, DataType weightsType)
57 {
58  return (inputType == type || weightsType == type);
59 }
60 
61 }
62 
63 } //namespace armnn
const TensorInfo & GetTensorInfo() const
const DataType * GetInputTensorData(unsigned int idx, const PayloadType &data)
DataType * GetOutputTensorData(unsigned int idx, const PayloadType &data)
Copyright (c) 2021 ARM Limited and Contributors.
uint32_t DivideRoundUp(uint32_t numerator, uint32_t denominator)
bool CheckDataType(DataType type, DataType inputType, DataType weightsType)
const TensorInfo & GetTensorInfo(const ITensorHandle *tensorHandle)
DataType
Definition: Types.hpp:48
virtual const void * Map(bool blocking=true) const =0
Map the tensor data for access.