Skip to content

Commit d278c80

Browse files
committed
Dynamic buffer calculation fix. Other fixes
1 parent 394a5b2 commit d278c80

File tree

3 files changed

+17
-41
lines changed

3 files changed

+17
-41
lines changed

Deeploy/Targets/PULPOpen/Templates/FloatConvTemplate.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,11 @@ def __init__(self, templateStr):
4242
@staticmethod
4343
def computeTransientBuffersSize(
4444
ctxt: NetworkContext,
45-
operatorRepresentation: OperatorRepresentation) -> List[Tuple[str, Union[int, IntVar]]]:
45+
operatorRepresentation: OperatorRepresentation) -> List[Tuple[str, str]]:
4646

4747
# Memory allocation for the im2col buffer can be dynamic, based on the number of cores.
4848
# WARNING: This works because value is only used as string, in the allocate template.
49-
# TODO: This should work as NUM_CORES * P * Q, but it raises an error if double the memory is not allocated.
50-
im2col_dim = "2 * NUM_CORES * " + str(
49+
im2col_dim = "NUM_CORES * " + str(
5150
operatorRepresentation['dim_kernel_x'] * operatorRepresentation['dim_kernel_y'])
5251
im2col_name = operatorRepresentation['nodeName'] + "_buffer"
5352
return [(im2col_name, im2col_dim)]
@@ -58,6 +57,9 @@ def hoistTransientBuffers(self, ctxt: NetworkContext,
5857
ctxt, operatorRepresentation)[0]
5958
ctxt.hoistTransientBuffer(im2col_name, im2col_dim)
6059

60+
# Manually set the type of the im2col buffer to match the input type, since it defaults to void for transient buffers
61+
ctxt.lookup(im2col_name)._type.referencedType = ctxt.lookup(operatorRepresentation['data_in'])._type.referencedType
62+
6163
operatorRepresentation['ctxtBuffer'] = im2col_name
6264
operatorRepresentation['ctxtBufferSize'] = im2col_dim
6365
return ctxt, operatorRepresentation, [im2col_name]
@@ -107,11 +109,11 @@ def hoistTransientBuffers(self, ctxt: NetworkContext,
107109
${stride_y},
108110
${bias}, ${has_bias},
109111
ref_${data_out}_${data_out},
110-
${padding_y_top},
111-
${padding_y_bottom},
112-
${padding_x_left},
113-
${padding_x_right},
114-
${ctxtBuffer}
112+
${padding_y_top},
113+
${padding_y_bottom},
114+
${padding_x_left},
115+
${padding_x_right},
116+
${ctxtBuffer}
115117
);
116118
117119
ref_${data_out}_${data_in} += ${ch_im_in} * ${dim_im_in_x} * ${dim_im_in_y};
@@ -139,11 +141,11 @@ def hoistTransientBuffers(self, ctxt: NetworkContext,
139141
${stride_y},
140142
${bias}, ${has_bias},
141143
ref_${data_out}_${data_out},
142-
${padding_y_top},
143-
${padding_y_bottom},
144-
${padding_x_left},
145-
${padding_x_right},
146-
${ctxtBuffer}
144+
${padding_y_top},
145+
${padding_y_bottom},
146+
${padding_x_left},
147+
${padding_x_right},
148+
${ctxtBuffer}
147149
);
148150
149151
ref_${data_out}_${data_in} += ${ch_im_in} * ${dim_im_in_x} * ${dim_im_in_y};

TargetLibraries/PULPOpen/inc/pulp_core.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99

1010
#define BEGIN_SINGLE_CORE if (pi_core_id() == 0) {
1111
#define END_SINGLE_CORE }
12-
#endif
13-
14-
#ifndef SINGLE_CORE
1512
#define SINGLE_CORE if (pi_core_id() == 0)
1613

1714
#endif //__DEEPLOY_MATH_PULPCORE_HEADER_

TargetLibraries/PULPOpen/src/DWConvolution_fp32.c

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,7 @@
1-
/* =====================================================================
2-
* Title: DWConvolution_fp32.c
3-
* Description: Float32 version of Depthwise Conv2D with NCHW format
4-
* (pre-padded input)
5-
*
6-
* Date: 01.08.2025
7-
*
8-
* =====================================================================
9-
*
10-
* Copyright (C) 2025 ETH Zurich and University of Bologna.
11-
*
12-
* Authors:
13-
* - Calin Diaconu, University of Bologna
1+
/*
2+
* SPDX-FileCopyrightText: 2025 ETH Zurich and University of Bologna
143
*
154
* SPDX-License-Identifier: Apache-2.0
16-
*
17-
* Licensed under the Apache License, Version 2.0 (the License); you may
18-
* not use this file except in compliance with the License.
19-
* You may obtain a copy of the License at
20-
*
21-
* www.apache.org/licenses/LICENSE-2.0
22-
*
23-
* Unless required by applicable law or agreed to in writing, software
24-
* distributed under the License is distributed on an "AS IS" BASIS,
25-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
26-
* See the License for the specific language governing permissions and
27-
* limitations under the License.
285
*/
296

307
#include "DeeployPULPMath.h"

0 commit comments

Comments
 (0)