Skip to content

Override parent backend optimizer passes with derived backend passes

Javier Duarte requested to merge derived_backend_passes into main

Created by: thesps

Opening this PR for discussion, with the solution if agreed.

In #509 we noticed that if a base and derived Backend class both define an optimizer pass of the same name, it is the base backend pass that remains registered to the derived backend set of passes. This is a bit counterintuitive - I think you'd expect the derived class to override passes in the same way it might override methods. I put the change in a separate branch since it touches something deeper in the framework.

A concrete example from #509:

print(hls4ml.model.optimizer.get_optimizer('vivadoaccelerator:fifo_depth_optimization'))
<hls4ml.backends.vivado.passes.fifo_depth_optimization.FifoDepthOptimization object at 0x7f6f353b5820>

Notice I get the pass registered to vivadoaccelerator backend, which returns an object in hls4ml.backends.vivado.

With this PR I changed the behaviour to register the base class passes first, which are then updated with the current class. So now it yields:

print(hls4ml.model.optimizer.get_optimizer('vivadoaccelerator:fifo_depth_optimization'))
<hls4ml.backends.vivado_accelerator.passes.fifo_depth_optimization.FifoDepthOptimization object at 0x7f35d77f65e0>

As expected, getting the pass from vivadoaccelerator returns the pass from hls4ml.backends.vivado_accelerator.

I think this case is our only example of the derived class defining a pass of the same name as the parent class. The backends that derive from FPGABackend only add passes, they don't override (I think).

Merge request reports

Loading