Beispiel #1
0
    def _register_flows(self):
        initializers = self._get_layer_initializers()
        init_flow = register_flow('init_layers',
                                  initializers,
                                  requires=['optimize'],
                                  backend=self.name)

        quartus_types = [
            'quartus:transform_types',
        ]
        quartus_types_flow = register_flow('specific_types',
                                           quartus_types,
                                           requires=[init_flow],
                                           backend=self.name)

        templates = self._get_layer_templates()
        template_flow = register_flow('apply_templates',
                                      templates,
                                      requires=[init_flow],
                                      backend=self.name)

        writer_passes = ['quartus:write_hls']
        writer_flow_requirements = [
            'optimize', quartus_types_flow, template_flow
        ]
        self._writer_flow = register_flow('write',
                                          writer_passes,
                                          requires=writer_flow_requirements,
                                          backend=self.name)

        all_passes = get_backend_passes(self.name)

        extras = [
            # Ideally this should be empty
            opt_pass for opt_pass in all_passes
            if opt_pass not in initializers + quartus_types + templates +
            writer_passes
        ]

        if len(extras) > 0:
            extras_flow = register_flow('extras',
                                        extras,
                                        requires=[init_flow],
                                        backend=self.name)
        else:
            extras_flow = None

        ip_flow_requirements = [
            'optimize', init_flow, quartus_types_flow, extras_flow,
            template_flow
        ]
        ip_flow_requirements = list(filter(None, ip_flow_requirements))

        self._default_flow = register_flow('ip',
                                           None,
                                           requires=ip_flow_requirements,
                                           backend=self.name)
Beispiel #2
0
    def _get_layer_initializers(self):
        all_initializers = {
            name: get_optimizer(name)
            for name in get_backend_passes(self.name)
            if isinstance(get_optimizer(name), LayerOptimizerPass)
        }

        # Sort through the initializers based on the base class (e.g., to apply 'Layer' optimizers before 'Dense')
        sorted_initializers = sorted(all_initializers.items(),
                                     key=lambda x: len(x[1].layer_class.mro()))

        # Return only the names of the initializers
        return [opt[0] for opt in sorted_initializers]
Beispiel #3
0
 def _get_layer_templates(self):
     return [
         name for name in get_backend_passes(self.name)
         if isinstance(get_optimizer(name), Template)
     ]
Beispiel #4
0
    def _register_flows(self):
        initializers = self._get_layer_initializers()
        init_flow = register_flow('init_layers',
                                  initializers,
                                  requires=['optimize'],
                                  backend=self.name)

        streaming_passes = [
            'vivado:remove_final_reshape',
            'vivado:reshape_stream',
            'vivado:clone_output',
            'vivado:insert_zero_padding_before_conv1d',
            'vivado:insert_zero_padding_before_conv2d',
            'vivado:broadcast_stream',
        ]
        streaming_flow = register_flow('streaming',
                                       streaming_passes,
                                       requires=[init_flow],
                                       backend=self.name)

        quantization_passes = [
            'vivado:merge_batch_norm_quantized_tanh',
            'vivado:quantize_dense_output',
            'fuse_consecutive_batch_normalization',
        ]
        quantization_flow = register_flow('quantization',
                                          quantization_passes,
                                          requires=[init_flow],
                                          backend=self.name)

        optimization_passes = [
            'vivado:optimize_pointwise_conv',
        ]
        optimization_flow = register_flow('optimize',
                                          optimization_passes,
                                          requires=[init_flow],
                                          backend=self.name)

        vivado_types = [
            'vivado:register_bram_weights',
            'vivado:transform_types',
            'vivado:generate_conv_streaming_instructions',
            'vivado:apply_resource_strategy',
        ]
        vivado_types_flow = register_flow('specific_types',
                                          vivado_types,
                                          requires=[init_flow],
                                          backend=self.name)

        templates = self._get_layer_templates()
        template_flow = register_flow('apply_templates',
                                      templates,
                                      requires=[init_flow],
                                      backend=self.name)

        writer_passes = ['vivado:write_hls']
        writer_flow_requirements = [
            'optimize', vivado_types_flow, template_flow
        ]
        self._writer_flow = register_flow('write',
                                          writer_passes,
                                          requires=writer_flow_requirements,
                                          backend=self.name)

        all_passes = get_backend_passes(self.name)

        extras = [
            # Ideally this should be empty
            opt_pass for opt_pass in all_passes
            if opt_pass not in initializers + streaming_passes +
            quantization_passes + optimization_passes + vivado_types +
            templates + writer_passes
        ]

        if len(extras) > 0:
            extras_flow = register_flow('extras',
                                        extras,
                                        requires=[init_flow],
                                        backend=self.name)
        else:
            extras_flow = None

        ip_flow_requirements = [
            'optimize', init_flow, streaming_flow, quantization_flow,
            optimization_flow, vivado_types_flow, extras_flow, template_flow
        ]
        ip_flow_requirements = list(filter(None, ip_flow_requirements))

        self._default_flow = register_flow('ip',
                                           None,
                                           requires=ip_flow_requirements,
                                           backend=self.name)