MCPcopy Create free account
hub / github.com/ARM-software/ComputeLibrary / gather_common

Method gather_common

src/core/NEON/kernels/NEGatherKernel.cpp:86–145  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

84
85template <typename TIndex>
86void NEGatherKernel::gather_common(const Window &window, const ThreadInfo &info)
87{
88 ARM_COMPUTE_UNUSED(info);
89
90 auto dst_win = window;
91
92 const auto src_info = _input->info();
93 const auto idx_info = _indices->info();
94 const auto dst_info = _output->info();
95
96 const auto num_dims = dst_info->num_dimensions();
97 const auto chunk_stride = src_info->strides_in_bytes()[_axis];
98
99 const auto window_start_x = window.x().start();
100 const auto window_end_x = window.x().end();
101 auto window_size_x = src_info->element_size();
102
103 const auto idx_limit = static_cast<TIndex>(src_info->tensor_shape()[_axis]);
104
105 if (_axis != 0)
106 {
107 dst_win.set(0, Window::Dimension(window_start_x, window_start_x + 1, 1));
108 window_size_x *= window_end_x - window_start_x;
109 }
110
111 // Compute source and index tensors window based on the output window.
112 auto src_win = dst_win;
113 Window idx_win;
114
115 for (size_t i = 0; i < idx_info->num_dimensions(); ++i)
116 {
117 src_win.set(_axis + i, Window::Dimension(0, 1, 1));
118 idx_win.set(_axis + i, window[_axis + i]);
119 }
120
121 // Use the custom strides to access all three tensors using the same loop.
122 Iterator src_it(num_dims, _src_it_strides, _input->buffer(), src_info->offset_first_element_in_bytes(), src_win);
123 Iterator idx_it(num_dims, _idx_it_strides, _indices->buffer(), idx_info->offset_first_element_in_bytes(), idx_win);
124 Iterator dst_it(num_dims, dst_info->strides_in_bytes(), _output->buffer(),
125 dst_info->offset_first_element_in_bytes(), dst_win);
126
127 execute_window_loop(
128 dst_win,
129 [&](const Coordinates &)
130 {
131 const auto idx = *reinterpret_cast<const TIndex *>(idx_it.ptr());
132
133 if (idx >= 0 && idx < idx_limit)
134 {
135 const auto src_ptr = src_it.ptr() + idx * chunk_stride;
136
137 std::copy_n(src_ptr, window_size_x, dst_it.ptr());
138 }
139 else
140 {
141 std::fill_n(dst_it.ptr(), window_size_x, 0);
142 }
143 },

Callers

nothing calls this directly

Calls 11

DimensionClass · 0.50
infoMethod · 0.45
num_dimensionsMethod · 0.45
startMethod · 0.45
xMethod · 0.45
endMethod · 0.45
element_sizeMethod · 0.45
setMethod · 0.45
bufferMethod · 0.45
ptrMethod · 0.45

Tested by

no test coverage detected