def _parse_hls_config(self): hls_config = self.config['HLSConfig'] self.optimizers = hls_config.get('Optimizers') if 'SkipOptimizers' in hls_config: if self.optimizers is not None: raise Exception( 'Invalid optimizer configuration, please use either "Optimizers" or "SkipOptimizers".' ) skip_optimizers = hls_config.get('SkipOptimizers') selected_optimizers = get_available_passes() for opt in skip_optimizers: try: selected_optimizers.remove(opt) except ValueError: pass self.optimizers = selected_optimizers model_cfg = hls_config.get('Model') if model_cfg is not None: precision_cfg = model_cfg.get('Precision') if precision_cfg is not None: if isinstance(precision_cfg, dict): for var, precision in precision_cfg.items(): self.model_precision[var] = precision else: self.model_precision[ 'default'] = precision_cfg # Default precision for everything self.model_rf = model_cfg.get('ReuseFactor') self.model_strategy = model_cfg.get('Strategy', 'Latency') self.model_compression = bool(model_cfg.get('Compression', 0)) layer_type_cfg = hls_config.get('LayerType') if layer_type_cfg is not None: for layer_type, layer_cfg in layer_type_cfg.items(): precision_cfg = layer_cfg.get('Precision') if isinstance(precision_cfg, dict): for var, precision in precision_cfg.items(): self.layer_type_precision[layer_type.lower() + '_' + var] = precision else: self.layer_type_precision[layer_type.lower() + '_default'] = precision_cfg rf = layer_cfg.get('ReuseFactor') if rf is not None: self.layer_type_rf[layer_type.lower()] = rf strategy = layer_cfg.get('Strategy') if strategy is not None: self.layer_type_strategy[layer_type.lower()] = strategy compression = layer_cfg.get('Compression') if compression is not None: self.layer_type_compression[layer_type.lower()] = bool( compression) layer_name_cfg = hls_config.get('LayerName') if layer_name_cfg is not None: for layer_name, layer_cfg in layer_name_cfg.items(): precision_cfg = layer_cfg.get('Precision') if isinstance(precision_cfg, dict): for var, precision in precision_cfg.items(): self.layer_name_precision[layer_name.lower() + '_' + var] = precision else: self.layer_name_precision[layer_name.lower() + '_default'] = precision_cfg rf = layer_cfg.get('ReuseFactor') if rf is not None: self.layer_name_rf[layer_name.lower()] = rf strategy = layer_cfg.get('Strategy') if strategy is not None: self.layer_name_strategy[layer_name.lower()] = strategy compression = layer_cfg.get('Compression') if compression is not None: self.layer_name_compression[layer_name.lower()] = bool( compression)
def _parse_hls_config(self): hls_config = self.config['HLSConfig'] self.flows = hls_config.get('Flows') if self.flows is None: self.flows = [self.backend.get_default_flow()] # TODO this is now effectively broken self.optimizers = hls_config.get('Optimizers') if 'SkipOptimizers' in hls_config: if self.optimizers is not None: raise Exception( 'Invalid optimizer configuration, please use either "Optimizers" or "SkipOptimizers".' ) skip_optimizers = hls_config.get('SkipOptimizers') selected_optimizers = get_available_passes() for opt in skip_optimizers: try: selected_optimizers.remove(opt) except ValueError: pass self.optimizers = selected_optimizers model_cfg = hls_config.get('Model') if model_cfg is not None: precision_cfg = model_cfg.get('Precision') if precision_cfg is not None: if isinstance(precision_cfg, dict): for var, precision in precision_cfg.items(): self.model_precision[var] = precision else: self.model_precision[ 'default'] = precision_cfg # Default precision for everything self.model_bf = model_cfg.get( 'BramFactor', np.inf) # Weight threshold to be external BRAM self.model_rf = model_cfg.get('ReuseFactor') self.model_targ_cycles = model_cfg.get('TargetCycles') self.model_conv_implementation = model_cfg.get( 'ConvImplementation', 'LineBuffer') self.model_strategy = model_cfg.get('Strategy', 'Latency') self.model_compression = bool(model_cfg.get('Compression', 0)) layer_type_cfg = hls_config.get('LayerType') if layer_type_cfg is not None: for layer_type, layer_cfg in layer_type_cfg.items(): precision_cfg = layer_cfg.get('Precision') if isinstance(precision_cfg, dict): for var, precision in precision_cfg.items(): self.layer_type_precision[layer_type.lower() + '_' + var] = precision else: self.layer_type_precision[layer_type.lower() + '_default'] = precision_cfg rf = layer_cfg.get('ReuseFactor') if rf is not None: self.layer_type_rf[layer_type.lower()] = rf targ_cycles = layer_cfg.get('TargetCycles') if targ_cycles is not None: self.layer_type_targ_cycles[ layer_type.lower()] = targ_cycles strategy = layer_cfg.get('Strategy') if strategy is not None: self.layer_type_strategy[layer_type.lower()] = strategy conv_implementation = layer_cfg.get('ConvImplementation') if conv_implementation is not None: self.layer_type_conv_implementation[ layer_type.lower()] = conv_implementation compression = layer_cfg.get('Compression') if compression is not None: self.layer_type_compression[layer_type.lower()] = bool( compression) layer_name_cfg = hls_config.get('LayerName') if layer_name_cfg is not None: for layer_name, layer_cfg in layer_name_cfg.items(): precision_cfg = layer_cfg.get('Precision') if isinstance(precision_cfg, dict): for var, precision in precision_cfg.items(): self.layer_name_precision[layer_name.lower() + '_' + var] = precision else: self.layer_name_precision[layer_name.lower() + '_default'] = precision_cfg rf = layer_cfg.get('ReuseFactor') if rf is not None: self.layer_name_rf[layer_name.lower()] = rf targ_cycles = layer_cfg.get('TargetCycles') if targ_cycles is not None: self.layer_name_targ_cycles[ layer_name.lower()] = targ_cycles strategy = layer_cfg.get('Strategy') if strategy is not None: self.layer_name_strategy[layer_name.lower()] = strategy conv_implementation = layer_cfg.get('ConvImplementation') if conv_implementation is not None: self.layer_name_conv_implementation[ layer_name.lower()] = conv_implementation compression = layer_cfg.get('Compression') if compression is not None: self.layer_name_compression[layer_name.lower()] = bool( compression)