Skip to content

utils

Memory Planners Utilities API

The utils module provides utility functions for memory planning in the AOT compilation process.

Functions:

Copyright 2025 Ambiq. All Rights Reserved.

Classes

Functions

compute_tensor_lifetimes

compute_tensor_lifetimes(operators: list[AotOperator]) -> dict[int, tuple[int, int]]

Compute the lifetimes of tensors based on the operators.

For each tensor (by buffer index), compute its lifetime as a tuple (first, last) based on the operator order. The lifetime is defined by the first operator that uses or produces the tensor and the last operator that uses it.

Parameters:

  • operators

    (list) –

    List of AotOperator objects.

Returns:

  • lifetimes ( dict ) –

    Mapping from tensor buffer index to a tuple (first, last).

compute_tensor_sizes

compute_tensor_sizes(operators: list[AotOperator]) -> dict[int, int]

Compute the size of each tensor in bytes.

Parameters:

  • operators

    (list) –

    List of AotOperator objects.

Returns:

  • tensor_sizes ( dict ) –

    Mapping from tensor index to size in bytes.

merge_free_list

merge_free_list(free_list: list[tuple[int, int]]) -> list[tuple[int, int]]

Merge contiguous free blocks.

Parameters:

  • free_list

    (list) –

    List of (offset, size) tuples.

Returns:

  • merged ( list ) –

    A new list with contiguous blocks merged.