blob: 4db053cf9f5141f8714e168e069031dc4869dc80 [file] [log] [blame]
Anthony Barbier2a07e182017-08-04 18:20:27 +01001/*
Giorgio Arenaa66eaa22017-12-21 19:50:06 +00002 * Copyright (c) 2017-2018 ARM Limited.
Anthony Barbier2a07e182017-08-04 18:20:27 +01003 *
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
25#include "utils/GraphUtils.h"
hakanardof36ac352018-02-16 10:06:34 +010026
Georgios Pinitascac13b12018-04-27 19:07:19 +010027#include "arm_compute/core/Helpers.h"
28#include "arm_compute/core/Types.h"
hakanardof36ac352018-02-16 10:06:34 +010029#include "arm_compute/runtime/SubTensor.h"
Georgios Pinitas7c3b9242018-06-21 19:01:25 +010030#include "utils/ImageLoader.h"
Anthony Barbier2a07e182017-08-04 18:20:27 +010031#include "utils/Utils.h"
32
Gian Marco44ec2e72017-10-19 14:13:38 +010033#include <iomanip>
Anthony Barbier2a07e182017-08-04 18:20:27 +010034
35using namespace arm_compute::graph_utils;
36
Georgios Pinitascac13b12018-04-27 19:07:19 +010037namespace
38{
39std::pair<arm_compute::TensorShape, arm_compute::PermutationVector> compute_permutation_paramaters(const arm_compute::TensorShape &shape,
40 arm_compute::DataLayout data_layout)
41{
42 // Set permutation parameters if needed
43 arm_compute::TensorShape permuted_shape = shape;
44 arm_compute::PermutationVector perm;
45 // Permute only if num_dimensions greater than 2
46 if(shape.num_dimensions() > 2)
47 {
48 perm = (data_layout == arm_compute::DataLayout::NHWC) ? arm_compute::PermutationVector(2U, 0U, 1U) : arm_compute::PermutationVector(1U, 2U, 0U);
49
50 arm_compute::PermutationVector perm_shape = (data_layout == arm_compute::DataLayout::NCHW) ? arm_compute::PermutationVector(2U, 0U, 1U) : arm_compute::PermutationVector(1U, 2U, 0U);
51 arm_compute::permute(permuted_shape, perm_shape);
52 }
53
54 return std::make_pair(permuted_shape, perm);
55}
56} // namespace
57
Georgios Pinitas140fdc72018-02-16 11:42:38 +000058void TFPreproccessor::preprocess(ITensor &tensor)
59{
60 Window window;
61 window.use_tensor_dimensions(tensor.info()->tensor_shape());
62
63 execute_window_loop(window, [&](const Coordinates & id)
64 {
65 const float value = *reinterpret_cast<float *>(tensor.ptr_to_element(id));
66 float res = value / 255.f; // Normalize to [0, 1]
67 res = (res - 0.5f) * 2.f; // Map to [-1, 1]
68 *reinterpret_cast<float *>(tensor.ptr_to_element(id)) = res;
69 });
70}
71
72CaffePreproccessor::CaffePreproccessor(std::array<float, 3> mean, bool bgr)
73 : _mean(mean), _bgr(bgr)
74{
75 if(_bgr)
76 {
77 std::swap(_mean[0], _mean[2]);
78 }
79}
80
81void CaffePreproccessor::preprocess(ITensor &tensor)
82{
83 Window window;
84 window.use_tensor_dimensions(tensor.info()->tensor_shape());
85
86 execute_window_loop(window, [&](const Coordinates & id)
87 {
88 const float value = *reinterpret_cast<float *>(tensor.ptr_to_element(id)) - _mean[id.z()];
89 *reinterpret_cast<float *>(tensor.ptr_to_element(id)) = value;
90 });
91}
92
Anthony Barbier2a07e182017-08-04 18:20:27 +010093PPMWriter::PPMWriter(std::string name, unsigned int maximum)
94 : _name(std::move(name)), _iterator(0), _maximum(maximum)
95{
96}
97
98bool PPMWriter::access_tensor(ITensor &tensor)
99{
100 std::stringstream ss;
101 ss << _name << _iterator << ".ppm";
Gian Marco44ec2e72017-10-19 14:13:38 +0100102
103 arm_compute::utils::save_to_ppm(tensor, ss.str());
Anthony Barbier2a07e182017-08-04 18:20:27 +0100104
105 _iterator++;
106 if(_maximum == 0)
107 {
108 return true;
109 }
110 return _iterator < _maximum;
111}
112
113DummyAccessor::DummyAccessor(unsigned int maximum)
114 : _iterator(0), _maximum(maximum)
115{
116}
117
118bool DummyAccessor::access_tensor(ITensor &tensor)
119{
120 ARM_COMPUTE_UNUSED(tensor);
121 bool ret = _maximum == 0 || _iterator < _maximum;
122 if(_iterator == _maximum)
123 {
124 _iterator = 0;
125 }
126 else
127 {
128 _iterator++;
129 }
130 return ret;
131}
132
Isabella Gottardi88d5b222018-04-06 12:24:55 +0100133NumPyAccessor::NumPyAccessor(std::string npy_path, TensorShape shape, DataType data_type, std::ostream &output_stream)
134 : _npy_tensor(), _filename(std::move(npy_path)), _output_stream(output_stream)
135{
136 NumPyBinLoader loader(_filename);
137
138 TensorInfo info(shape, 1, data_type);
139 _npy_tensor.allocator()->init(info);
140 _npy_tensor.allocator()->allocate();
141
142 loader.access_tensor(_npy_tensor);
143}
144
145template <typename T>
146void NumPyAccessor::access_numpy_tensor(ITensor &tensor)
147{
148 const int num_elements = tensor.info()->total_size();
149 int num_mismatches = utils::compare_tensor<T>(tensor, _npy_tensor);
150 float percentage_mismatches = static_cast<float>(num_mismatches) / num_elements;
151
152 _output_stream << "Results: " << 100.f - (percentage_mismatches * 100) << " % matches with the provided output[" << _filename << "]." << std::endl;
153}
154
155bool NumPyAccessor::access_tensor(ITensor &tensor)
156{
157 ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(&tensor, 1, DataType::F32);
158 ARM_COMPUTE_ERROR_ON(_npy_tensor.info()->dimension(0) != tensor.info()->dimension(0));
159
160 switch(tensor.info()->data_type())
161 {
162 case DataType::F32:
163 access_numpy_tensor<float>(tensor);
164 break;
165 default:
166 ARM_COMPUTE_ERROR("NOT SUPPORTED!");
167 }
168
169 return false;
170}
171
Georgios Pinitas140fdc72018-02-16 11:42:38 +0000172PPMAccessor::PPMAccessor(std::string ppm_path, bool bgr, std::unique_ptr<IPreprocessor> preprocessor)
173 : _ppm_path(std::move(ppm_path)), _bgr(bgr), _preprocessor(std::move(preprocessor))
Gian Marco44ec2e72017-10-19 14:13:38 +0100174{
175}
176
177bool PPMAccessor::access_tensor(ITensor &tensor)
178{
179 utils::PPMLoader ppm;
Gian Marco44ec2e72017-10-19 14:13:38 +0100180
181 // Open PPM file
182 ppm.open(_ppm_path);
183
Georgios Pinitascac13b12018-04-27 19:07:19 +0100184 // Get permutated shape and permutation parameters
185 TensorShape permuted_shape = tensor.info()->tensor_shape();
186 arm_compute::PermutationVector perm;
187 if(tensor.info()->data_layout() != DataLayout::NCHW)
188 {
189 std::tie(permuted_shape, perm) = compute_permutation_paramaters(tensor.info()->tensor_shape(), tensor.info()->data_layout());
190 }
191 ARM_COMPUTE_ERROR_ON_MSG(ppm.width() != permuted_shape.x() || ppm.height() != permuted_shape.y(),
192 "Failed to load image file: dimensions [%d,%d] not correct, expected [%d,%d].", ppm.width(), ppm.height(), permuted_shape.x(), permuted_shape.y());
Isabella Gottardia4c61882017-11-03 12:11:55 +0000193
Gian Marco44ec2e72017-10-19 14:13:38 +0100194 // Fill the tensor with the PPM content (BGR)
195 ppm.fill_planar_tensor(tensor, _bgr);
196
Georgios Pinitas140fdc72018-02-16 11:42:38 +0000197 // Preprocess tensor
198 if(_preprocessor)
Gian Marco44ec2e72017-10-19 14:13:38 +0100199 {
Georgios Pinitas140fdc72018-02-16 11:42:38 +0000200 _preprocessor->preprocess(tensor);
201 }
Gian Marco44ec2e72017-10-19 14:13:38 +0100202
203 return true;
204}
205
Georgios Pinitas7c3b9242018-06-21 19:01:25 +0100206ValidationInputAccessor::ValidationInputAccessor(const std::string &image_list,
207 std::string images_path,
208 bool bgr,
209 unsigned int start,
210 unsigned int end)
211 : _path(std::move(images_path)), _images(), _bgr(bgr), _offset(0)
212{
213 ARM_COMPUTE_ERROR_ON_MSG(start > end, "Invalid validation range!");
214
215 std::ifstream ifs;
216 try
217 {
218 ifs.exceptions(std::ifstream::badbit);
219 ifs.open(image_list, std::ios::in | std::ios::binary);
220
221 // Parse image names
222 unsigned int counter = 0;
223 for(std::string line; !std::getline(ifs, line).fail() && counter <= end; ++counter)
224 {
225 // Add image to process if withing range
226 if(counter >= start)
227 {
228 std::stringstream linestream(line);
229 std::string image_name;
230
231 linestream >> image_name;
232 _images.emplace_back(std::move(image_name));
233 }
234 }
235 }
236 catch(const std::ifstream::failure &e)
237 {
238 ARM_COMPUTE_ERROR("Accessing %s: %s", image_list.c_str(), e.what());
239 }
240}
241
242bool ValidationInputAccessor::access_tensor(arm_compute::ITensor &tensor)
243{
244 bool ret = _offset < _images.size();
245 if(ret)
246 {
247 utils::JPEGLoader jpeg;
248
249 // Open JPEG file
250 jpeg.open(_path + _images[_offset++]);
251
252 // Get permutated shape and permutation parameters
253 TensorShape permuted_shape = tensor.info()->tensor_shape();
254 arm_compute::PermutationVector perm;
255 if(tensor.info()->data_layout() != DataLayout::NCHW)
256 {
257 std::tie(permuted_shape, perm) = compute_permutation_paramaters(tensor.info()->tensor_shape(),
258 tensor.info()->data_layout());
259 }
260 ARM_COMPUTE_ERROR_ON_MSG(jpeg.width() != permuted_shape.x() || jpeg.height() != permuted_shape.y(),
261 "Failed to load image file: dimensions [%d,%d] not correct, expected [%d,%d].",
262 jpeg.width(), jpeg.height(), permuted_shape.x(), permuted_shape.y());
263
264 // Fill the tensor with the PPM content (BGR)
265 jpeg.fill_planar_tensor(tensor, _bgr);
266 }
267
268 return ret;
269}
270
Gian Marco44ec2e72017-10-19 14:13:38 +0100271TopNPredictionsAccessor::TopNPredictionsAccessor(const std::string &labels_path, size_t top_n, std::ostream &output_stream)
272 : _labels(), _output_stream(output_stream), _top_n(top_n)
273{
274 _labels.clear();
275
276 std::ifstream ifs;
277
278 try
279 {
280 ifs.exceptions(std::ifstream::badbit);
281 ifs.open(labels_path, std::ios::in | std::ios::binary);
282
283 for(std::string line; !std::getline(ifs, line).fail();)
284 {
285 _labels.emplace_back(line);
286 }
287 }
288 catch(const std::ifstream::failure &e)
289 {
290 ARM_COMPUTE_ERROR("Accessing %s: %s", labels_path.c_str(), e.what());
291 }
292}
293
Giorgio Arenaa66eaa22017-12-21 19:50:06 +0000294template <typename T>
295void TopNPredictionsAccessor::access_predictions_tensor(ITensor &tensor)
Gian Marco44ec2e72017-10-19 14:13:38 +0100296{
Gian Marco44ec2e72017-10-19 14:13:38 +0100297 // Get the predicted class
Giorgio Arenaa66eaa22017-12-21 19:50:06 +0000298 std::vector<T> classes_prob;
Gian Marco44ec2e72017-10-19 14:13:38 +0100299 std::vector<size_t> index;
300
Giorgio Arenaa66eaa22017-12-21 19:50:06 +0000301 const auto output_net = reinterpret_cast<T *>(tensor.buffer() + tensor.info()->offset_first_element_in_bytes());
Gian Marco44ec2e72017-10-19 14:13:38 +0100302 const size_t num_classes = tensor.info()->dimension(0);
303
304 classes_prob.resize(num_classes);
305 index.resize(num_classes);
306
307 std::copy(output_net, output_net + num_classes, classes_prob.begin());
308
309 // Sort results
310 std::iota(std::begin(index), std::end(index), static_cast<size_t>(0));
311 std::sort(std::begin(index), std::end(index),
312 [&](size_t a, size_t b)
313 {
314 return classes_prob[a] > classes_prob[b];
315 });
316
317 _output_stream << "---------- Top " << _top_n << " predictions ----------" << std::endl
318 << std::endl;
319 for(size_t i = 0; i < _top_n; ++i)
320 {
321 _output_stream << std::fixed << std::setprecision(4)
Giorgio Arenaa66eaa22017-12-21 19:50:06 +0000322 << +classes_prob[index.at(i)]
Gian Marco44ec2e72017-10-19 14:13:38 +0100323 << " - [id = " << index.at(i) << "]"
324 << ", " << _labels[index.at(i)] << std::endl;
325 }
Giorgio Arenaa66eaa22017-12-21 19:50:06 +0000326}
327
328bool TopNPredictionsAccessor::access_tensor(ITensor &tensor)
329{
330 ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(&tensor, 1, DataType::F32, DataType::QASYMM8);
331 ARM_COMPUTE_ERROR_ON(_labels.size() != tensor.info()->dimension(0));
332
333 switch(tensor.info()->data_type())
334 {
335 case DataType::QASYMM8:
336 access_predictions_tensor<uint8_t>(tensor);
337 break;
338 case DataType::F32:
339 access_predictions_tensor<float>(tensor);
340 break;
341 default:
342 ARM_COMPUTE_ERROR("NOT SUPPORTED!");
343 }
Gian Marco44ec2e72017-10-19 14:13:38 +0100344
345 return false;
346}
347
Michalis Spyrou53b405f2017-09-27 15:55:31 +0100348RandomAccessor::RandomAccessor(PixelValue lower, PixelValue upper, std::random_device::result_type seed)
349 : _lower(lower), _upper(upper), _seed(seed)
350{
351}
352
353template <typename T, typename D>
354void RandomAccessor::fill(ITensor &tensor, D &&distribution)
355{
356 std::mt19937 gen(_seed);
357
hakanardof36ac352018-02-16 10:06:34 +0100358 if(tensor.info()->padding().empty() && (dynamic_cast<SubTensor *>(&tensor) == nullptr))
Michalis Spyrou53b405f2017-09-27 15:55:31 +0100359 {
360 for(size_t offset = 0; offset < tensor.info()->total_size(); offset += tensor.info()->element_size())
361 {
362 const T value = distribution(gen);
363 *reinterpret_cast<T *>(tensor.buffer() + offset) = value;
364 }
365 }
366 else
367 {
368 // If tensor has padding accessing tensor elements through execution window.
369 Window window;
370 window.use_tensor_dimensions(tensor.info()->tensor_shape());
371
372 execute_window_loop(window, [&](const Coordinates & id)
373 {
374 const T value = distribution(gen);
375 *reinterpret_cast<T *>(tensor.ptr_to_element(id)) = value;
376 });
377 }
378}
379
380bool RandomAccessor::access_tensor(ITensor &tensor)
381{
382 switch(tensor.info()->data_type())
383 {
384 case DataType::U8:
385 {
386 std::uniform_int_distribution<uint8_t> distribution_u8(_lower.get<uint8_t>(), _upper.get<uint8_t>());
387 fill<uint8_t>(tensor, distribution_u8);
388 break;
389 }
390 case DataType::S8:
Michalis Spyrou53b405f2017-09-27 15:55:31 +0100391 {
392 std::uniform_int_distribution<int8_t> distribution_s8(_lower.get<int8_t>(), _upper.get<int8_t>());
393 fill<int8_t>(tensor, distribution_s8);
394 break;
395 }
396 case DataType::U16:
397 {
398 std::uniform_int_distribution<uint16_t> distribution_u16(_lower.get<uint16_t>(), _upper.get<uint16_t>());
399 fill<uint16_t>(tensor, distribution_u16);
400 break;
401 }
402 case DataType::S16:
Michalis Spyrou53b405f2017-09-27 15:55:31 +0100403 {
404 std::uniform_int_distribution<int16_t> distribution_s16(_lower.get<int16_t>(), _upper.get<int16_t>());
405 fill<int16_t>(tensor, distribution_s16);
406 break;
407 }
408 case DataType::U32:
409 {
410 std::uniform_int_distribution<uint32_t> distribution_u32(_lower.get<uint32_t>(), _upper.get<uint32_t>());
411 fill<uint32_t>(tensor, distribution_u32);
412 break;
413 }
414 case DataType::S32:
415 {
416 std::uniform_int_distribution<int32_t> distribution_s32(_lower.get<int32_t>(), _upper.get<int32_t>());
417 fill<int32_t>(tensor, distribution_s32);
418 break;
419 }
420 case DataType::U64:
421 {
422 std::uniform_int_distribution<uint64_t> distribution_u64(_lower.get<uint64_t>(), _upper.get<uint64_t>());
423 fill<uint64_t>(tensor, distribution_u64);
424 break;
425 }
426 case DataType::S64:
427 {
428 std::uniform_int_distribution<int64_t> distribution_s64(_lower.get<int64_t>(), _upper.get<int64_t>());
429 fill<int64_t>(tensor, distribution_s64);
430 break;
431 }
432 case DataType::F16:
433 {
434 std::uniform_real_distribution<float> distribution_f16(_lower.get<float>(), _upper.get<float>());
435 fill<float>(tensor, distribution_f16);
436 break;
437 }
438 case DataType::F32:
439 {
440 std::uniform_real_distribution<float> distribution_f32(_lower.get<float>(), _upper.get<float>());
441 fill<float>(tensor, distribution_f32);
442 break;
443 }
444 case DataType::F64:
445 {
446 std::uniform_real_distribution<double> distribution_f64(_lower.get<double>(), _upper.get<double>());
447 fill<double>(tensor, distribution_f64);
448 break;
449 }
450 default:
451 ARM_COMPUTE_ERROR("NOT SUPPORTED!");
452 }
453 return true;
454}
455
Georgios Pinitascac13b12018-04-27 19:07:19 +0100456NumPyBinLoader::NumPyBinLoader(std::string filename, DataLayout file_layout)
457 : _filename(std::move(filename)), _file_layout(file_layout)
Anthony Barbier2a07e182017-08-04 18:20:27 +0100458{
459}
460
461bool NumPyBinLoader::access_tensor(ITensor &tensor)
462{
463 const TensorShape tensor_shape = tensor.info()->tensor_shape();
464 std::vector<unsigned long> shape;
465
466 // Open file
467 std::ifstream stream(_filename, std::ios::in | std::ios::binary);
468 ARM_COMPUTE_ERROR_ON_MSG(!stream.good(), "Failed to load binary data");
Anthony Barbier87f21cd2017-11-10 16:27:32 +0000469 std::string header = npy::read_header(stream);
Anthony Barbier2a07e182017-08-04 18:20:27 +0100470
471 // Parse header
472 bool fortran_order = false;
473 std::string typestr;
Anthony Barbier87f21cd2017-11-10 16:27:32 +0000474 npy::parse_header(header, typestr, fortran_order, shape);
Anthony Barbier2a07e182017-08-04 18:20:27 +0100475
476 // Check if the typestring matches the given one
477 std::string expect_typestr = arm_compute::utils::get_typestring(tensor.info()->data_type());
478 ARM_COMPUTE_ERROR_ON_MSG(typestr != expect_typestr, "Typestrings mismatch");
479
Georgios Pinitas7f530b32018-01-22 11:20:44 +0000480 // Reverse vector in case of non fortran order
481 if(!fortran_order)
Anthony Barbier2a07e182017-08-04 18:20:27 +0100482 {
Georgios Pinitas7f530b32018-01-22 11:20:44 +0000483 std::reverse(shape.begin(), shape.end());
484 }
485
486 // Correct dimensions (Needs to match TensorShape dimension corrections)
487 if(shape.size() != tensor_shape.num_dimensions())
488 {
489 for(int i = static_cast<int>(shape.size()) - 1; i > 0; --i)
Anthony Barbier2a07e182017-08-04 18:20:27 +0100490 {
Georgios Pinitas7f530b32018-01-22 11:20:44 +0000491 if(shape[i] == 1)
492 {
493 shape.pop_back();
494 }
495 else
496 {
497 break;
498 }
Anthony Barbier2a07e182017-08-04 18:20:27 +0100499 }
500 }
Georgios Pinitas7f530b32018-01-22 11:20:44 +0000501
Georgios Pinitascac13b12018-04-27 19:07:19 +0100502 bool are_layouts_different = (_file_layout != tensor.info()->data_layout());
503
Georgios Pinitas7f530b32018-01-22 11:20:44 +0000504 // Validate tensor ranks
505 ARM_COMPUTE_ERROR_ON_MSG(shape.size() != tensor_shape.num_dimensions(), "Tensor ranks mismatch");
506
Georgios Pinitascac13b12018-04-27 19:07:19 +0100507 // Set permutation parameters if needed
508 TensorShape permuted_shape = tensor_shape;
509 arm_compute::PermutationVector perm;
510 if(are_layouts_different)
511 {
512 std::tie(permuted_shape, perm) = compute_permutation_paramaters(tensor_shape, tensor.info()->data_layout());
513 }
514
Georgios Pinitas7f530b32018-01-22 11:20:44 +0000515 // Validate shapes
516 for(size_t i = 0; i < shape.size(); ++i)
Anthony Barbier2a07e182017-08-04 18:20:27 +0100517 {
Georgios Pinitascac13b12018-04-27 19:07:19 +0100518 ARM_COMPUTE_ERROR_ON_MSG(permuted_shape[i] != shape[i], "Tensor dimensions mismatch");
Anthony Barbier2a07e182017-08-04 18:20:27 +0100519 }
520
Georgios Pinitascac13b12018-04-27 19:07:19 +0100521 // Validate shapes and copy tensor
522 if(!are_layouts_different || perm.num_dimensions() <= 2)
Anthony Barbier2a07e182017-08-04 18:20:27 +0100523 {
Georgios Pinitascac13b12018-04-27 19:07:19 +0100524 // Read data
525 if(tensor.info()->padding().empty() && (dynamic_cast<SubTensor *>(&tensor) == nullptr))
526 {
527 // If tensor has no padding read directly from stream.
528 stream.read(reinterpret_cast<char *>(tensor.buffer()), tensor.info()->total_size());
529 }
530 else
531 {
532 // If tensor has padding accessing tensor elements through execution window.
533 Window window;
534 window.use_tensor_dimensions(tensor_shape);
535
536 execute_window_loop(window, [&](const Coordinates & id)
537 {
538 stream.read(reinterpret_cast<char *>(tensor.ptr_to_element(id)), tensor.info()->element_size());
539 });
540 }
Anthony Barbier2a07e182017-08-04 18:20:27 +0100541 }
542 else
543 {
544 // If tensor has padding accessing tensor elements through execution window.
545 Window window;
Georgios Pinitascac13b12018-04-27 19:07:19 +0100546 window.use_tensor_dimensions(permuted_shape);
Anthony Barbier2a07e182017-08-04 18:20:27 +0100547
548 execute_window_loop(window, [&](const Coordinates & id)
549 {
Georgios Pinitascac13b12018-04-27 19:07:19 +0100550 Coordinates coords(id);
551 arm_compute::permute(coords, perm);
552 stream.read(reinterpret_cast<char *>(tensor.ptr_to_element(coords)), tensor.info()->element_size());
Anthony Barbier2a07e182017-08-04 18:20:27 +0100553 });
554 }
555 return true;
Anthony Barbier87f21cd2017-11-10 16:27:32 +0000556}