Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
5d65505
Added binding and kernel for generic float DW Conv2D. Added bias hand…
diaconuccalin May 5, 2025
fe90854
Updated changelog
diaconuccalin May 5, 2025
135cf70
Applied formatting
diaconuccalin May 6, 2025
f7e471d
Merge branch 'devel' into float_conv2d_dw
diaconuccalin May 6, 2025
8deb735
Added bias handling for DW Conv2D Generic kernel
diaconuccalin May 12, 2025
123c26f
Added bias handling for float regular Conv2D Generic kernel
diaconuccalin May 12, 2025
faa0965
Added regular and DW float Conv2D tests with biases. Fixed the float …
diaconuccalin May 13, 2025
48fe8cc
Restored deleted file
diaconuccalin May 13, 2025
6e3460e
Added new regular and DW float Conv2D bias tests to generic CI pipeline
diaconuccalin May 13, 2025
edc43e1
Reformat
diaconuccalin May 13, 2025
2356bc9
Updated CHANGELOG
diaconuccalin May 13, 2025
32624d0
Fixed naming in CI file
diaconuccalin May 13, 2025
762030b
Revert "Reformat"
diaconuccalin May 15, 2025
b705fa7
rv32imf_xpulpv2 ISA support for Siracusa platform (#64)
runwangdl May 6, 2025
79af6a2
Added bias handling for DW Conv2D Generic kernel
diaconuccalin May 12, 2025
d33f374
Added bias handling for float regular Conv2D Generic kernel
diaconuccalin May 12, 2025
d42534f
Added regular and DW float Conv2D tests with biases. Fixed the float …
diaconuccalin May 13, 2025
fb92ab2
Restored deleted file
diaconuccalin May 13, 2025
eb623ea
Added new regular and DW float Conv2D bias tests to generic CI pipeline
diaconuccalin May 13, 2025
1668d8e
Reformat
diaconuccalin May 13, 2025
8f6d509
Updated CHANGELOG
diaconuccalin May 13, 2025
c95c5a6
Fixed naming in CI file
diaconuccalin May 13, 2025
98cd5ab
Revert "Reformat"
diaconuccalin May 15, 2025
87fb976
Merge branch 'float_conv2d_dw' of https://github.com/diaconuccalin/De…
diaconuccalin May 15, 2025
b7162a7
Merge branch 'devel' into float_conv2d_dw
diaconuccalin May 15, 2025
f24288e
Created new make target and script to only format files modified in c…
diaconuccalin May 15, 2025
c63c774
Applied formatting
diaconuccalin May 15, 2025
4210ce2
Moved the empty conv bias optimization from parser to optimization
diaconuccalin May 15, 2025
1304409
Merge branch 'devel' into float_conv2d_dw
diaconuccalin May 20, 2025
ae750da
Merge branch 'devel' into float_conv2d_dw
diaconuccalin May 21, 2025
980c230
Revert "Created new make target and script to only format files modif…
diaconuccalin May 22, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,13 @@ jobs:
testFloatAdder
testFloatGEMM
testFloat2DConvolution
testFloat2DConvolutionBias
testFloat2DConvolutionZeroBias
testFloatLayerNorm
testFloatDiv
testFloat2DDWConvolution
testFloat2DDWConvolutionBias
testFloat2DDWConvolutionZeroBias
testFloatRelu
testFloatMaxPool
testFloatMatmul
Expand Down
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,15 @@ Change main.c to use OUTPUTTYPE instead of float
- HOTFIX: Deeploy subdirectories installed when installing Deeploy with pip install
- HOTFIX: Linking TEST_RECENT on MacOS


## Add RV32IMF Picolibc support for Siracusa platform

### Added
- Adds RV32IMF Picolib to the toolchain

## Add Generic Float DW Conv2D Kernel

### Added
- Generic float DW Conv2D kernel and bindings.
- Bias handling and computation for regular and DW Conv2D.
- Empty bias handling for generic regular and DW Conv2D.
- Tests for Conv2D regular and DW, with and without bias (and included them in the CI pipeline).
Original file line number Diff line number Diff line change
Expand Up @@ -635,3 +635,33 @@ def __init__(self):
graph.inputs.append(_input)

super().__init__(graph, _remove_global_output_reshape_fun, "_REMOVE_GLOBAL_OUTPUT_RESHAPE_PASS")


def _remove_empty_conv_bias_fun(graph: gs.Graph, match: Match, name: str):
# Extract matched convolution
matched_nodes = list(match.nodes_map.values())
opNode = matched_nodes[0]

# Check if the Conv node has a bias input
# If it does, check if the bias only contains zeros
if len(opNode.inputs) > 2 and np.all(opNode.inputs[2].values == 0):
del opNode.inputs[2]

# Return updated graph
return graph


@contextagnostic
class RemoveEmptyConvBiasPass(ReplaceSequentialPatternPass):

def __init__(self):
# Initialized graph with a Conv node
graph = gs.Graph()
_input = gs.Variable(name = 'input_1')
output = graph.layer(inputs = [_input], outputs = ['convOut'], op = 'Conv', name = 'conv')
graph.outputs.append(output)
graph.inputs.append(_input)

# Apply function
name = "_REMOVE_EMPTY_CONV_BIAS_PASS"
super().__init__(graph, _remove_empty_conv_bias_fun, name)
30 changes: 19 additions & 11 deletions Deeploy/Targets/Generic/Bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
#
# File: BasicBindings.py
#
# Last edited: 17.12.2022
# Last edited: 05.05.2025
#
# Copyright (C) 2022, ETH Zurich and University of Bologna.
# Copyright (C) 2025, ETH Zurich and University of Bologna.
#
# Author:
# Authors:
# - Moritz Scherer, ETH Zurich
# - Philip Wiese, ETH Zurich
# - Calin Diaconu, University of Bologna
#
# ----------------------------------------------------------------------
# SPDX-License-Identifier: Apache-2.0
Expand Down Expand Up @@ -36,12 +37,12 @@
from Deeploy.FutureExtension.CodeTransformationPasses.FutureCodeTransformation import FutureGeneration
from Deeploy.Targets.Generic.Templates import AddTemplate, ConcatTemplate, ConvTemplate, DebugPrintTemplate, \
DequantTemplate, DummyTemplate, DWConvTemplate, FloatAddTemplate, FloatConvTemplate, FloatDivTemplate, \
FloatGELUTemplate, FloatGemmTemplate, FloatLayernormTemplate, FloatMatMulTemplate, FloatMaxPoolTemplate, \
FloatMulTemplate, FloatPadTemplate, FloatReluTemplate, FloatSoftmaxTemplate, GatherTemplate, GemmTemplate, \
IntegerDivTemplate, ITAMaxTemplate, ITAPartialMaxTemplate, MatMulTemplate, MaxPoolTemplate, MulTemplate, \
PadTemplate, QuantTemplate, ReduceMeanTemplate, ReduceSumTemplate, RequantShiftTemplate, ReshapeTemplate, \
RQIntegerDivTemplate, RQSiGELUTemplate, SliceTemplate, TransposeTemplate, iGELUTemplate, iLayernormTemplate, \
iRMSNormTemplate, iSoftmaxTemplate
FloatDWConvTemplate, FloatGELUTemplate, FloatGemmTemplate, FloatLayernormTemplate, FloatMatMulTemplate, \
FloatMaxPoolTemplate, FloatMulTemplate, FloatPadTemplate, FloatReluTemplate, FloatSoftmaxTemplate, GatherTemplate, \
GemmTemplate, IntegerDivTemplate, ITAMaxTemplate, ITAPartialMaxTemplate, MatMulTemplate, MaxPoolTemplate, \
MulTemplate, PadTemplate, QuantTemplate, ReduceMeanTemplate, ReduceSumTemplate, RequantShiftTemplate, \
ReshapeTemplate, RQIntegerDivTemplate, RQSiGELUTemplate, SliceTemplate, TransposeTemplate, iGELUTemplate, \
iLayernormTemplate, iRMSNormTemplate, iSoftmaxTemplate
from Deeploy.Targets.Generic.TypeCheckers import AddChecker, ConcatChecker, ConvChecker, DebugPrintChecker, \
DequantChecker, DivChecker, DummyChecker, GatherChecker, GELUChecker, GEMMChecker, LayerNormChecker, \
MatMulChecker, MaxPoolChecker, MulChecker, PadChecker, QuantChecker, ReduceMeanChecker, ReduceSumChecker, \
Expand Down Expand Up @@ -91,8 +92,15 @@
BasicTransformer)
]

BasicDWConv2DBinding = NodeBinding(ConvChecker([PointerClass(int8_t), PointerClass(int8_t)], [PointerClass(int32_t)]),
DWConvTemplate.reference2DTemplate, BasicTransformer)
BasicDWConv2DBindings = [
NodeBinding(ConvChecker([PointerClass(int8_t), PointerClass(int8_t)], [PointerClass(int32_t)]),
DWConvTemplate.reference2DTemplate, BasicTransformer)
] + [
NodeBinding(
ConvChecker([PointerClass(float32_t), PointerClass(float32_t),
PointerClass(float32_t)], [PointerClass(float32_t)]), FloatDWConvTemplate.reference2DTemplate,
BasicTransformer)
]

BasicDebugPrintBindings = [
NodeBinding(DebugPrintChecker([PointerClass(type)], [PointerClass(type)]), DebugPrintTemplate.referenceTemplate,
Expand Down
32 changes: 29 additions & 3 deletions Deeploy/Targets/Generic/Parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
#
# File: BasicParsers.py
#
# Last edited: 15.12.2021
# Last edited: 12.05.2025
#
# Copyright (C) 2021, ETH Zurich and University of Bologna.
# Copyright (C) 2025, ETH Zurich and University of Bologna.
#
# Authors:
# - Moritz Scherer, ETH Zurich
# - Victor Jung, ETH Zurich
# - Calin Diaconu, University of Bologna
#
# ----------------------------------------------------------------------
# SPDX-License-Identifier: Apache-2.0
Expand Down Expand Up @@ -2138,7 +2139,22 @@ def parseNodeCtxt(self,

newCtxt, ret = super().parseNodeCtxt(ctxt, node, channels_first)

if not ret:
if ret:
inputs = ['data_in', 'weight']

# Handle bias, if present
if len(node.inputs) > 2:
inputs.append("bias")
self.operatorRepresentation["has_bias"] = "true"
else:
self.operatorRepresentation["has_bias"] = "false"
self.operatorRepresentation["bias"] = "NULL"

for idx, inputNode in enumerate(node.inputs):
self.operatorRepresentation[inputs[idx]] = ctxt.lookup(inputNode.name).name

return newCtxt, True
else:
return ctxt, False

assert len(node.inputs
Expand Down Expand Up @@ -2178,8 +2194,18 @@ def parseNodeCtxt(self,

if ret:
inputs = ['data_in', 'weight']

# Handle bias, if present
if len(node.inputs) > 2:
inputs.append("bias")
self.operatorRepresentation["has_bias"] = "true"
else:
self.operatorRepresentation["has_bias"] = "false"
self.operatorRepresentation["bias"] = "NULL"

for idx, inputNode in enumerate(node.inputs):
self.operatorRepresentation[inputs[idx]] = ctxt.lookup(inputNode.name).name

if self.operatorRepresentation['group'] == self.operatorRepresentation['ch_im_in']:
return newCtxt, True

Expand Down
12 changes: 8 additions & 4 deletions Deeploy/Targets/Generic/Platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
#
# File: GenericPlatform.py
#
# Last edited: 17.12.2022
# Last edited: 05.05.2025
#
# Copyright (C) 2022, ETH Zurich and University of Bologna.
# Copyright (C) 2025, ETH Zurich and University of Bologna.
#
# Author:
# - Moritz Scherer, ETH Zurich
# - Philip Wiese, ETH Zurich
# - Calin Diaconu, University of Bologna
#
# ----------------------------------------------------------------------
# SPDX-License-Identifier: Apache-2.0
Expand All @@ -25,10 +26,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from Deeploy.CommonExtensions.OptimizationPasses.TopologyOptimizationPasses.LoweringOptimizationPasses import \
RemoveEmptyConvBiasPass
from Deeploy.DeeployTypes import ConstantBuffer, DeploymentEngine, DeploymentPlatform, NodeMapper, NodeTemplate, \
StructBuffer, TopologyOptimizer, TransientBuffer, VariableBuffer
from Deeploy.Targets.Generic.Bindings import BasicAddBindings, BasicConv1DBinding, BasicConv2DBindings, \
BasicDebugPrintBindings, BasicDequantBindings, BasicDivBindings, BasicDWConv1DBinding, BasicDWConv2DBinding, \
BasicDebugPrintBindings, BasicDequantBindings, BasicDivBindings, BasicDWConv1DBinding, BasicDWConv2DBindings, \
BasicGatherBindings, BasicGELUBindings, BasicGEMMBindings, BasicITAPartialSoftmaxBinding, BasicITASoftmaxBinding, \
BasicLayerNormBindings, BasicMatMulBindings, BasicMaxPool2DBindings, BasicMulBindings, BasicPad1DBindings, \
BasicPad2DBindings, BasicQuantBindings, BasicReduceMeanBindings, BasicReduceSumBindings, BasicReluBinding, \
Expand All @@ -54,7 +57,7 @@
Conv2DMapper = NodeMapper(GenericConv2DParser(), BasicConv2DBindings)
DebugMapper = NodeMapper(DebugParser(), BasicDebugPrintBindings)
DWConv1DMapper = NodeMapper(GenericDWConv1DParser(), [BasicDWConv1DBinding])
DWConv2DMapper = NodeMapper(GenericDWConv2DParser(), [BasicDWConv2DBinding])
DWConv2DMapper = NodeMapper(GenericDWConv2DParser(), BasicDWConv2DBindings)
FlattenMapper = NodeMapper(FlattenParser(), BasicReshapeBindings)
GatherMapper = NodeMapper(GatherParser(), BasicGatherBindings)
GELUMapper = NodeMapper(GELUParser(), BasicGELUBindings)
Expand Down Expand Up @@ -169,6 +172,7 @@ class GenericStructBuffer(StructBuffer):
MergeConstAddAndRequantPass(),
ExtractPaddingFromConvPass(),
ExtractPaddingFromPoolPass(),
RemoveEmptyConvBiasPass(),
# DebugPrintPass(r'.*[Mm]at[Mm]ul.*', position = 'after'),
])

Expand Down
8 changes: 6 additions & 2 deletions Deeploy/Targets/Generic/Templates/FloatConvTemplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
#
# File: FLoatConvTemplate.py
#
# Last edited: 23.01.2025
# Last edited: 12.05.2025
#
# Copyright (C) 2023, ETH Zurich and University of Bologna.
#
# Author: Run Wang, ETH Zurich
# Authors:
# - Run Wang, ETH Zurich
# - Calin Diaconu, University of Bologna
#
# ----------------------------------------------------------------------
# SPDX-License-Identifier: Apache-2.0
Expand Down Expand Up @@ -41,6 +43,8 @@
ref_${data_out}_${data_in}, ${ch_im_in}, ${dim_im_in_x}, ${dim_im_in_y},
${weight}, ${ch_im_out}, ${dim_kernel_x}, ${dim_kernel_y},
${stride_x}, ${stride_y},
${bias},
${has_bias},
ref_${data_out}_${data_out}
);
ref_${data_out}_${data_in} += ${batchOffsetIn};
Expand Down
53 changes: 53 additions & 0 deletions Deeploy/Targets/Generic/Templates/FloatDWConvTemplate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# ----------------------------------------------------------------------
#
# File: FLoatDWConvTemplate.py
#
# Last edited: 12.05.2025
#
# Copyright (C) 2025, ETH Zurich and University of Bologna.
#
# Author:
# - Calin Diaconu, University of Bologna
#
# ----------------------------------------------------------------------
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the License); you may
# not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an AS IS BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from Deeploy.DeeployTypes import NodeTemplate

reference2DTemplate = NodeTemplate("""
<%
batchOffsetIn = ch_im_in * dim_im_in_x * dim_im_in_y
batchOffsetOut = ch_im_out * dim_im_out_x * dim_im_out_y
%>
// 2D FP Depth-wise Conv (Name: ${nodeName}, Op: ${nodeOp})
BEGIN_SINGLE_CORE
${data_in_type.typeName} ref_${data_out}_${data_in} = ${data_in};
${data_out_type.typeName} ref_${data_out}_${data_out} = ${data_out};
for (uint32_t n=0; n<${batch}; ++n) {
DWConv2d_fp${data_in_type.referencedType.typeWidth}_fp${weight_type.referencedType.typeWidth}_fp${data_out_type.referencedType.typeWidth}_NCHW(
ref_${data_out}_${data_in},
${ch_im_in}, ${dim_im_in_x}, ${dim_im_in_y},
${weight},
${ch_im_out}, ${dim_kernel_x}, ${dim_kernel_y},
${stride_x}, ${stride_y},
${bias},
${has_bias},
ref_${data_out}_${data_out}
);
ref_${data_out}_${data_in} += ${batchOffsetIn};
ref_${data_out}_${data_out} += ${batchOffsetOut};
}
END_SINGLE_CORE
""")
11 changes: 6 additions & 5 deletions Deeploy/Targets/MemPool/Platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
#
# File: MemPoolPlatform.py
#
# Last edited: 17.12.2022
# Last edited: 05.05.2025
#
# Copyright (C) 2022, ETH Zurich and University of Bologna.
# Copyright (C) 2025, ETH Zurich and University of Bologna.
#
# Author:
# Authors:
# - Philip Wiese, ETH Zurich
# - Calin Diaconu, University of Bologna
#
# ----------------------------------------------------------------------
# SPDX-License-Identifier: Apache-2.0
Expand All @@ -31,7 +32,7 @@
from Deeploy.DeeployTypes import ConstantBuffer, DeploymentEngine, DeploymentPlatform, NodeMapper, NodeTemplate, \
StructBuffer, TopologyOptimizer, TransientBuffer, VariableBuffer
from Deeploy.Targets.Generic.Bindings import BasicAddBindings, BasicConv1DBinding, BasicConv2DBindings, \
BasicDebugPrintBindings, BasicDivBindings, BasicDWConv1DBinding, BasicDWConv2DBinding, BasicGatherBindings, \
BasicDebugPrintBindings, BasicDivBindings, BasicDWConv1DBinding, BasicDWConv2DBindings, BasicGatherBindings, \
BasicGELUBindings, BasicLayerNormBindings, BasicMulBindings, BasicPad1DBindings, BasicPad2DBindings, \
BasicReduceMeanBindings, BasicReduceSumBindings, BasicReshapeBindings, BasicRQIntegerDivBinding, \
BasicRQSGELUBinding, BasicSliceBindings, BasicSoftmaxBindings, BasicTransposeBindings, DummyBinding
Expand Down Expand Up @@ -62,7 +63,7 @@
GenericConv1D_Mapper = NodeMapper(GenericConv1DParser(), [BasicConv1DBinding])
GenericDWConv1D_Mapper = NodeMapper(GenericDWConv1DParser(), [BasicDWConv1DBinding])
GenericConv2D_Mapper = NodeMapper(GenericConv2DParser(), BasicConv2DBindings)
GenericDWConv2D_Mapper = NodeMapper(GenericDWConv2DParser(), [BasicDWConv2DBinding])
GenericDWConv2D_Mapper = NodeMapper(GenericDWConv2DParser(), BasicDWConv2DBindings)

GenericConv_Mappers = [GenericConv2D_Mapper, GenericDWConv2D_Mapper, GenericConv1D_Mapper, GenericDWConv1D_Mapper]

Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
10 changes: 6 additions & 4 deletions TargetLibraries/Generic/inc/kernel/Convolution.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
* Title: Convolution.h
* Description:
*
* Date: 04.01.2023
* Date: 12.05.2025
*
* ===================================================================== */

/*
* Copyright (C) 2023 ETH Zurich and University of Bologna.
* Copyright (C) 2025 ETH Zurich and University of Bologna.
*
* Authors:
* - Philip Wiese, ETH Zurich
* - Calin Diaconu, University of Bologna
*
* SPDX-License-Identifier: Apache-2.0
*
Expand Down Expand Up @@ -62,7 +63,8 @@ void Conv2d_s8_s8_s32_NCHW(int8_t const *__restrict__ pSrcA, uint32_t C,
void Conv2d_fp32_fp32_fp32_NCHW(const float *__restrict__ pSrcA, uint32_t C,
uint32_t H_padded, uint32_t W_padded,
const float *__restrict__ pSrcB, uint32_t F,
uint32_t P, uint32_t Q, uint32_t SP, uint32_t SQ,
float *__restrict__ pDstC);
uint32_t P, uint32_t Q, uint32_t SP,
uint32_t SQ, const float *__restrict__ pSrcBias,
const bool has_bias, float *__restrict__ pDstC);

#endif //__DEEPLOY_BASIC_MATH_CONVOLUTION_KERNEL_HEADER_
Loading
Loading