blob: 2d54335355179261b290dc17ab9ed8ebc7978e46 [file] [log] [blame]
telsoa014fcda012018-03-09 14:13:49 +00001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
David Beckecb56cd2018-09-05 12:52:57 +01003// SPDX-License-Identifier: MIT
telsoa014fcda012018-03-09 14:13:49 +00004//
5#pragma once
6
7namespace armnn
8{
9namespace
10{
11
telsoa01c577f2c2018-08-31 09:22:23 +010012// Make a workload of the specified WorkloadType.
telsoa014fcda012018-03-09 14:13:49 +000013template<typename WorkloadType>
14struct MakeWorkloadForType
15{
surmeh013537c2c2018-05-18 16:31:43 +010016 template<typename QueueDescriptorType, typename... Args>
17 static std::unique_ptr<WorkloadType> Func(const QueueDescriptorType& descriptor,
18 const WorkloadInfo& info,
19 Args&&... args)
telsoa014fcda012018-03-09 14:13:49 +000020 {
surmeh013537c2c2018-05-18 16:31:43 +010021 return std::make_unique<WorkloadType>(descriptor, info, std::forward<Args>(args)...);
telsoa014fcda012018-03-09 14:13:49 +000022 }
23};
24
25// Specialization for void workload type used for unsupported workloads.
26template<>
27struct MakeWorkloadForType<NullWorkload>
28{
surmeh013537c2c2018-05-18 16:31:43 +010029 template<typename QueueDescriptorType, typename... Args>
30 static std::unique_ptr<NullWorkload> Func(const QueueDescriptorType& descriptor,
31 const WorkloadInfo& info,
32 Args&&... args)
telsoa014fcda012018-03-09 14:13:49 +000033 {
34 return nullptr;
35 }
36};
37
38// Makes a workload for one the specified types based on the data type requirements of the tensorinfo.
39// Specify type void as the WorkloadType for unsupported DataType/WorkloadType combos.
narpra01db2b1602019-01-23 15:23:11 +000040template <typename Float16Workload, typename Float32Workload, typename Uint8Workload, typename Int32Workload,
kevmay012b4d88e2019-01-24 14:05:09 +000041 typename BooleanWorkload, typename QueueDescriptorType, typename... Args>
Aron Virginas-Tara8e06ed2018-10-19 16:46:15 +010042std::unique_ptr<IWorkload> MakeWorkloadHelper(const QueueDescriptorType& descriptor,
43 const WorkloadInfo& info,
44 Args&&... args)
telsoa014fcda012018-03-09 14:13:49 +000045{
46 const DataType dataType = !info.m_InputTensorInfos.empty() ?
47 info.m_InputTensorInfos[0].GetDataType()
48 : info.m_OutputTensorInfos[0].GetDataType();
49
kevmay012b4d88e2019-01-24 14:05:09 +000050 BOOST_ASSERT(info.m_InputTensorInfos.empty() ||
51 info.m_OutputTensorInfos.empty() ||
52 ((info.m_InputTensorInfos[0].GetDataType() == info.m_OutputTensorInfos[0].GetDataType()) ||
53 info.m_OutputTensorInfos[0].GetDataType() == armnn::DataType::Boolean));
telsoa014fcda012018-03-09 14:13:49 +000054
55 switch (dataType)
56 {
telsoa01c577f2c2018-08-31 09:22:23 +010057 case DataType::Float16:
58 return MakeWorkloadForType<Float16Workload>::Func(descriptor, info, std::forward<Args>(args)...);
telsoa014fcda012018-03-09 14:13:49 +000059 case DataType::Float32:
surmeh013537c2c2018-05-18 16:31:43 +010060 return MakeWorkloadForType<Float32Workload>::Func(descriptor, info, std::forward<Args>(args)...);
telsoa014fcda012018-03-09 14:13:49 +000061 case DataType::QuantisedAsymm8:
surmeh013537c2c2018-05-18 16:31:43 +010062 return MakeWorkloadForType<Uint8Workload>::Func(descriptor, info, std::forward<Args>(args)...);
narpra01db2b1602019-01-23 15:23:11 +000063 case DataType::Signed32:
64 return MakeWorkloadForType<Int32Workload>::Func(descriptor, info, std::forward<Args>(args)...);
kevmay012b4d88e2019-01-24 14:05:09 +000065 case DataType::Boolean:
66 return MakeWorkloadForType<BooleanWorkload>::Func(descriptor, info, std::forward<Args>(args)...);
telsoa014fcda012018-03-09 14:13:49 +000067 default:
68 BOOST_ASSERT_MSG(false, "Unknown DataType.");
69 return nullptr;
70 }
71}
72
telsoa01c577f2c2018-08-31 09:22:23 +010073// Makes a workload for one the specified types based on the data type requirements of the tensorinfo.
kevmay012b4d88e2019-01-24 14:05:09 +000074// Calling this method is the equivalent of calling the five typed MakeWorkload method with <FloatWorkload,
75// FloatWorkload, Uint8Workload, NullWorkload, NullWorkload>.
telsoa01c577f2c2018-08-31 09:22:23 +010076// Specify type void as the WorkloadType for unsupported DataType/WorkloadType combos.
77template <typename FloatWorkload, typename Uint8Workload, typename QueueDescriptorType, typename... Args>
Aron Virginas-Tara8e06ed2018-10-19 16:46:15 +010078std::unique_ptr<IWorkload> MakeWorkloadHelper(const QueueDescriptorType& descriptor,
79 const WorkloadInfo& info,
80 Args&&... args)
telsoa01c577f2c2018-08-31 09:22:23 +010081{
kevmay012b4d88e2019-01-24 14:05:09 +000082 return MakeWorkloadHelper<FloatWorkload, FloatWorkload, Uint8Workload, NullWorkload, NullWorkload>(
83 descriptor,
84 info,
85 std::forward<Args>(args)...);
telsoa01c577f2c2018-08-31 09:22:23 +010086}
87
telsoa014fcda012018-03-09 14:13:49 +000088} //namespace
surmeh013537c2c2018-05-18 16:31:43 +010089} //namespace armnn