@@ -305,6 +305,36 @@ inline bool has_large_size(const convolution_desc_t &cd,
305305 return false ;
306306}
307307
308+ // Relaxed version of has_large_size(). The only difference from
309+ // has_large_size() is that this variant checks the per-tensor spatial product
310+ // instead of the count of all consecutive elements excluding the minibatch
311+ // (i.e. spatial * channels). Weights nelems and per-dim strides/paddings/dilations
312+ // are checked the same way. Use this when element offsets into memory are computed
313+ // as dim_t and only per-dim / spatial values need to fit in int.
314+ inline bool has_large_size_relaxed (const convolution_desc_t &cd,
315+ const memory_desc_wrapper &src_d, const memory_desc_wrapper &weights_d,
316+ const memory_desc_wrapper &dst_d) {
317+ auto is_large = [](const dim_t val) { return val > INT_MAX ; };
318+
319+ const int ndims = src_d.ndims ();
320+ dim_t src_spatial = 1 , dst_spatial = 1 ;
321+ for (int d = 2 ; d < ndims; d++) {
322+ src_spatial *= src_d.dims ()[d];
323+ dst_spatial *= dst_d.dims ()[d];
324+ }
325+ if (is_large (src_spatial) || is_large (dst_spatial)) return true ;
326+
327+ if (is_large (weights_d.nelems ())) return true ;
328+
329+ for (int d = 3 ; d <= ndims; d++) {
330+ if (utils::one_of (true , is_large (cd.strides [ndims - d]),
331+ is_large (cd.padding [0 ][ndims - d]),
332+ is_large (cd.dilates [ndims - d])))
333+ return true ;
334+ }
335+ return false ;
336+ }
337+
308338struct jit_conv_args_t {
309339 const void *src = nullptr ; /* hack, non-const for backward_data */
310340 const void *dst = nullptr ; /* hack, non-const for forward */
0 commit comments