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

Method prepare

src/cpu/kernels/CpuReshapeKernel.cpp:223–274  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

221}
222
223void CpuReshapeKernel::prepare(ITensorPack &tensors)
224{
225 const auto src = tensors.get_const_tensor(TensorType::ACL_SRC);
226 auto dst = tensors.get_tensor(TensorType::ACL_DST);
227
228 const ITensorInfo *src_info = src->info();
229 const ITensorInfo *dst_info = dst->info();
230
231 // Calculate kernel window based on the padding info
232 Window win;
233
234 const bool src_has_holes = has_holes(*src_info, src_info->num_dimensions() - 1);
235 const bool dst_has_holes = has_holes(*dst_info, dst_info->num_dimensions() - 1);
236 const bool src_has_holes_in_x = has_holes(*src_info, Window::DimX);
237 const bool dst_has_holes_in_x = has_holes(*dst_info, Window::DimX);
238 const auto src_row_size = static_cast<int>(src_info->tensor_shape()[0]);
239 const auto dst_row_size = static_cast<int>(dst_info->tensor_shape()[0]);
240
241 if (!src_has_holes && !dst_has_holes)
242 {
243 std::tie(win, _split_dimension) = calculate_squashed_or_max_window(*dst_info);
244 /*
245 Copy the tensor per window. If the src and dst tensors
246 are contiguous memory allocations without any holes or
247 padding, then the tensor is squashed to 1D window and
248 we can use use a single memcopy call to copy the whole
249 window in reshape_tensor_per_window fn
250 */
251 _reshape_tensor_fn = reshape_tensor_per_window;
252 }
253 else
254 {
255 win = calculate_max_window(*dst_info);
256 /*
257 Copy tensor row by row if src and dst have no holes in X
258 dim and they have the same number of elements in their rows
259 */
260 if (!src_has_holes_in_x && !dst_has_holes_in_x && (src_row_size == dst_row_size))
261 {
262 _reshape_tensor_fn = reshape_tensor_per_row;
263 }
264 else
265 {
266 /*
267 Fall back to the element wise copy
268 */
269 _reshape_tensor_fn = reshape_tensor_per_element_selector;
270 }
271 }
272
273 ICPPKernel::configure(win);
274}
275} // namespace kernels
276} // namespace cpu
277} // namespace arm_compute

Callers

nothing calls this directly

Calls 7

has_holesFunction · 0.85
get_const_tensorMethod · 0.80
calculate_max_windowFunction · 0.50
get_tensorMethod · 0.45
infoMethod · 0.45
num_dimensionsMethod · 0.45

Tested by

no test coverage detected