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

Method prepare

src/cpu/operators/CpuScale.cpp:216–283  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

214}
215
216void CpuScale::prepare(ITensorPack &tensors)
217{
218 if (!_is_prepared)
219 {
220 _is_prepared = true;
221 const auto src = tensors.get_const_tensor(TensorType::ACL_SRC);
222 auto dst = tensors.get_tensor(TensorType::ACL_DST);
223 auto dx = tensors.get_tensor(TensorType::ACL_INT_0);
224 auto dy = tensors.get_tensor(TensorType::ACL_INT_1);
225 auto offsets = tensors.get_tensor(TensorType::ACL_INT_2);
226
227 // Get data layout and width/height indices
228 const int idx_width = get_data_layout_dimension_index(_data_layout, DataLayoutDimension::WIDTH);
229 const int idx_height = get_data_layout_dimension_index(_data_layout, DataLayoutDimension::HEIGHT);
230
231 // Compute the ratio between source width/height and destination width/height
232 const bool is_align_corners_used =
233 _scale_info.align_corners &&
234 arm_compute::scale_utils::is_align_corners_allowed_sampling_policy(_scale_info.sampling_policy);
235 const auto wr = arm_compute::scale_utils::calculate_resize_ratio(
236 src->info()->dimension(idx_width), dst->info()->dimension(idx_width), is_align_corners_used);
237 const auto hr = arm_compute::scale_utils::calculate_resize_ratio(
238 src->info()->dimension(idx_height), dst->info()->dimension(idx_height), is_align_corners_used);
239
240 // Area interpolation behaves as Nearest Neighbour in case of up-sampling
241 InterpolationPolicy policy_to_use =
242 (_scale_info.interpolation_policy == InterpolationPolicy::AREA && wr <= 1.f && hr <= 1.f)
243 ? InterpolationPolicy::NEAREST_NEIGHBOR
244 : _scale_info.interpolation_policy;
245 const SamplingPolicy sampling_policy = _scale_info.sampling_policy;
246
247 bool precompute_indices_weights = arm_compute::scale_utils::is_precomputation_required(
248 _data_layout, src->info()->data_type(), policy_to_use, _scale_info.border_mode);
249
250 if (precompute_indices_weights)
251 {
252 switch (policy_to_use)
253 {
254 case InterpolationPolicy::NEAREST_NEIGHBOR:
255 {
256 // Pre-compute offsets for nearest interpolation
257 precompute_dx_dy_offsets(nullptr, nullptr, offsets, wr, hr, sampling_policy, is_align_corners_used);
258 break;
259 }
260 case InterpolationPolicy::BILINEAR:
261 {
262 // Pre-compute dx, dy and offsets for bilinear interpolation
263 precompute_dx_dy_offsets(dx, dy, offsets, wr, hr, sampling_policy, is_align_corners_used);
264 break;
265 }
266 case InterpolationPolicy::AREA:
267 {
268 break;
269 }
270 default:
271 ARM_COMPUTE_ERROR("Unsupported interpolation mode");
272 }
273 }

Callers

nothing calls this directly

Calls 7

precompute_dx_dy_offsetsFunction · 0.85
get_const_tensorMethod · 0.80
get_tensorMethod · 0.45
dimensionMethod · 0.45
infoMethod · 0.45
data_typeMethod · 0.45

Tested by

no test coverage detected