blob: 560182286e4e1f8cb371991364e54e7630f37c94 [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 {
Jan Eilers8eb25602020-03-09 12:13:48 +000034 IgnoreUnused(descriptor);
35 IgnoreUnused(info);
36 IgnoreUnused(args...);
telsoa014fcda012018-03-09 14:13:49 +000037 return nullptr;
38 }
39};
40
41// Makes a workload for one the specified types based on the data type requirements of the tensorinfo.
42// Specify type void as the WorkloadType for unsupported DataType/WorkloadType combos.
narpra01db2b1602019-01-23 15:23:11 +000043template <typename Float16Workload, typename Float32Workload, typename Uint8Workload, typename Int32Workload,
Keith Davis5204aa82020-01-27 15:24:59 +000044 typename BooleanWorkload, typename Int8Workload, typename QueueDescriptorType, typename... Args>
Aron Virginas-Tara8e06ed2018-10-19 16:46:15 +010045std::unique_ptr<IWorkload> MakeWorkloadHelper(const QueueDescriptorType& descriptor,
46 const WorkloadInfo& info,
47 Args&&... args)
telsoa014fcda012018-03-09 14:13:49 +000048{
49 const DataType dataType = !info.m_InputTensorInfos.empty() ?
50 info.m_InputTensorInfos[0].GetDataType()
51 : info.m_OutputTensorInfos[0].GetDataType();
52
telsoa014fcda012018-03-09 14:13:49 +000053 switch (dataType)
54 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +000055
telsoa01c577f2c2018-08-31 09:22:23 +010056 case DataType::Float16:
57 return MakeWorkloadForType<Float16Workload>::Func(descriptor, info, std::forward<Args>(args)...);
telsoa014fcda012018-03-09 14:13:49 +000058 case DataType::Float32:
surmeh013537c2c2018-05-18 16:31:43 +010059 return MakeWorkloadForType<Float32Workload>::Func(descriptor, info, std::forward<Args>(args)...);
Derek Lambertif90c56d2020-01-10 17:14:08 +000060 case DataType::QAsymmU8:
surmeh013537c2c2018-05-18 16:31:43 +010061 return MakeWorkloadForType<Uint8Workload>::Func(descriptor, info, std::forward<Args>(args)...);
Keith Davis5204aa82020-01-27 15:24:59 +000062 case DataType::QSymmS8:
Keith Davisa8565012020-02-14 12:22:40 +000063 case DataType::QAsymmS8:
Keith Davis5204aa82020-01-27 15:24:59 +000064 return MakeWorkloadForType<Int8Workload>::Func(descriptor, info, std::forward<Args>(args)...);
narpra01db2b1602019-01-23 15:23:11 +000065 case DataType::Signed32:
66 return MakeWorkloadForType<Int32Workload>::Func(descriptor, info, std::forward<Args>(args)...);
kevmay012b4d88e2019-01-24 14:05:09 +000067 case DataType::Boolean:
68 return MakeWorkloadForType<BooleanWorkload>::Func(descriptor, info, std::forward<Args>(args)...);
Narumol Prangnawarat44179c32020-03-11 14:51:27 +000069 case DataType::BFloat16:
Derek Lambertif90c56d2020-01-10 17:14:08 +000070 case DataType::QSymmS16:
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +010071 return nullptr;
telsoa014fcda012018-03-09 14:13:49 +000072 default:
Narumol Prangnawaratac2770a2020-04-01 16:51:23 +010073 ARMNN_ASSERT_MSG(false, "Unknown DataType.");
telsoa014fcda012018-03-09 14:13:49 +000074 return nullptr;
75 }
76}
77
telsoa01c577f2c2018-08-31 09:22:23 +010078// Makes a workload for one the specified types based on the data type requirements of the tensorinfo.
kevmay012b4d88e2019-01-24 14:05:09 +000079// Calling this method is the equivalent of calling the five typed MakeWorkload method with <FloatWorkload,
Keith Davis5204aa82020-01-27 15:24:59 +000080// FloatWorkload, Uint8Workload, NullWorkload, NullWorkload, NullWorkload>.
telsoa01c577f2c2018-08-31 09:22:23 +010081// Specify type void as the WorkloadType for unsupported DataType/WorkloadType combos.
82template <typename FloatWorkload, typename Uint8Workload, typename QueueDescriptorType, typename... Args>
Aron Virginas-Tara8e06ed2018-10-19 16:46:15 +010083std::unique_ptr<IWorkload> MakeWorkloadHelper(const QueueDescriptorType& descriptor,
84 const WorkloadInfo& info,
85 Args&&... args)
telsoa01c577f2c2018-08-31 09:22:23 +010086{
Keith Davis5204aa82020-01-27 15:24:59 +000087 return MakeWorkloadHelper<FloatWorkload, FloatWorkload, Uint8Workload, NullWorkload, NullWorkload, NullWorkload>(
kevmay012b4d88e2019-01-24 14:05:09 +000088 descriptor,
89 info,
90 std::forward<Args>(args)...);
telsoa01c577f2c2018-08-31 09:22:23 +010091}
92
telsoa014fcda012018-03-09 14:13:49 +000093} //namespace
surmeh013537c2c2018-05-18 16:31:43 +010094} //namespace armnn