| 67 | |
| 68 | template <typename T> |
| 69 | void CPPPermuteKernel::run_permute(const Window &window) |
| 70 | { |
| 71 | // Permute strides |
| 72 | Strides strides = _output->info()->strides_in_bytes(); |
| 73 | Strides perm_strides = strides; |
| 74 | permute_strides(perm_strides, _perm); |
| 75 | |
| 76 | // Create output window |
| 77 | Window window_out(window); |
| 78 | const Window::Dimension zero_window = Window::Dimension(0, 0, 0); |
| 79 | for (size_t d = 0; d <= _perm.num_dimensions(); ++d) |
| 80 | { |
| 81 | window_out.set(d, zero_window); |
| 82 | } |
| 83 | |
| 84 | // Create iterators |
| 85 | Iterator in(_input, window); |
| 86 | Iterator out(_output, window_out); |
| 87 | |
| 88 | if (_input->info()->num_dimensions() <= 3) |
| 89 | { |
| 90 | execute_window_loop( |
| 91 | window, |
| 92 | [&](const Coordinates &id) |
| 93 | { |
| 94 | const int idx = id[0] * perm_strides[0] + id[1] * perm_strides[1] + id[2] * perm_strides[2]; |
| 95 | *(reinterpret_cast<T *>(out.ptr() + idx)) = *(reinterpret_cast<const T *>(in.ptr())); |
| 96 | }, |
| 97 | in, out); |
| 98 | } |
| 99 | else if (_input->info()->num_dimensions() >= 4) |
| 100 | { |
| 101 | execute_window_loop( |
| 102 | window, |
| 103 | [&](const Coordinates &id) |
| 104 | { |
| 105 | const int idx = id[0] * perm_strides[0] + id[1] * perm_strides[1] + id[2] * perm_strides[2] + |
| 106 | id[3] * perm_strides[3]; |
| 107 | *(reinterpret_cast<T *>(out.ptr() + idx)) = *(reinterpret_cast<const T *>(in.ptr())); |
| 108 | }, |
| 109 | in, out); |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | CPPPermuteKernel::CPPPermuteKernel() : _func(), _input(nullptr), _output(nullptr), _perm() |
| 114 | { |
nothing calls this directly
no test coverage detected