Strided pointwise convolution on rectangular feature maps not correctly handled by InferConvInpGen
hleblevec opened this issue · 3 comments
Quick summary
The tool does not correctly handle strided pointwise convolution with rectangular feature maps anymore. With the previous build, I would use the RTL variant of ConvInpGen which supports this config, but now the transformation is trying to infer a DownSampler node because it detects a strided pointwise Im2Col, but the DownSampler node does not work with rectangular input.
Details
Steps to Reproduce
- Use main branch with release 0.10.0
- Have a model with a Convolution having stride>1 and kernel_size=1 but with non-square feature maps.
- Decompose into Im2Col + MatMul in the streamlining step.
- Run
step_convert_to_hw_layers
.
Expected behavior
ConvInpGen node created with this configuration.
Actual behavior
Triggers a warning:
Optional
Possible fix
- Is it still relevant to have a DownSampler node for the specific case of strided pointwise convolutions? Does it work better than a ConvInpGen in this specific scenario?
- If yes, a possible fix would be, in the case of a rectangular input, to move to normal ConvInpGen in the
InferConvInpGen
transformation rather than skipping the conversion. This node would need to be rewired to the RTL variant in theSpecializeLayers
transformation, which shouldn't be a problem because the_swg_hls_possible
function verifies that the input is square.
finn/src/finn/transformation/fpgadataflow/specialize_layers.py
Lines 201 to 233 in e3087ad
Hi @hleblevec,
Thanks for pointing that out! I actually think we could integrate the functionality of the DownSampler into the ConvolutionInputGenerator custom op structure as one additional variant. This would make this extra node obsolete. Let me know if that would be something you would like to contribute to the repo yourself!
Hi @auphelia,
Yeah sure! If I understood well, it would be a variant introduced by SpecializeLayers
depending on the given parameters?
Yes, so it requires a little bit of refactoring work. But the idea would be to delete DownSampler
+ DownSampler_hls
and convert for the previous cases also to ConvolutionInputGenerator
in convert_to_hw_layers
and then in SpecializeLayers
you would default to the RTL variant but with a square or 1D input, you could also specialize to HLS if the user wants that.
That would mean that the functionality of DownSampler_hls
needs to be integrated into ConvolutionInputGenerator_hls
as an additional variant. It is similar to the integration of the previous custom op ConvolutionInputGenerator1D
that was summarized with ConvolutionInputGenerator
into ConvolutionInputGenerator_hls
. If you need additional pointers, you can reach out via email and we can schedule a meeting to discuss the details.