telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame^] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
| 3 | // See LICENSE file in the project root for full license information. |
| 4 | // |
| 5 | #pragma once |
| 6 | |
| 7 | #include "WorkloadData.hpp" |
| 8 | #include "WorkloadInfo.hpp" |
| 9 | #include <algorithm> |
| 10 | #include "Profiling.hpp" |
| 11 | |
| 12 | namespace armnn |
| 13 | { |
| 14 | |
| 15 | // Workload interface to enqueue a layer computation |
| 16 | class IWorkload |
| 17 | { |
| 18 | public: |
| 19 | virtual ~IWorkload(){}; |
| 20 | |
| 21 | virtual void Execute() const = 0; |
| 22 | }; |
| 23 | |
| 24 | // NullWorkload used to denote an unsupported workload when used by the MakeWorkload<> template |
| 25 | // in the various workload factories. |
| 26 | // There should never be an instantiation of a NullWorkload. |
| 27 | class NullWorkload : public IWorkload |
| 28 | { |
| 29 | NullWorkload()=delete; |
| 30 | }; |
| 31 | |
| 32 | template <typename QueueDescriptor> |
| 33 | class BaseWorkload : public IWorkload |
| 34 | { |
| 35 | public: |
| 36 | |
| 37 | BaseWorkload(const QueueDescriptor& descriptor, const WorkloadInfo& info) |
| 38 | : m_Data(descriptor) |
| 39 | { |
| 40 | m_Data.Validate(info); |
| 41 | } |
| 42 | |
| 43 | const QueueDescriptor& GetData() const { return m_Data; } |
| 44 | |
| 45 | protected: |
| 46 | const QueueDescriptor m_Data; |
| 47 | }; |
| 48 | |
| 49 | template <typename QueueDescriptor, armnn::DataType DataType> |
| 50 | class TypedWorkload : public BaseWorkload<QueueDescriptor> |
| 51 | { |
| 52 | public: |
| 53 | |
| 54 | TypedWorkload(const QueueDescriptor& descriptor, const WorkloadInfo& info) |
| 55 | : BaseWorkload<QueueDescriptor>(descriptor, info) |
| 56 | { |
| 57 | BOOST_ASSERT_MSG(std::all_of(info.m_InputTensorInfos.begin(), |
| 58 | info.m_InputTensorInfos.end(), |
| 59 | [&](auto it){ |
| 60 | return it.GetDataType() == DataType; |
| 61 | }), |
| 62 | "Trying to create workload with incorrect type"); |
| 63 | BOOST_ASSERT_MSG(std::all_of(info.m_OutputTensorInfos.begin(), |
| 64 | info.m_OutputTensorInfos.end(), |
| 65 | [&](auto it){ |
| 66 | return it.GetDataType() == DataType; |
| 67 | }), |
| 68 | "Trying to create workload with incorrect type"); |
| 69 | } |
| 70 | |
| 71 | static constexpr armnn::DataType ms_DataType = DataType; |
| 72 | }; |
| 73 | |
| 74 | template <typename QueueDescriptor> |
| 75 | using Float32Workload = TypedWorkload<QueueDescriptor, armnn::DataType::Float32>; |
| 76 | |
| 77 | template <typename QueueDescriptor> |
| 78 | using Uint8Workload = TypedWorkload<QueueDescriptor, armnn::DataType::QuantisedAsymm8>; |
| 79 | |
| 80 | } //namespace armnn |