Skip to content

Commit 32c958e

Browse files
committed
add guard in maxpool parser and kernel for kernel length and strides
1 parent 2e20c89 commit 32c958e

3 files changed

Lines changed: 18 additions & 2 deletions

File tree

Deeploy/Targets/Generic/Parsers.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,13 @@ def __init__(self):
193193
def parseNode(self, node: gs.Node) -> bool:
194194

195195
ret = all([
196-
'ceil_mode' in node.attrs, 'kernel_shape' in node.attrs, 'pads' in node.attrs, 'strides' in node.attrs,
196+
'ceil_mode' in node.attrs,
197+
'kernel_shape' in node.attrs,
198+
'pads' in node.attrs,
199+
'strides' in node.attrs,
197200
len(node.inputs) == 1,
198-
len(node.outputs) >= 1
201+
len(node.outputs) >= 1,
202+
all([stride > 0 for stride in node.attrs['strides']]),
199203
])
200204

201205
if ret:

TargetLibraries/Generic/src/MaxPool_fp32.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ void MaxPool2d_fp32_fp32_NCHW(float32_t const *__restrict__ pSrcA, uint32_t C,
1111
uint32_t SP, uint32_t SQ,
1212
float32_t *__restrict__ pDstC) {
1313

14+
if (H < P || W < Q || SP == 0 || SQ == 0) {
15+
return;
16+
}
1417
uint32_t H_out = (H - P) / SP + 1;
1518
uint32_t W_out = (W - Q) / SQ + 1;
1619

@@ -43,6 +46,9 @@ void MaxPool2d_fp32_fp32_NCHW(float32_t const *__restrict__ pSrcA, uint32_t C,
4346
void MaxPool1d_fp32_fp32(float32_t const *__restrict__ pSrcA, uint32_t C,
4447
uint32_t W, uint32_t K, uint32_t S,
4548
float32_t *__restrict__ pDstC) {
49+
if (W < K || S == 0) {
50+
return;
51+
}
4652
uint32_t W_out = (W - K) / S + 1;
4753
for (uint32_t c = 0; c < C; ++c) {
4854
for (uint32_t w_out = 0; w_out < W_out; ++w_out) {

TargetLibraries/Generic/src/MaxPool_s8.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ void MaxPool2d_s8_s8_NCHW(int8_t const *__restrict__ pSrcA, uint32_t C,
1010
uint32_t H, uint32_t W, uint32_t P, uint32_t Q,
1111
uint32_t SP, uint32_t SQ, int8_t *__restrict__ pDstC,
1212
int32_t input_offset, int32_t output_offset) {
13+
if (H < P || W < Q || SP == 0 || SQ == 0) {
14+
return;
15+
}
1316
// WIESEP: For now assume padding=0
1417
uint32_t H_out = (H - P) / SP + 1;
1518
uint32_t W_out = (W - Q) / SQ + 1;
@@ -52,6 +55,9 @@ void MaxPool2d_s8_s8_NCHW(int8_t const *__restrict__ pSrcA, uint32_t C,
5255
void MaxPool1d_s8_s8(int8_t const *__restrict__ pSrcA, uint32_t C, uint32_t L,
5356
uint32_t K, uint32_t S, int8_t *__restrict__ pDstC,
5457
int32_t input_offset, int32_t output_offset) {
58+
if (L < K || S == 0) {
59+
return;
60+
}
5561
uint32_t L_out = (L - K) / S + 1;
5662
for (uint32_t c = 0; c < C; ++c) {
5763
for (uint32_t l_out = 0; l_out < L_out; ++l_out) {

0 commit comments

Comments
 (0)