Release 18.08
[platform/upstream/armnn.git] / src / armnn / backends / ClWorkloads / ClBaseConstantWorkload.cpp
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // See LICENSE file in the project root for full license information.
4 //
5
6 #include "ClBaseConstantWorkload.hpp"
7 #include "backends/ArmComputeTensorUtils.hpp"
8 #include "backends/ClTensorHandle.hpp"
9 #include "backends/CpuTensorHandle.hpp"
10 #include "Half.hpp"
11
12 namespace armnn
13 {
14
15 template class ClBaseConstantWorkload<DataType::Float16, DataType::Float32>;
16 template class ClBaseConstantWorkload<DataType::QuantisedAsymm8>;
17
18 template<armnn::DataType... dataTypes>
19 void ClBaseConstantWorkload<dataTypes...>::Execute() const
20 {
21     // The intermediate tensor held by the corresponding layer output handler can be initialised with the given data
22     // on the first inference, then reused for subsequent inferences.
23     // The initialisation cannot happen at workload construction time since the ACL kernel for the next layer may not
24     // have been configured at the time.
25     if (!m_RanOnce)
26     {
27         const ConstantQueueDescriptor& data = this->m_Data;
28
29         BOOST_ASSERT(data.m_LayerOutput != nullptr);
30         arm_compute::CLTensor& output = static_cast<ClTensorHandle*>(data.m_Outputs[0])->GetTensor();
31         arm_compute::DataType computeDataType = static_cast<ClTensorHandle*>(data.m_Outputs[0])->GetDataType();
32
33         switch (computeDataType)
34         {
35             case arm_compute::DataType::F16:
36             {
37                 CopyArmComputeClTensorData(data.m_LayerOutput->GetConstTensor<Half>(), output);
38                 break;
39             }
40             case arm_compute::DataType::F32:
41             {
42                 CopyArmComputeClTensorData(data.m_LayerOutput->GetConstTensor<float>(), output);
43                 break;
44             }
45             case arm_compute::DataType::QASYMM8:
46             {
47                 CopyArmComputeClTensorData(data.m_LayerOutput->GetConstTensor<uint8_t>(), output);
48                 break;
49             }
50             default:
51             {
52                 BOOST_ASSERT_MSG(false, "Unknown data type");
53                 break;
54             }
55         }
56
57         m_RanOnce = true;
58     }
59 }
60
61
62 } //namespace armnn