telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
David Beck | ecb56cd | 2018-09-05 12:52:57 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 4 | // |
| 5 | #pragma once |
| 6 | |
| 7 | namespace armnn |
| 8 | { |
| 9 | namespace |
| 10 | { |
| 11 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 12 | // Make a workload of the specified WorkloadType. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 13 | template<typename WorkloadType> |
| 14 | struct MakeWorkloadForType |
| 15 | { |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 16 | template<typename QueueDescriptorType, typename... Args> |
| 17 | static std::unique_ptr<WorkloadType> Func(const QueueDescriptorType& descriptor, |
| 18 | const WorkloadInfo& info, |
| 19 | Args&&... args) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 20 | { |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 21 | return std::make_unique<WorkloadType>(descriptor, info, std::forward<Args>(args)...); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 22 | } |
| 23 | }; |
| 24 | |
| 25 | // Specialization for void workload type used for unsupported workloads. |
| 26 | template<> |
| 27 | struct MakeWorkloadForType<NullWorkload> |
| 28 | { |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 29 | template<typename QueueDescriptorType, typename... Args> |
| 30 | static std::unique_ptr<NullWorkload> Func(const QueueDescriptorType& descriptor, |
| 31 | const WorkloadInfo& info, |
| 32 | Args&&... args) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 33 | { |
| 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. |
narpra01 | db2b160 | 2019-01-23 15:23:11 +0000 | [diff] [blame] | 40 | template <typename Float16Workload, typename Float32Workload, typename Uint8Workload, typename Int32Workload, |
kevmay01 | 2b4d88e | 2019-01-24 14:05:09 +0000 | [diff] [blame] | 41 | typename BooleanWorkload, typename QueueDescriptorType, typename... Args> |
Aron Virginas-Tar | a8e06ed | 2018-10-19 16:46:15 +0100 | [diff] [blame] | 42 | std::unique_ptr<IWorkload> MakeWorkloadHelper(const QueueDescriptorType& descriptor, |
| 43 | const WorkloadInfo& info, |
| 44 | Args&&... args) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 45 | { |
| 46 | const DataType dataType = !info.m_InputTensorInfos.empty() ? |
| 47 | info.m_InputTensorInfos[0].GetDataType() |
| 48 | : info.m_OutputTensorInfos[0].GetDataType(); |
| 49 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 50 | switch (dataType) |
| 51 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 52 | case DataType::Float16: |
| 53 | return MakeWorkloadForType<Float16Workload>::Func(descriptor, info, std::forward<Args>(args)...); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 54 | case DataType::Float32: |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 55 | return MakeWorkloadForType<Float32Workload>::Func(descriptor, info, std::forward<Args>(args)...); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 56 | case DataType::QuantisedAsymm8: |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 57 | return MakeWorkloadForType<Uint8Workload>::Func(descriptor, info, std::forward<Args>(args)...); |
narpra01 | db2b160 | 2019-01-23 15:23:11 +0000 | [diff] [blame] | 58 | case DataType::Signed32: |
| 59 | return MakeWorkloadForType<Int32Workload>::Func(descriptor, info, std::forward<Args>(args)...); |
kevmay01 | 2b4d88e | 2019-01-24 14:05:09 +0000 | [diff] [blame] | 60 | case DataType::Boolean: |
| 61 | return MakeWorkloadForType<BooleanWorkload>::Func(descriptor, info, std::forward<Args>(args)...); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 62 | default: |
| 63 | BOOST_ASSERT_MSG(false, "Unknown DataType."); |
| 64 | return nullptr; |
| 65 | } |
| 66 | } |
| 67 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 68 | // Makes a workload for one the specified types based on the data type requirements of the tensorinfo. |
kevmay01 | 2b4d88e | 2019-01-24 14:05:09 +0000 | [diff] [blame] | 69 | // Calling this method is the equivalent of calling the five typed MakeWorkload method with <FloatWorkload, |
| 70 | // FloatWorkload, Uint8Workload, NullWorkload, NullWorkload>. |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 71 | // Specify type void as the WorkloadType for unsupported DataType/WorkloadType combos. |
| 72 | template <typename FloatWorkload, typename Uint8Workload, typename QueueDescriptorType, typename... Args> |
Aron Virginas-Tar | a8e06ed | 2018-10-19 16:46:15 +0100 | [diff] [blame] | 73 | std::unique_ptr<IWorkload> MakeWorkloadHelper(const QueueDescriptorType& descriptor, |
| 74 | const WorkloadInfo& info, |
| 75 | Args&&... args) |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 76 | { |
kevmay01 | 2b4d88e | 2019-01-24 14:05:09 +0000 | [diff] [blame] | 77 | return MakeWorkloadHelper<FloatWorkload, FloatWorkload, Uint8Workload, NullWorkload, NullWorkload>( |
| 78 | descriptor, |
| 79 | info, |
| 80 | std::forward<Args>(args)...); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 81 | } |
| 82 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 83 | } //namespace |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 84 | } //namespace armnn |