Skip to content

Commit f2a4710

Browse files
committed
x64: conv: relax large size check for 3d f32/int8 shapes
1 parent c8ec11b commit f2a4710

2 files changed

Lines changed: 34 additions & 3 deletions

File tree

src/cpu/x64/jit_brgemm_conv_utils.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1679,9 +1679,10 @@ status_t init_jcp(jit_brgemm_conv_conf_t &jcp, cpu_isa_t isa,
16791679
const memory_desc_wrapper dst_d(&dst_md);
16801680
const memory_desc_wrapper bias_d(&bias_md);
16811681

1682-
// Big int (> INT_MAX) values are unsupported and jcp fields may overflow
1682+
// Per-tensor spatial product, weights nelems, and per-dim
1683+
// strides/paddings/dilations must fit in int.
16831684
// TODO: change data type of jcp fields to size_t
1684-
VDISPATCH_CONV_IC(!has_large_size(cd, src_d, weights_d, dst_d),
1685+
VDISPATCH_CONV_IC(!has_large_size_relaxed(cd, src_d, weights_d, dst_d),
16851686
VERBOSE_BAD_PARAM, "large size is not supported");
16861687

16871688
const bool with_groups = weights_d.ndims() == src_d.ndims() + 1;
@@ -2658,7 +2659,7 @@ status_t init_1x1_conf(jit_brgemm_conv_conf_t &jcp, cpu_isa_t isa,
26582659

26592660
const size_t rtus_buffer_size = jcp.is_reduced_rtus
26602661
? jcp.rtus_padded_ic_size * jcp.os_block
2661-
: jcp.LDA * jcp.os;
2662+
: static_cast<size_t>(jcp.LDA) * jcp.os;
26622663
jcp.inp_buffer_size
26632664
= jcp.is_rtus ? rnd_up(rtus_buffer_size, align_size) : 0;
26642665

src/cpu/x64/jit_primitive_conf.hpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
308338
struct 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

Comments
 (0)