37 PermuteLayer(
const std::vector<ITensor *> &src_tensors,
const std::vector<ITensor *> &dst_tensors,
38 const std::vector<ir::PermuteType> &types,
39 const std::shared_ptr<ExternalContext> &external_context);
46 std::shared_ptr<ExternalContext> _external_context;
49 void appendPermuteTasks(
const ITensor *src_tensor,
ITensor *dst_tensor,
55 struct PermuteWorkerTask : ruy::Task
62 : _src_buffer{src_tensor.
buffer()}, _dst_buffer{dst_tensor.
buffer()},
63 _src_start_offset{src_tensor.
calcOffset(start_coords)},
64 _dst_start_offset{dst_tensor.
calcOffset(start_coords)}, _src_strides{}, _dst_strides{},
65 _loop_shape{loop_shape}, _size{
size}, _permute_type{permute_type}
68 setStrides(src_tensor, &_src_strides);
69 setStrides(dst_tensor, &_dst_strides);
72 PermuteWorkerTask(
const uint8_t *src_buffer, uint8_t *dst_buffer, uint32_t src_start_offset,
73 uint32_t dst_start_offset,
size_t size)
74 : _src_buffer{src_buffer}, _dst_buffer{dst_buffer}, _src_start_offset{src_start_offset},
75 _dst_start_offset{dst_start_offset}, _src_strides{0}, _dst_strides{0}, _loop_shape{1},
80 void setBuffers(
const uint8_t *src_buffer, uint8_t *dst_buffer)
82 _src_buffer = src_buffer;
83 _dst_buffer = dst_buffer;
88 size_t src_offset = _src_start_offset;
89 size_t dst_offset = _dst_start_offset;
90 assert(
static_cast<size_t>(_loop_shape.rank()) ==
coords.size());
96 for (
auto i = 0; i < _loop_shape.rank(); ++i)
98 assert(
coords[i] >= 0 && dst_coords[i] >= 0);
99 src_offset +=
coords[i] * _src_strides[i];
100 dst_offset += dst_coords[i] * _dst_strides[i];
102 memcpy(_dst_buffer + dst_offset, _src_buffer + src_offset, _size);
107 void setStrides(
const ITensor &tensor, Strides *strides)
109 auto shape = tensor.getShape();
110 const size_t rank = shape.rank();
111 for (
size_t i = 0; i < rank; ++i)
115 if (shape.dim(i) > 1)
117 strides->set(i, tensor.calcOffset(one_step) - tensor.calcOffset(no_step));
125 assert((*strides)[i] >= 0);
130 const uint8_t *_src_buffer;
131 uint8_t *_dst_buffer;
132 size_t _src_start_offset;
133 size_t _dst_start_offset;
134 Strides _src_strides;
135 Strides _dst_strides;
140 std::unordered_map<const ITensor *, std::vector<PermuteWorkerTask>> _tasks_map;
Array< CornerBox > coords