1515*******************************************************************************/
1616
1717#include " cpu/aarch64/acl_utils.hpp"
18+ #include < limits>
1819
1920namespace dnnl {
2021namespace impl {
@@ -26,6 +27,17 @@ namespace acl_utils {
2627using namespace dnnl ::impl::alg_kind;
2728using namespace data_type ;
2829
30+ status_t safe_set_strides (arm_compute::Strides &strides, size_t dim, size_t val,
31+ bool inc_dim = true ) {
32+ // ACL stride value is uint32, check for overflow
33+ if (val > std::numeric_limits<uint32_t >::max ()) {
34+ return status::unimplemented;
35+ }
36+
37+ strides.set (dim, val, inc_dim);
38+ return status::success;
39+ }
40+
2941arm_compute::DataType get_acl_data_t (
3042 const dnnl_data_type_t dt, const bool is_quantized) {
3143 switch (dt) {
@@ -154,8 +166,8 @@ status_t tensor_info(
154166 for (int i = md.ndims () - 1 ; i >= 0 ; --i) {
155167 // ACL strides are in bytes, oneDNN strides are in numbers of elements,
156168 // multiply by data type size to convert
157- strides_in_bytes. set (
158- acl_stride_i, blocking_desc.strides [i] * md.data_type_size ());
169+ CHECK ( safe_set_strides (strides_in_bytes, acl_stride_i,
170+ blocking_desc.strides [i] * md.data_type_size () ));
159171 ++acl_stride_i;
160172 }
161173
@@ -190,10 +202,12 @@ status_t insert_singleton_dimension(arm_compute::TensorInfo &ti, size_t dim_i) {
190202 arm_compute::Strides strides;
191203 for (size_t old_i = 0 , new_i = 0 ; old_i < ti.num_dimensions (); ++old_i) {
192204 if (old_i == dim_i) {
193- strides.set (new_i, ti.strides_in_bytes ()[old_i], false );
205+ CHECK (safe_set_strides (
206+ strides, new_i, ti.strides_in_bytes ()[old_i], false ));
194207 ++new_i;
195208 }
196- strides.set (new_i, ti.strides_in_bytes ()[old_i], false );
209+ CHECK (safe_set_strides (
210+ strides, new_i, ti.strides_in_bytes ()[old_i], false ));
197211 ++new_i;
198212 }
199213
@@ -274,9 +288,9 @@ int reorder_dimensions_by_stride(std::vector<memory_desc_t *> permuted_mds,
274288 return reordered_dims;
275289}
276290
277- void reorder_to_weight_format (arm_compute::TensorInfo &info, memory_desc_t &md ,
278- arm_compute::WeightFormat wf, dim_t I_dim, dim_t O_dim ,
279- const std::vector<dim_t > &spatial_dims,
291+ status_t reorder_to_weight_format (arm_compute::TensorInfo &info,
292+ memory_desc_t &md, arm_compute::WeightFormat wf, dim_t I_dim,
293+ dim_t O_dim, const std::vector<dim_t > &spatial_dims,
280294 const std::vector<dim_t > &batch_dims) {
281295
282296 md.format_kind = format_kind::blocked;
@@ -336,12 +350,14 @@ void reorder_to_weight_format(arm_compute::TensorInfo &info, memory_desc_t &md,
336350 // the interleaving). Note that we use the innermost_batch_stride
337351 // because all the batched dimensions are collapsed (as required by ACL).
338352 arm_compute::Strides new_strides_in_bytes = info.strides_in_bytes ();
339- new_strides_in_bytes.set (1 , ldb * info.element_size ());
340- new_strides_in_bytes.set (2 , innermost_batch_stride * info.element_size ());
353+ CHECK (safe_set_strides (new_strides_in_bytes, 1 , ldb * info.element_size ()));
354+ CHECK (safe_set_strides (new_strides_in_bytes, 2 ,
355+ innermost_batch_stride * info.element_size ()));
341356
342357 info.init (info.tensor_shape (), info.num_channels (), info.data_type (),
343358 new_strides_in_bytes, info.offset_first_element_in_bytes (),
344359 memory_desc_wrapper (md).size ());
360+ return status::success;
345361}
346362
347363} // namespace acl_utils
0 commit comments