Anthony Barbier | 2a07e18 | 2017-08-04 18:20:27 +0100 | [diff] [blame] | 1 | /* |
Giorgio Arena | a66eaa2 | 2017-12-21 19:50:06 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2018 ARM Limited. |
Anthony Barbier | 2a07e18 | 2017-08-04 18:20:27 +0100 | [diff] [blame] | 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_GRAPH_UTILS_H__ |
| 25 | #define __ARM_COMPUTE_GRAPH_UTILS_H__ |
| 26 | |
Michalis Spyrou | 53b405f | 2017-09-27 15:55:31 +0100 | [diff] [blame] | 27 | #include "arm_compute/core/PixelValue.h" |
Isabella Gottardi | 88d5b22 | 2018-04-06 12:24:55 +0100 | [diff] [blame] | 28 | #include "arm_compute/core/utils/misc/Utility.h" |
Gian Marco | bfa3b52 | 2017-12-12 10:08:38 +0000 | [diff] [blame] | 29 | #include "arm_compute/graph/Graph.h" |
Anthony Barbier | 2a07e18 | 2017-08-04 18:20:27 +0100 | [diff] [blame] | 30 | #include "arm_compute/graph/ITensorAccessor.h" |
| 31 | #include "arm_compute/graph/Types.h" |
Isabella Gottardi | 88d5b22 | 2018-04-06 12:24:55 +0100 | [diff] [blame] | 32 | #include "arm_compute/runtime/Tensor.h" |
Anthony Barbier | 2a07e18 | 2017-08-04 18:20:27 +0100 | [diff] [blame] | 33 | |
Georgios Pinitas | 140fdc7 | 2018-02-16 11:42:38 +0000 | [diff] [blame] | 34 | #include <array> |
Michalis Spyrou | 53b405f | 2017-09-27 15:55:31 +0100 | [diff] [blame] | 35 | #include <random> |
Gian Marco | 44ec2e7 | 2017-10-19 14:13:38 +0100 | [diff] [blame] | 36 | #include <string> |
| 37 | #include <vector> |
Michalis Spyrou | 53b405f | 2017-09-27 15:55:31 +0100 | [diff] [blame] | 38 | |
Anthony Barbier | 2a07e18 | 2017-08-04 18:20:27 +0100 | [diff] [blame] | 39 | namespace arm_compute |
| 40 | { |
| 41 | namespace graph_utils |
| 42 | { |
Georgios Pinitas | 140fdc7 | 2018-02-16 11:42:38 +0000 | [diff] [blame] | 43 | /** Preprocessor interface **/ |
| 44 | class IPreprocessor |
| 45 | { |
| 46 | public: |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 47 | /** Default destructor. */ |
| 48 | virtual ~IPreprocessor() = default; |
| 49 | /** Preprocess the given tensor. |
| 50 | * |
| 51 | * @param[in] tensor Tensor to preprocess. |
| 52 | */ |
Georgios Pinitas | 140fdc7 | 2018-02-16 11:42:38 +0000 | [diff] [blame] | 53 | virtual void preprocess(ITensor &tensor) = 0; |
| 54 | }; |
| 55 | |
| 56 | /** Caffe preproccessor */ |
| 57 | class CaffePreproccessor : public IPreprocessor |
| 58 | { |
| 59 | public: |
| 60 | /** Default Constructor |
| 61 | * |
| 62 | * @param mean Mean array in RGB ordering |
| 63 | * @param bgr Boolean specifying if the preprocessing should assume BGR format |
| 64 | */ |
| 65 | CaffePreproccessor(std::array<float, 3> mean = std::array<float, 3> { { 0, 0, 0 } }, bool bgr = true); |
| 66 | void preprocess(ITensor &tensor) override; |
| 67 | |
| 68 | private: |
| 69 | std::array<float, 3> _mean; |
| 70 | bool _bgr; |
| 71 | }; |
| 72 | |
| 73 | /** TF preproccessor */ |
| 74 | class TFPreproccessor : public IPreprocessor |
| 75 | { |
| 76 | public: |
| 77 | void preprocess(ITensor &tensor) override; |
| 78 | }; |
| 79 | |
Anthony Barbier | 2a07e18 | 2017-08-04 18:20:27 +0100 | [diff] [blame] | 80 | /** PPM writer class */ |
| 81 | class PPMWriter : public graph::ITensorAccessor |
| 82 | { |
| 83 | public: |
| 84 | /** Constructor |
| 85 | * |
| 86 | * @param[in] name PPM file name |
| 87 | * @param[in] maximum Maximum elements to access |
| 88 | */ |
| 89 | PPMWriter(std::string name, unsigned int maximum = 1); |
| 90 | /** Allows instances to move constructed */ |
| 91 | PPMWriter(PPMWriter &&) = default; |
| 92 | |
| 93 | // Inherited methods overriden: |
| 94 | bool access_tensor(ITensor &tensor) override; |
| 95 | |
| 96 | private: |
| 97 | const std::string _name; |
| 98 | unsigned int _iterator; |
| 99 | unsigned int _maximum; |
| 100 | }; |
| 101 | |
| 102 | /** Dummy accessor class */ |
Michalis Spyrou | 53b405f | 2017-09-27 15:55:31 +0100 | [diff] [blame] | 103 | class DummyAccessor final : public graph::ITensorAccessor |
Anthony Barbier | 2a07e18 | 2017-08-04 18:20:27 +0100 | [diff] [blame] | 104 | { |
| 105 | public: |
| 106 | /** Constructor |
| 107 | * |
| 108 | * @param[in] maximum Maximum elements to write |
| 109 | */ |
| 110 | DummyAccessor(unsigned int maximum = 1); |
| 111 | /** Allows instances to move constructed */ |
| 112 | DummyAccessor(DummyAccessor &&) = default; |
| 113 | |
| 114 | // Inherited methods overriden: |
| 115 | bool access_tensor(ITensor &tensor) override; |
| 116 | |
| 117 | private: |
| 118 | unsigned int _iterator; |
| 119 | unsigned int _maximum; |
| 120 | }; |
| 121 | |
Isabella Gottardi | 88d5b22 | 2018-04-06 12:24:55 +0100 | [diff] [blame] | 122 | /** NumPy accessor class */ |
| 123 | class NumPyAccessor final : public graph::ITensorAccessor |
| 124 | { |
| 125 | public: |
| 126 | /** Constructor |
| 127 | * |
| 128 | * @param[in] npy_path Path to npy file. |
| 129 | * @param[in] shape Shape of the numpy tensor data. |
| 130 | * @param[in] data_type DataType of the numpy tensor data. |
| 131 | * @param[out] output_stream (Optional) Output stream |
| 132 | */ |
| 133 | NumPyAccessor(std::string npy_path, TensorShape shape, DataType data_type, std::ostream &output_stream = std::cout); |
| 134 | /** Allow instances of this class to be move constructed */ |
| 135 | NumPyAccessor(NumPyAccessor &&) = default; |
| 136 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 137 | NumPyAccessor(const NumPyAccessor &) = delete; |
| 138 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 139 | NumPyAccessor &operator=(const NumPyAccessor &) = delete; |
| 140 | |
| 141 | // Inherited methods overriden: |
| 142 | bool access_tensor(ITensor &tensor) override; |
| 143 | |
| 144 | private: |
| 145 | template <typename T> |
| 146 | void access_numpy_tensor(ITensor &tensor); |
| 147 | |
| 148 | Tensor _npy_tensor; |
| 149 | const std::string _filename; |
| 150 | std::ostream &_output_stream; |
| 151 | }; |
| 152 | |
Gian Marco | 44ec2e7 | 2017-10-19 14:13:38 +0100 | [diff] [blame] | 153 | /** PPM accessor class */ |
| 154 | class PPMAccessor final : public graph::ITensorAccessor |
| 155 | { |
| 156 | public: |
| 157 | /** Constructor |
| 158 | * |
Georgios Pinitas | 140fdc7 | 2018-02-16 11:42:38 +0000 | [diff] [blame] | 159 | * @param[in] ppm_path Path to PPM file |
Georgios Pinitas | 7c3b924 | 2018-06-21 19:01:25 +0100 | [diff] [blame^] | 160 | * @param[in] bgr (Optional) Fill the first plane with blue channel (default = false - RGB format) |
Georgios Pinitas | 140fdc7 | 2018-02-16 11:42:38 +0000 | [diff] [blame] | 161 | * @param[in] preprocessor (Optional) PPM pre-processing object |
Gian Marco | 44ec2e7 | 2017-10-19 14:13:38 +0100 | [diff] [blame] | 162 | */ |
Georgios Pinitas | 140fdc7 | 2018-02-16 11:42:38 +0000 | [diff] [blame] | 163 | PPMAccessor(std::string ppm_path, bool bgr = true, std::unique_ptr<IPreprocessor> preprocessor = nullptr); |
Gian Marco | 44ec2e7 | 2017-10-19 14:13:38 +0100 | [diff] [blame] | 164 | /** Allow instances of this class to be move constructed */ |
| 165 | PPMAccessor(PPMAccessor &&) = default; |
| 166 | |
| 167 | // Inherited methods overriden: |
| 168 | bool access_tensor(ITensor &tensor) override; |
| 169 | |
| 170 | private: |
Georgios Pinitas | 140fdc7 | 2018-02-16 11:42:38 +0000 | [diff] [blame] | 171 | const std::string _ppm_path; |
| 172 | const bool _bgr; |
| 173 | std::unique_ptr<IPreprocessor> _preprocessor; |
Gian Marco | 44ec2e7 | 2017-10-19 14:13:38 +0100 | [diff] [blame] | 174 | }; |
| 175 | |
Georgios Pinitas | 7c3b924 | 2018-06-21 19:01:25 +0100 | [diff] [blame^] | 176 | /** Input Accessor used for network validation */ |
| 177 | class ValidationInputAccessor final : public graph::ITensorAccessor |
| 178 | { |
| 179 | public: |
| 180 | /** Constructor |
| 181 | * |
| 182 | * @param[in] image_list File containing all the images to validate |
| 183 | * @param[in] images_path Path to images. |
| 184 | * @param[in] bgr (Optional) Fill the first plane with blue channel (default = false - RGB format) |
| 185 | * @param[in] start (Optional) Start range |
| 186 | * @param[in] end (Optional) End range |
| 187 | * |
| 188 | * @note |
| 189 | */ |
| 190 | ValidationInputAccessor(const std::string &image_list, |
| 191 | std::string images_path, |
| 192 | bool bgr = true, |
| 193 | unsigned int start = 0, |
| 194 | unsigned int end = 0); |
| 195 | |
| 196 | // Inherited methods overriden: |
| 197 | bool access_tensor(ITensor &tensor) override; |
| 198 | |
| 199 | private: |
| 200 | std::string _path; |
| 201 | std::vector<std::string> _images; |
| 202 | bool _bgr; |
| 203 | size_t _offset; |
| 204 | }; |
| 205 | |
Gian Marco | 44ec2e7 | 2017-10-19 14:13:38 +0100 | [diff] [blame] | 206 | /** Result accessor class */ |
| 207 | class TopNPredictionsAccessor final : public graph::ITensorAccessor |
| 208 | { |
| 209 | public: |
| 210 | /** Constructor |
| 211 | * |
| 212 | * @param[in] labels_path Path to labels text file. |
| 213 | * @param[in] top_n (Optional) Number of output classes to print |
| 214 | * @param[out] output_stream (Optional) Output stream |
| 215 | */ |
| 216 | TopNPredictionsAccessor(const std::string &labels_path, size_t top_n = 5, std::ostream &output_stream = std::cout); |
| 217 | /** Allow instances of this class to be move constructed */ |
| 218 | TopNPredictionsAccessor(TopNPredictionsAccessor &&) = default; |
| 219 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 220 | TopNPredictionsAccessor(const TopNPredictionsAccessor &) = delete; |
| 221 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 222 | TopNPredictionsAccessor &operator=(const TopNPredictionsAccessor &) = delete; |
| 223 | |
| 224 | // Inherited methods overriden: |
| 225 | bool access_tensor(ITensor &tensor) override; |
| 226 | |
| 227 | private: |
Giorgio Arena | a66eaa2 | 2017-12-21 19:50:06 +0000 | [diff] [blame] | 228 | template <typename T> |
| 229 | void access_predictions_tensor(ITensor &tensor); |
| 230 | |
Gian Marco | 44ec2e7 | 2017-10-19 14:13:38 +0100 | [diff] [blame] | 231 | std::vector<std::string> _labels; |
| 232 | std::ostream &_output_stream; |
| 233 | size_t _top_n; |
| 234 | }; |
| 235 | |
Michalis Spyrou | 53b405f | 2017-09-27 15:55:31 +0100 | [diff] [blame] | 236 | /** Random accessor class */ |
| 237 | class RandomAccessor final : public graph::ITensorAccessor |
| 238 | { |
| 239 | public: |
| 240 | /** Constructor |
| 241 | * |
| 242 | * @param[in] lower Lower bound value. |
| 243 | * @param[in] upper Upper bound value. |
| 244 | * @param[in] seed (Optional) Seed used to initialise the random number generator. |
| 245 | */ |
| 246 | RandomAccessor(PixelValue lower, PixelValue upper, const std::random_device::result_type seed = 0); |
| 247 | /** Allows instances to move constructed */ |
| 248 | RandomAccessor(RandomAccessor &&) = default; |
| 249 | |
| 250 | // Inherited methods overriden: |
| 251 | bool access_tensor(ITensor &tensor) override; |
| 252 | |
| 253 | private: |
| 254 | template <typename T, typename D> |
| 255 | void fill(ITensor &tensor, D &&distribution); |
| 256 | PixelValue _lower; |
| 257 | PixelValue _upper; |
| 258 | std::random_device::result_type _seed; |
| 259 | }; |
| 260 | |
Anthony Barbier | 2a07e18 | 2017-08-04 18:20:27 +0100 | [diff] [blame] | 261 | /** Numpy Binary loader class*/ |
Michalis Spyrou | 53b405f | 2017-09-27 15:55:31 +0100 | [diff] [blame] | 262 | class NumPyBinLoader final : public graph::ITensorAccessor |
Anthony Barbier | 2a07e18 | 2017-08-04 18:20:27 +0100 | [diff] [blame] | 263 | { |
| 264 | public: |
| 265 | /** Default Constructor |
| 266 | * |
Georgios Pinitas | cac13b1 | 2018-04-27 19:07:19 +0100 | [diff] [blame] | 267 | * @param[in] filename Binary file name |
| 268 | * @param[in] file_layout (Optional) Layout of the numpy tensor data. Defaults to NCHW |
Anthony Barbier | 2a07e18 | 2017-08-04 18:20:27 +0100 | [diff] [blame] | 269 | */ |
Georgios Pinitas | cac13b1 | 2018-04-27 19:07:19 +0100 | [diff] [blame] | 270 | NumPyBinLoader(std::string filename, DataLayout file_layout = DataLayout::NCHW); |
Anthony Barbier | 2a07e18 | 2017-08-04 18:20:27 +0100 | [diff] [blame] | 271 | /** Allows instances to move constructed */ |
| 272 | NumPyBinLoader(NumPyBinLoader &&) = default; |
| 273 | |
| 274 | // Inherited methods overriden: |
| 275 | bool access_tensor(ITensor &tensor) override; |
| 276 | |
| 277 | private: |
| 278 | const std::string _filename; |
Georgios Pinitas | cac13b1 | 2018-04-27 19:07:19 +0100 | [diff] [blame] | 279 | const DataLayout _file_layout; |
Anthony Barbier | 2a07e18 | 2017-08-04 18:20:27 +0100 | [diff] [blame] | 280 | }; |
Isabella Gottardi | a4c6188 | 2017-11-03 12:11:55 +0000 | [diff] [blame] | 281 | |
Georgios Pinitas | 652bde5 | 2018-01-10 15:33:28 +0000 | [diff] [blame] | 282 | /** Generates appropriate random accessor |
| 283 | * |
| 284 | * @param[in] lower Lower random values bound |
| 285 | * @param[in] upper Upper random values bound |
| 286 | * @param[in] seed Random generator seed |
| 287 | * |
| 288 | * @return A ramdom accessor |
| 289 | */ |
| 290 | inline std::unique_ptr<graph::ITensorAccessor> get_random_accessor(PixelValue lower, PixelValue upper, const std::random_device::result_type seed = 0) |
| 291 | { |
| 292 | return arm_compute::support::cpp14::make_unique<RandomAccessor>(lower, upper, seed); |
| 293 | } |
| 294 | |
Isabella Gottardi | a4c6188 | 2017-11-03 12:11:55 +0000 | [diff] [blame] | 295 | /** Generates appropriate weights accessor according to the specified path |
| 296 | * |
| 297 | * @note If path is empty will generate a DummyAccessor else will generate a NumPyBinLoader |
| 298 | * |
Georgios Pinitas | cac13b1 | 2018-04-27 19:07:19 +0100 | [diff] [blame] | 299 | * @param[in] path Path to the data files |
| 300 | * @param[in] data_file Relative path to the data files from path |
| 301 | * @param[in] file_layout (Optional) Layout of file. Defaults to NCHW |
Isabella Gottardi | a4c6188 | 2017-11-03 12:11:55 +0000 | [diff] [blame] | 302 | * |
| 303 | * @return An appropriate tensor accessor |
| 304 | */ |
Georgios Pinitas | cac13b1 | 2018-04-27 19:07:19 +0100 | [diff] [blame] | 305 | inline std::unique_ptr<graph::ITensorAccessor> get_weights_accessor(const std::string &path, |
| 306 | const std::string &data_file, |
| 307 | DataLayout file_layout = DataLayout::NCHW) |
Isabella Gottardi | a4c6188 | 2017-11-03 12:11:55 +0000 | [diff] [blame] | 308 | { |
| 309 | if(path.empty()) |
| 310 | { |
| 311 | return arm_compute::support::cpp14::make_unique<DummyAccessor>(); |
| 312 | } |
| 313 | else |
| 314 | { |
Georgios Pinitas | cac13b1 | 2018-04-27 19:07:19 +0100 | [diff] [blame] | 315 | return arm_compute::support::cpp14::make_unique<NumPyBinLoader>(path + data_file, file_layout); |
Isabella Gottardi | a4c6188 | 2017-11-03 12:11:55 +0000 | [diff] [blame] | 316 | } |
| 317 | } |
| 318 | |
| 319 | /** Generates appropriate input accessor according to the specified ppm_path |
| 320 | * |
| 321 | * @note If ppm_path is empty will generate a DummyAccessor else will generate a PPMAccessor |
| 322 | * |
Georgios Pinitas | 140fdc7 | 2018-02-16 11:42:38 +0000 | [diff] [blame] | 323 | * @param[in] ppm_path Path to PPM file |
| 324 | * @param[in] preprocessor Preproccessor object |
| 325 | * @param[in] bgr (Optional) Fill the first plane with blue channel (default = true) |
Isabella Gottardi | a4c6188 | 2017-11-03 12:11:55 +0000 | [diff] [blame] | 326 | * |
| 327 | * @return An appropriate tensor accessor |
| 328 | */ |
Georgios Pinitas | 140fdc7 | 2018-02-16 11:42:38 +0000 | [diff] [blame] | 329 | inline std::unique_ptr<graph::ITensorAccessor> get_input_accessor(const std::string &ppm_path, |
| 330 | std::unique_ptr<IPreprocessor> preprocessor = nullptr, |
| 331 | bool bgr = true) |
Isabella Gottardi | a4c6188 | 2017-11-03 12:11:55 +0000 | [diff] [blame] | 332 | { |
| 333 | if(ppm_path.empty()) |
| 334 | { |
| 335 | return arm_compute::support::cpp14::make_unique<DummyAccessor>(); |
| 336 | } |
| 337 | else |
| 338 | { |
Isabella Gottardi | 88d5b22 | 2018-04-06 12:24:55 +0100 | [diff] [blame] | 339 | if(arm_compute::utility::endswith(ppm_path, ".npy")) |
| 340 | { |
| 341 | return arm_compute::support::cpp14::make_unique<NumPyBinLoader>(ppm_path); |
| 342 | } |
| 343 | else |
| 344 | { |
| 345 | return arm_compute::support::cpp14::make_unique<PPMAccessor>(ppm_path, bgr, std::move(preprocessor)); |
| 346 | } |
Isabella Gottardi | a4c6188 | 2017-11-03 12:11:55 +0000 | [diff] [blame] | 347 | } |
| 348 | } |
| 349 | |
| 350 | /** Generates appropriate output accessor according to the specified labels_path |
| 351 | * |
| 352 | * @note If labels_path is empty will generate a DummyAccessor else will generate a TopNPredictionsAccessor |
| 353 | * |
| 354 | * @param[in] labels_path Path to labels text file |
| 355 | * @param[in] top_n (Optional) Number of output classes to print |
| 356 | * @param[out] output_stream (Optional) Output stream |
| 357 | * |
| 358 | * @return An appropriate tensor accessor |
| 359 | */ |
| 360 | inline std::unique_ptr<graph::ITensorAccessor> get_output_accessor(const std::string &labels_path, size_t top_n = 5, std::ostream &output_stream = std::cout) |
| 361 | { |
| 362 | if(labels_path.empty()) |
| 363 | { |
Anthony Barbier | e1a905a | 2017-12-22 13:53:46 +0000 | [diff] [blame] | 364 | return arm_compute::support::cpp14::make_unique<DummyAccessor>(0); |
Isabella Gottardi | a4c6188 | 2017-11-03 12:11:55 +0000 | [diff] [blame] | 365 | } |
| 366 | else |
| 367 | { |
| 368 | return arm_compute::support::cpp14::make_unique<TopNPredictionsAccessor>(labels_path, top_n, output_stream); |
| 369 | } |
| 370 | } |
Isabella Gottardi | 88d5b22 | 2018-04-06 12:24:55 +0100 | [diff] [blame] | 371 | /** Generates appropriate npy output accessor according to the specified npy_path |
| 372 | * |
| 373 | * @note If npy_path is empty will generate a DummyAccessor else will generate a NpyAccessor |
| 374 | * |
| 375 | * @param[in] npy_path Path to npy file. |
| 376 | * @param[in] shape Shape of the numpy tensor data. |
| 377 | * @param[in] data_type DataType of the numpy tensor data. |
| 378 | * @param[out] output_stream (Optional) Output stream |
| 379 | * |
| 380 | * @return An appropriate tensor accessor |
| 381 | */ |
| 382 | inline std::unique_ptr<graph::ITensorAccessor> get_npy_output_accessor(const std::string &npy_path, TensorShape shape, DataType data_type, std::ostream &output_stream = std::cout) |
| 383 | { |
| 384 | if(npy_path.empty()) |
| 385 | { |
| 386 | return arm_compute::support::cpp14::make_unique<DummyAccessor>(0); |
| 387 | } |
| 388 | else |
| 389 | { |
| 390 | return arm_compute::support::cpp14::make_unique<NumPyAccessor>(npy_path, shape, data_type, output_stream); |
| 391 | } |
| 392 | } |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 393 | |
| 394 | /** Utility function to return the TargetHint |
| 395 | * |
| 396 | * @param[in] target Integer value which expresses the selected target. Must be 0 for NEON or 1 for OpenCL or 2 (OpenCL with Tuner) |
| 397 | * |
| 398 | * @return the TargetHint |
| 399 | */ |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 400 | inline graph::Target set_target_hint(int target) |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 401 | { |
Georgios Pinitas | fbb8054 | 2018-03-27 17:15:49 +0100 | [diff] [blame] | 402 | ARM_COMPUTE_ERROR_ON_MSG(target > 3, "Invalid target. Target must be 0 (NEON), 1 (OpenCL), 2 (OpenCL + Tuner), 3 (GLES)"); |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 403 | if((target == 1 || target == 2)) |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 404 | { |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 405 | return graph::Target::CL; |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 406 | } |
Georgios Pinitas | fbb8054 | 2018-03-27 17:15:49 +0100 | [diff] [blame] | 407 | else if(target == 3) |
| 408 | { |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 409 | return graph::Target::GC; |
Georgios Pinitas | fbb8054 | 2018-03-27 17:15:49 +0100 | [diff] [blame] | 410 | } |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 411 | else |
| 412 | { |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 413 | return graph::Target::NEON; |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 414 | } |
| 415 | } |
Michalis Spyrou | e472082 | 2017-10-02 17:44:52 +0100 | [diff] [blame] | 416 | } // namespace graph_utils |
Anthony Barbier | 2a07e18 | 2017-08-04 18:20:27 +0100 | [diff] [blame] | 417 | } // namespace arm_compute |
| 418 | |
| 419 | #endif /* __ARM_COMPUTE_GRAPH_UTILS_H__ */ |