Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 ARM Limited. |
| 3 | * |
| 4 | * SPDX-License-Identifier: MIT |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and associated documentation files (the "Software"), to |
| 8 | * deal in the Software without restriction, including without limitation the |
| 9 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 10 | * sell copies of the Software, and to permit persons to whom the Software is |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in all |
| 14 | * copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | * SOFTWARE. |
| 23 | */ |
| 24 | #ifndef __ARM_COMPUTE_TEST_DATA_TYPE_DATASET_H__ |
| 25 | #define __ARM_COMPUTE_TEST_DATA_TYPE_DATASET_H__ |
| 26 | |
| 27 | #include "arm_compute/core/Types.h" |
| 28 | |
| 29 | #ifdef BOOST |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 30 | #include "tests/validation_old/boost_wrapper.h" |
Anthony Barbier | ac69aa1 | 2017-07-03 17:39:37 +0100 | [diff] [blame] | 31 | #endif /* BOOST */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 32 | |
| 33 | namespace arm_compute |
| 34 | { |
| 35 | namespace test |
| 36 | { |
| 37 | /** Abstract data set containing data types. |
| 38 | * |
| 39 | * Can be used as input for Boost data test cases to automatically run a test |
| 40 | * case on different data types. |
| 41 | */ |
| 42 | template <unsigned int Size> |
| 43 | class DataTypes |
| 44 | { |
| 45 | public: |
| 46 | /** Type of the samples in the data set. */ |
| 47 | using sample = DataType; |
| 48 | |
| 49 | /** Dimensionality of the data set. */ |
| 50 | enum |
| 51 | { |
| 52 | arity = 1 |
| 53 | }; |
| 54 | |
| 55 | /** Number of samples in the data set. */ |
| 56 | #ifdef BOOST |
| 57 | boost::unit_test::data::size_t size() const |
Anthony Barbier | ac69aa1 | 2017-07-03 17:39:37 +0100 | [diff] [blame] | 58 | #else /* BOOST */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 59 | unsigned int size() const |
Anthony Barbier | ac69aa1 | 2017-07-03 17:39:37 +0100 | [diff] [blame] | 60 | #endif /* BOOST */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 61 | { |
| 62 | return _types.size(); |
| 63 | } |
| 64 | |
| 65 | /** Type of the iterator used to step through all samples in the data set. |
| 66 | * Needs to support operator*() and operator++() which a pointer does. |
| 67 | */ |
| 68 | using iterator = const DataType *; |
| 69 | |
| 70 | /** Iterator to the first sample in the data set. */ |
| 71 | iterator begin() const |
| 72 | { |
| 73 | return _types.data(); |
| 74 | } |
| 75 | |
| 76 | protected: |
| 77 | /** Protected constructor to make the class abstract. */ |
| 78 | template <typename... Ts> |
| 79 | DataTypes(Ts &&... types) |
| 80 | : _types{ { types... } } |
| 81 | { |
| 82 | } |
| 83 | |
| 84 | /** Protected destructor to prevent deletion of derived classes through a |
| 85 | * pointer to the base class. |
| 86 | */ |
| 87 | ~DataTypes() = default; |
| 88 | |
| 89 | private: |
| 90 | std::array<DataType, Size> _types; |
| 91 | }; |
| 92 | |
| 93 | /** Data set containing all data types. */ |
| 94 | class AllDataTypes final : public DataTypes<14> |
| 95 | { |
| 96 | public: |
| 97 | AllDataTypes() |
| 98 | : DataTypes{ DataType::U8, DataType::S8, DataType::U16, DataType::S16, |
| 99 | DataType::U32, DataType::S32, DataType::U64, DataType::S64, |
| 100 | DataType::F16, DataType::F32, DataType::F64, DataType::SIZET, |
| 101 | DataType::QS8, DataType::QS16 } |
| 102 | { |
| 103 | } |
| 104 | |
| 105 | ~AllDataTypes() = default; |
| 106 | }; |
| 107 | |
| 108 | /** Data set containing all unsigned data types. */ |
| 109 | class UnsignedDataTypes final : public DataTypes<4> |
| 110 | { |
| 111 | public: |
| 112 | UnsignedDataTypes() |
| 113 | : DataTypes{ DataType::U8, DataType::U16, DataType::U32, DataType::U64 } |
| 114 | { |
| 115 | } |
| 116 | |
| 117 | ~UnsignedDataTypes() = default; |
| 118 | }; |
| 119 | |
| 120 | /** Data set containing all signed data types. */ |
| 121 | class SignedDataTypes final : public DataTypes<4> |
| 122 | { |
| 123 | public: |
| 124 | SignedDataTypes() |
| 125 | : DataTypes{ DataType::S8, DataType::S16, DataType::S32, DataType::S64 } |
| 126 | { |
| 127 | } |
| 128 | |
| 129 | ~SignedDataTypes() = default; |
| 130 | }; |
| 131 | |
| 132 | /** Data set containing all floating point data types. */ |
| 133 | class FloatDataTypes final : public DataTypes<3> |
| 134 | { |
| 135 | public: |
| 136 | FloatDataTypes() |
| 137 | : DataTypes{ DataType::F16, DataType::F32, DataType::F64 } |
| 138 | { |
| 139 | } |
| 140 | |
| 141 | ~FloatDataTypes() = default; |
| 142 | }; |
| 143 | |
| 144 | /** Data set containing all fixed point data types. */ |
| 145 | class FixedPointDataTypes final : public DataTypes<2> |
| 146 | { |
| 147 | public: |
| 148 | FixedPointDataTypes() |
| 149 | : DataTypes{ DataType::QS8, DataType::QS16 } |
| 150 | { |
| 151 | } |
| 152 | |
| 153 | ~FixedPointDataTypes() = default; |
| 154 | }; |
| 155 | |
| 156 | /** Supported CNN float types. */ |
| 157 | class CNNFloatDataTypes final : public DataTypes<1> |
| 158 | { |
| 159 | public: |
| 160 | CNNFloatDataTypes() |
| 161 | : DataTypes{ DataType::F32 } |
| 162 | { |
| 163 | } |
| 164 | |
| 165 | ~CNNFloatDataTypes() = default; |
| 166 | }; |
| 167 | |
| 168 | /** Supported CNN fixed point types. */ |
Georgios Pinitas | ac4e873 | 2017-07-05 17:02:25 +0100 | [diff] [blame] | 169 | class CNNFixedPointDataTypes final : public DataTypes<2> |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 170 | { |
| 171 | public: |
| 172 | CNNFixedPointDataTypes() |
Georgios Pinitas | ac4e873 | 2017-07-05 17:02:25 +0100 | [diff] [blame] | 173 | : DataTypes{ DataType::QS8, DataType::QS16 } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 174 | { |
| 175 | } |
| 176 | |
| 177 | ~CNNFixedPointDataTypes() = default; |
| 178 | }; |
| 179 | |
| 180 | /** Supported CNN types. */ |
| 181 | class CNNDataTypes final : public DataTypes<2> |
| 182 | { |
| 183 | public: |
| 184 | CNNDataTypes() |
| 185 | : DataTypes{ DataType::F32, DataType::QS8 } |
| 186 | { |
| 187 | } |
| 188 | |
| 189 | ~CNNDataTypes() = default; |
| 190 | }; |
| 191 | } // namespace test |
| 192 | } // namespace arm_compute |
Anthony Barbier | ac69aa1 | 2017-07-03 17:39:37 +0100 | [diff] [blame] | 193 | #endif /* __ARM_COMPUTE_TEST_DATA_TYPE_DATASET_H__ */ |