hls4ml.backends package

Subpackages

Submodules

hls4ml.backends.backend module

class hls4ml.backends.backend.Backend(name)

Bases: object

create_initial_config(**kwargs)

Create the minimal conversion config for the backend.

Subclasses should implement this method to provide the initial configuration for the conversion.

create_layer_class(layer_class)

Wrap the original layer class into the backend-specific layer class.

Backends should extend base layer classes with new attributes and variables as needed. These new classes are then used within the model.

Parameters:

layer_class (class) – Base class to extend

get_available_flows()

Returns the list of flows registered for this backend.

Returns:

The list of registered flows.

Return type:

list

get_custom_source()

Returns the registered custom source files.

Returns:

Custom source files. Keys represent destination paths, values are absolute paths to registered source

files.

Return type:

dict

get_default_flow()

The name of the default flow of the backend.

Default flow is used as the conversion target if the target flow has not been specified.

register_pass(name, opt_cls, flow=None)

Register an optimizer path for the backend.

Note that user-provided optimizers registered without specifying any flow will not be invoked.

Parameters:
  • name (str) – Name of the optimizer

  • opt_cls (class) – Optimizer class

  • flow (str, list or tuple, optional) – Existing flow(s) to add the optimizer to. Defaults to None.

register_source(source_file, destination_dir='nnet_utils')

Register custom source that is not part of the backend’s templates.

Parameters:
  • source_file (str or Path) – Absolute path to the source file.

  • destination_dir (str, optional) – The sub-directory of the output project to write the source file to. Defaults to ‘nnet_utils’.

Raises:

Exception – If the source file is not a str or Path, or if the path is not absolute

register_template(template_cls)

Register a template “optimizer”.

E.g., function call template or op configuration template.

Parameters:

template_cls (class) – Template to register.

hls4ml.backends.backend.get_available_backends()
hls4ml.backends.backend.get_backend(name)
hls4ml.backends.backend.register_backend(name, backend_cls)

Create the backend instance and add it to the registry.

Parameters:
  • name (str) – Name of the backend.

  • backend_cls (class) – Backend class to instantiate. Class must implement a constructor without parameters.

Raises:

Exception – If the backend has already been registered.

hls4ml.backends.template module

class hls4ml.backends.template.FunctionCallTemplate(layer_class, include_header=None)

Bases: Template

transform(model, node)

Transformation to apply if matching was successful.

Transform should return a boolean value indicating if the model graph was altered (by adding/removing nodes).

Parameters:
  • model (ModelGraph) – Model to optimize

  • node (Layer) – The matched node in the model graph.

class hls4ml.backends.template.LayerConfigTemplate(layer_class)

Bases: Template

class hls4ml.backends.template.Template(name, layer_class, attribute_name)

Bases: OptimizerPass

format(node)
get_name()
match(node)

Predicate to match on a given node.

Parameters:

node (Layer) – Node in the model graph to try matching the optimizer on.

transform(model, node)

Transformation to apply if matching was successful.

Transform should return a boolean value indicating if the model graph was altered (by adding/removing nodes).

Parameters:
  • model (ModelGraph) – Model to optimize

  • node (Layer) – The matched node in the model graph.

Module contents