Skip to content

Commit cd99749

Browse files
committed
cpu: conv: gemm: set threshold for requested scratchpad size
to fix memory allocation segfault on convolutions wuth huge kernels
1 parent 3b48e73 commit cd99749

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/cpu/gemm_convolution_utils.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,6 +1115,17 @@ status_t init_conf(jit_gemm_conv_conf_t &jcp,
11151115
sizeof(float) * jcp.oc * jcp.ngroups);
11161116
}
11171117
}
1118+
// Heuristic threshold for requested scratchpad memory to avoid
1119+
// possible crash on memory allocation:
1120+
// 1Gb or size of the buffers already used for this convolution proportional
1121+
// to the number of threads and multiplied by a heuristic coefficient (15)
1122+
size_t scratchpad_limit_by_absolute_value = (size_t)1 << 30; // 1Gb
1123+
size_t scratchpad_limit_by_tensor_sizes = 15 * max_threads
1124+
* (src_d.size() + weights_d.size() + dst_d.size());
1125+
1126+
size_t scratchpad_limit = nstl::min(scratchpad_limit_by_absolute_value,
1127+
scratchpad_limit_by_tensor_sizes);
1128+
if (scratchpad.size() > scratchpad_limit) return status::unimplemented;
11181129
return status::success;
11191130
}
11201131

0 commit comments

Comments
 (0)