utils
AOT Handler Utilities API
The utils module provides utility functions for AOT handlers.
Copyright 2025 Ambiq. All Rights Reserved.
Classes
Functions
generate_mermaid
sanitize_for_c_comment
Sanitize a string (or bytes) so it can safely live inside a C block comment (/ ... /).
Transforms: - If bytes/bytearray, decode as UTF-8 (replacing errors). - Replaces '/' with '/ ' and '/' with ' /' - Strips out non-printable/control chars except tab/newline/carriage-return.
Parameters:
Returns:
-
str(str) –Sanitized text.
derive_stimulus_seed
Derive the stimulus seed for a tensor.
The seed is a pure function of salt and tensor_id so stimulus is
reproducible across processes and independent of scheduling order. Only
hashlib is involved, so the derivation is stable across interpreter and
NumPy versions.
tensor_id alone is not unique across models — the LiteRT parser numbers
tensors by their position within a subgraph, so tensor "0" exists in
every model. salt supplies the case-level component (the model name)
that keeps otherwise-identical tensors from sharing a stream.
Parameters:
-
(tensor_idstr) –Identifier of the tensor within its model.
-
(saltstr, default:'') –Case-level qualifier, typically the model name. Defaults to an empty string.
Returns:
-
int(int) –64-bit seed for the tensor's stimulus generator.
generate_stimulus_data
Generate deterministic pseudo-random stimulus data for a tensor.
Parameters:
-
(tensorAirTensor) –Target tensor.
-
(saltstr, default:'') –Case-level qualifier mixed into the seed, typically the model name. Tensor ids are only unique within a model, so without a salt two models sharing a tensor index, dtype and shape receive identical stimulus. Defaults to an empty string.
Returns:
-
ndarray–np.ndarray: Generated stimulus data, seeded from
saltand the tensor identifier.