xnn.common.models.fast.AutoPolicy#

class xnn.common.models.fast.AutoPolicy(min_edges=<factory>, min_edges_float64=<factory>, default_min_edges=0, default_min_edges_float64=0, max_edges=<factory>, max_edges_float64=<factory>, default_max_edges=None, default_max_edges_float64=None, cpu_min_edges=None, cpu_min_edges_float64=None)[source]#

Bases: object

When use_fast="auto" takes the fast path.

The fast kernels have a fixed per-call cost, so they lose on small inputs and win on large ones. The crossover is measured per GPU model and precision and stored as a minimum edge count of the neighbor graph; a GPU without a measured entry uses the default.

Parameters:
  • min_edges (dict of str to int) – float32 thresholds, keyed by a substring of the CUDA device name (matched case-insensitively, first match wins).

  • min_edges_float64 (dict of str to int) – The same for float64 (where the reference is slower, so the kernels win earlier).

  • default_min_edges (int) – The thresholds of a GPU in neither table.

  • default_min_edges_float64 (int) – The thresholds of a GPU in neither table.

  • max_edges (dict of str to int) – Upper bounds, for fast paths that win only on small inputs (compiled blocks, which save kernel launches): the fast path is taken below them. A GPU in neither table has none unless the defaults set one.

  • max_edges_float64 (dict of str to int) – Upper bounds, for fast paths that win only on small inputs (compiled blocks, which save kernel launches): the fast path is taken below them. A GPU in neither table has none unless the defaults set one.

  • default_max_edges (int, optional) – The upper bounds of a GPU in neither table (None: no bound).

  • default_max_edges_float64 (int, optional) – The upper bounds of a GPU in neither table (None: no bound).

  • cpu_min_edges (int, optional) – The thresholds on a CPU, for fast paths that have a CPU implementation (None, the default: never on a CPU).

  • cpu_min_edges_float64 (int, optional) – The thresholds on a CPU, for fast paths that have a CPU implementation (None, the default: never on a CPU).

threshold(device, dtype=torch.float32)[source]#

The minimum edge count for device and dtype.

Parameters:
Return type:

int

decide(device, dtype, num_edges)[source]#

Whether a graph with num_edges edges takes the fast path.

Parameters:
Return type:

bool

upper_bound(device, dtype=torch.float32)[source]#

The edge count from which the fast path is no longer taken (None: no bound).

Parameters:
Return type:

int | None