|
28 | 28 | Softmax, |
29 | 29 | ) |
30 | 30 | from hls4ml.model.optimizer import get_backend_passes, layer_optimizer |
31 | | -from hls4ml.model.types import FixedPrecisionType, IntegerPrecisionType, NamedType |
| 31 | +from hls4ml.model.types import FixedPrecisionType, IntegerPrecisionType, NamedType, PackedType |
32 | 32 | from hls4ml.report import parse_vivado_report |
33 | 33 | from hls4ml.utils.fixed_point_utils import ceil_log2 |
34 | 34 |
|
@@ -75,6 +75,12 @@ def _register_layer_attributes(self): |
75 | 75 | attrs.append(ChoiceAttribute('conv_implementation', choices=['LineBuffer', 'Encoded'], default='LineBuffer')) |
76 | 76 | self.attribute_map[layer] = attrs |
77 | 77 |
|
| 78 | + sep_conv_layers = [SeparableConv1D, SeparableConv2D] |
| 79 | + for layer in sep_conv_layers: |
| 80 | + attrs = self.attribute_map.get(layer, []) |
| 81 | + attrs.append(TypeAttribute('dw_output', default=FixedPrecisionType(18, 8))) |
| 82 | + self.attribute_map[layer] = attrs |
| 83 | + |
78 | 84 | def _register_flows(self): |
79 | 85 | initializers = self._get_layer_initializers() |
80 | 86 | init_flow = register_flow('init_layers', initializers, requires=['optimize'], backend=self.name) |
@@ -288,6 +294,15 @@ def init_sepconv1d(self, layer): |
288 | 294 | ) # TODO Once we have SeparableConv implementation for io_parallel this should be set properly |
289 | 295 | layer.set_attr('implementation', layer.model.config.get_conv_implementation(layer).lower()) |
290 | 296 |
|
| 297 | + # Set the output type of the depthwise phase |
| 298 | + dw_out_precision, _ = layer.model.config.get_precision(layer, 'dw_output') |
| 299 | + dw_out_name = layer.name + '_dw_out_t' |
| 300 | + if layer.model.config.get_config_value('IOType') == 'io_stream': |
| 301 | + dw_output_t = PackedType(dw_out_name, dw_out_precision, layer.get_attr('n_chan'), n_pack=1) |
| 302 | + else: |
| 303 | + dw_output_t = NamedType(dw_out_name, dw_out_precision) |
| 304 | + layer.set_attr('dw_output_t', dw_output_t) |
| 305 | + |
291 | 306 | @layer_optimizer(Conv2D) |
292 | 307 | def init_conv2d(self, layer): |
293 | 308 | if len(layer.weights['weight'].data.shape) == 2: # This can happen if we assign weights of Dense layer to 1x1 Conv2D |
@@ -334,6 +349,15 @@ def init_sepconv2d(self, layer): |
334 | 349 | ) # TODO Once we have SeparableConv implementation for io_parallel this should be set properly |
335 | 350 | layer.set_attr('implementation', layer.model.config.get_conv_implementation(layer).lower()) |
336 | 351 |
|
| 352 | + # Set the output type of the depthwise phase |
| 353 | + dw_out_precision, _ = layer.model.config.get_precision(layer, 'dw_output') |
| 354 | + dw_out_name = layer.name + '_dw_out_t' |
| 355 | + if layer.model.config.get_config_value('IOType') == 'io_stream': |
| 356 | + dw_output_t = PackedType(dw_out_name, dw_out_precision, layer.get_attr('n_chan'), n_pack=1) |
| 357 | + else: |
| 358 | + dw_output_t = NamedType(dw_out_name, dw_out_precision) |
| 359 | + layer.set_attr('dw_output_t', dw_output_t) |
| 360 | + |
337 | 361 | @layer_optimizer(DepthwiseConv2D) |
338 | 362 | def init_depconv2d(self, layer): |
339 | 363 | if layer.model.config.is_resource_strategy(layer): |
|
0 commit comments