hls4ml.optimization.objectives package

Submodules

hls4ml.optimization.objectives.gpu_objectives module

class hls4ml.optimization.objectives.gpu_objectives.GPUFLOPEstimator

Bases: ObjectiveEstimator

classmethod is_layer_optimizable(layer_attributes)

For a given layer, checks whether optimizations make sense, with respect to the given objective(s) Furthermore, it returns the type of optimization (structured, unstructured etc.) Most suitable for minimizing the objective(s).

Parameters:

layer_attributes (hls4ml.optimization.attributes.LayerAttributes) – Layer attributes

Returns:

tuple containing

  • optimizable (boolean): can optimizations be applied to this layer

  • optimization_attributes (hls4ml.optimization.attributes.OptimizationAttributes):

    Most suitable approach for optimization

Examples

  • Metric = Total weights, Layer = Dense, shape = (4, 4) -> return True, unstructured

  • Metric = DSP, Layer = Dense, Precision = ap_fixed<8, 0> -> return False

    (Vivado doesn’t use DSP when precision < 9)

  • Metric = DSP, Layer = Dense, Precision = ap_fixed<16, 6> ->

    return True, pattern structure, both pruning and weight sharing

classmethod layer_resources(layer_attributes)

For a given layer, how many units of the metric are used, given a generic weight matrix

Parameters:

layer_attributes (hls4ml.optimization.attributes.LayerAttributes) – Layer attributes

Returns:

total resources (w.r.t every dimension of the objective) used

Return type:

resources (list, int)

Example

Metric = Total weights, Layer = Dense, shape = (4, 4) -> return [16] [regardless of layer sparsity]

classmethod layer_savings(layer_attributes)

For a given layer, how many units of the metric are saved, when optimizing one structure The structure type, alongside its parameters (e.g. block shape) are stored in layer attributes For best results, OptimizationAttributes in layer_attribtues should be obtained from is_layer_optimizable

Parameters:

layer_attributes (hls4ml.optimization.attributes.LayerAttributes) – Layer attributes

Returns:

savings achieved (one for every dimension of objective)

With OptimizationAttributes from layer_attributes

Return type:

savings (list, int)

Example

Metric = Total weights, Layer = Dense, shape = (4, 4): - structure_type == unstructured -> return [1] - structure_type == structured -> return [4]

hls4ml.optimization.objectives.vivado_objectives module

class hls4ml.optimization.objectives.vivado_objectives.VivadoDSPEstimator

Bases: ObjectiveEstimator

classmethod is_layer_optimizable(layer_attributes)

For a given layer, checks whether optimizations make sense, with respect to the given objective(s) Furthermore, it returns the type of optimization (structured, unstructured etc.) Most suitable for minimizing the objective(s).

Parameters:

layer_attributes (hls4ml.optimization.attributes.LayerAttributes) – Layer attributes

Returns:

tuple containing

  • optimizable (boolean): can optimizations be applied to this layer

  • optimization_attributes (hls4ml.optimization.attributes.OptimizationAttributes):

    Most suitable approach for optimization

Examples

  • Metric = Total weights, Layer = Dense, shape = (4, 4) -> return True, unstructured

  • Metric = DSP, Layer = Dense, Precision = ap_fixed<8, 0> -> return False

    (Vivado doesn’t use DSP when precision < 9)

  • Metric = DSP, Layer = Dense, Precision = ap_fixed<16, 6> ->

    return True, pattern structure, both pruning and weight sharing

classmethod layer_resources(layer_attributes)

For a given layer, how many units of the metric are used, given a generic weight matrix

Parameters:

layer_attributes (hls4ml.optimization.attributes.LayerAttributes) – Layer attributes

Returns:

total resources (w.r.t every dimension of the objective) used

Return type:

resources (list, int)

Example

Metric = Total weights, Layer = Dense, shape = (4, 4) -> return [16] [regardless of layer sparsity]

classmethod layer_savings(layer_attributes)

For a given layer, how many units of the metric are saved, when optimizing one structure The structure type, alongside its parameters (e.g. block shape) are stored in layer attributes For best results, OptimizationAttributes in layer_attribtues should be obtained from is_layer_optimizable

Parameters:

layer_attributes (hls4ml.optimization.attributes.LayerAttributes) – Layer attributes

Returns:

savings achieved (one for every dimension of objective)

With OptimizationAttributes from layer_attributes

Return type:

savings (list, int)

Example

Metric = Total weights, Layer = Dense, shape = (4, 4): - structure_type == unstructured -> return [1] - structure_type == structured -> return [4]

class hls4ml.optimization.objectives.vivado_objectives.VivadoFFEstimator

Bases: ObjectiveEstimator

classmethod is_layer_optimizable(layer_attributes)

For a given layer, checks whether optimizations make sense, with respect to the given objective(s) Furthermore, it returns the type of optimization (structured, unstructured etc.) Most suitable for minimizing the objective(s).

Parameters:

layer_attributes (hls4ml.optimization.attributes.LayerAttributes) – Layer attributes

Returns:

tuple containing

  • optimizable (boolean): can optimizations be applied to this layer

  • optimization_attributes (hls4ml.optimization.attributes.OptimizationAttributes):

    Most suitable approach for optimization

Examples

  • Metric = Total weights, Layer = Dense, shape = (4, 4) -> return True, unstructured

  • Metric = DSP, Layer = Dense, Precision = ap_fixed<8, 0> -> return False

    (Vivado doesn’t use DSP when precision < 9)

  • Metric = DSP, Layer = Dense, Precision = ap_fixed<16, 6> ->

    return True, pattern structure, both pruning and weight sharing

classmethod layer_resources(layer_attributes)

For a given layer, how many units of the metric are used, given a generic weight matrix

Parameters:

layer_attributes (hls4ml.optimization.attributes.LayerAttributes) – Layer attributes

Returns:

total resources (w.r.t every dimension of the objective) used

Return type:

resources (list, int)

Example

Metric = Total weights, Layer = Dense, shape = (4, 4) -> return [16] [regardless of layer sparsity]

classmethod layer_savings(layer_attributes)

For a given layer, how many units of the metric are saved, when optimizing one structure The structure type, alongside its parameters (e.g. block shape) are stored in layer attributes For best results, OptimizationAttributes in layer_attribtues should be obtained from is_layer_optimizable

Parameters:

layer_attributes (hls4ml.optimization.attributes.LayerAttributes) – Layer attributes

Returns:

savings achieved (one for every dimension of objective)

With OptimizationAttributes from layer_attributes

Return type:

savings (list, int)

Example

Metric = Total weights, Layer = Dense, shape = (4, 4): - structure_type == unstructured -> return [1] - structure_type == structured -> return [4]

class hls4ml.optimization.objectives.vivado_objectives.VivadoMultiObjectiveEstimator

Bases: ObjectiveEstimator

classmethod is_layer_optimizable(layer_attributes)

For a given layer, checks whether optimizations make sense, with respect to the given objective(s) Furthermore, it returns the type of optimization (structured, unstructured etc.) Most suitable for minimizing the objective(s).

Parameters:

layer_attributes (hls4ml.optimization.attributes.LayerAttributes) – Layer attributes

Returns:

tuple containing

  • optimizable (boolean): can optimizations be applied to this layer

  • optimization_attributes (hls4ml.optimization.attributes.OptimizationAttributes):

    Most suitable approach for optimization

Examples

  • Metric = Total weights, Layer = Dense, shape = (4, 4) -> return True, unstructured

  • Metric = DSP, Layer = Dense, Precision = ap_fixed<8, 0> -> return False

    (Vivado doesn’t use DSP when precision < 9)

  • Metric = DSP, Layer = Dense, Precision = ap_fixed<16, 6> ->

    return True, pattern structure, both pruning and weight sharing

classmethod layer_resources(layer_attributes)

For a given layer, how many units of the metric are used, given a generic weight matrix

Parameters:

layer_attributes (hls4ml.optimization.attributes.LayerAttributes) – Layer attributes

Returns:

total resources (w.r.t every dimension of the objective) used

Return type:

resources (list, int)

Example

Metric = Total weights, Layer = Dense, shape = (4, 4) -> return [16] [regardless of layer sparsity]

classmethod layer_savings(layer_attributes)

For a given layer, how many units of the metric are saved, when optimizing one structure The structure type, alongside its parameters (e.g. block shape) are stored in layer attributes For best results, OptimizationAttributes in layer_attribtues should be obtained from is_layer_optimizable

Parameters:

layer_attributes (hls4ml.optimization.attributes.LayerAttributes) – Layer attributes

Returns:

savings achieved (one for every dimension of objective)

With OptimizationAttributes from layer_attributes

Return type:

savings (list, int)

Example

Metric = Total weights, Layer = Dense, shape = (4, 4): - structure_type == unstructured -> return [1] - structure_type == structured -> return [4]

Module contents

class hls4ml.optimization.objectives.ObjectiveEstimator

Bases: ABC

Abstract class with methods for estimating the utilization and savings of a certain layer, with respect to some objective For each objective, an inherited class is written with the correct implementation of the below methods The objectives can be multi-dimensional, e.g. DSPs and BRAM Care needs to be taken when optimizing several objectives, especially if conflicting

abstract is_layer_optimizable(layer_attributes)

For a given layer, checks whether optimizations make sense, with respect to the given objective(s) Furthermore, it returns the type of optimization (structured, unstructured etc.) Most suitable for minimizing the objective(s).

Parameters:

layer_attributes (hls4ml.optimization.attributes.LayerAttributes) – Layer attributes

Returns:

tuple containing

  • optimizable (boolean): can optimizations be applied to this layer

  • optimization_attributes (hls4ml.optimization.attributes.OptimizationAttributes):

    Most suitable approach for optimization

Examples

  • Metric = Total weights, Layer = Dense, shape = (4, 4) -> return True, unstructured

  • Metric = DSP, Layer = Dense, Precision = ap_fixed<8, 0> -> return False

    (Vivado doesn’t use DSP when precision < 9)

  • Metric = DSP, Layer = Dense, Precision = ap_fixed<16, 6> ->

    return True, pattern structure, both pruning and weight sharing

abstract layer_resources(layer_attributes)

For a given layer, how many units of the metric are used, given a generic weight matrix

Parameters:

layer_attributes (hls4ml.optimization.attributes.LayerAttributes) – Layer attributes

Returns:

total resources (w.r.t every dimension of the objective) used

Return type:

resources (list, int)

Example

Metric = Total weights, Layer = Dense, shape = (4, 4) -> return [16] [regardless of layer sparsity]

abstract layer_savings(layer_attributes)

For a given layer, how many units of the metric are saved, when optimizing one structure The structure type, alongside its parameters (e.g. block shape) are stored in layer attributes For best results, OptimizationAttributes in layer_attribtues should be obtained from is_layer_optimizable

Parameters:

layer_attributes (hls4ml.optimization.attributes.LayerAttributes) – Layer attributes

Returns:

savings achieved (one for every dimension of objective)

With OptimizationAttributes from layer_attributes

Return type:

savings (list, int)

Example

Metric = Total weights, Layer = Dense, shape = (4, 4): - structure_type == unstructured -> return [1] - structure_type == structured -> return [4]

class hls4ml.optimization.objectives.ParameterEstimator

Bases: ObjectiveEstimator

A class containing objective estimation with the goal of minimizing The number of non-zero weights in a layer [corresponds to unstructured pruning]

classmethod is_layer_optimizable(layer_attributes)

For a given layer, checks whether optimizations make sense, with respect to the given objective(s) Furthermore, it returns the type of optimization (structured, unstructured etc.) Most suitable for minimizing the objective(s).

Parameters:

layer_attributes (hls4ml.optimization.attributes.LayerAttributes) – Layer attributes

Returns:

tuple containing

  • optimizable (boolean): can optimizations be applied to this layer

  • optimization_attributes (hls4ml.optimization.attributes.OptimizationAttributes):

    Most suitable approach for optimization

Examples

  • Metric = Total weights, Layer = Dense, shape = (4, 4) -> return True, unstructured

  • Metric = DSP, Layer = Dense, Precision = ap_fixed<8, 0> -> return False

    (Vivado doesn’t use DSP when precision < 9)

  • Metric = DSP, Layer = Dense, Precision = ap_fixed<16, 6> ->

    return True, pattern structure, both pruning and weight sharing

classmethod layer_resources(layer_attributes)

For a given layer, how many units of the metric are used, given a generic weight matrix

Parameters:

layer_attributes (hls4ml.optimization.attributes.LayerAttributes) – Layer attributes

Returns:

total resources (w.r.t every dimension of the objective) used

Return type:

resources (list, int)

Example

Metric = Total weights, Layer = Dense, shape = (4, 4) -> return [16] [regardless of layer sparsity]

classmethod layer_savings(layer_attributes)

For a given layer, how many units of the metric are saved, when optimizing one structure The structure type, alongside its parameters (e.g. block shape) are stored in layer attributes For best results, OptimizationAttributes in layer_attribtues should be obtained from is_layer_optimizable

Parameters:

layer_attributes (hls4ml.optimization.attributes.LayerAttributes) – Layer attributes

Returns:

savings achieved (one for every dimension of objective)

With OptimizationAttributes from layer_attributes

Return type:

savings (list, int)

Example

Metric = Total weights, Layer = Dense, shape = (4, 4): - structure_type == unstructured -> return [1] - structure_type == structured -> return [4]