Deeploy.MemoryLevelExtension.CodeTransformationPasses.PrintInputs.MemoryAwarePrintInputGeneration

class Deeploy.MemoryLevelExtension.CodeTransformationPasses.PrintInputs.MemoryAwarePrintInputGeneration(memoryHierarchyRegex: str | None = None)

Bases: _MemoryAwareGeneration, PrintInputGeneration

Memory-aware input tensor debug printing transformation.

This class combines MemoryAwareGeneration and PrintInputGeneration to provide selective debug printing of input tensors based on their memory level assignments. It’s particularly useful for debugging multi-level memory architectures where you want to focus on specific memory regions.

The class inherits filtering capabilities from MemoryAwareGeneration and input printing logic from PrintInputGeneration, applying memory-based filtering before generating debug print statements.

Notes

This transformation is especially valuable in embedded neural network deployments with complex memory hierarchies (e.g., L1/L2/L3 cache levels, scratchpad memories, external DRAM) where debugging specific memory regions is crucial for performance optimization and correctness verification.

Methods

__init__(memoryHierarchyRegex: str | None = None)

Initialize the MemoryAwareGeneration base class.

Parameters:

memoryHierarchyRegex (str, optional) – A regular expression pattern to match against buffer memory levels. If None, only buffers without memory level annotations are included.

__init__([memoryHierarchyRegex])

Initialize the MemoryAwareGeneration base class.

apply(ctxt, executionBlock, name[, verbose])

Apply memory-aware input tensor printing transformation.

dereferenceVars(template, varNames)

Dereference the specified variables in the given template.

extractDynamicReferences(ctxt[, ...])

Extract all dynamic references from the given execution block.

indexVars(template, varNames, index)

Index the specified variables in the given template.

Attributes

parseTreeDict

apply(ctxt: NetworkContext, executionBlock: ExecutionBlock, name: str, verbose: CodeGenVerbosity = CodeGenVerbosity(tilingProfiling=None, untiledProfiling=None)) Tuple[NetworkContext, ExecutionBlock]

Apply memory-aware input tensor printing transformation.

Filters input tensors by memory level before adding debug print statements, enabling focused debugging of specific memory regions.

Parameters:
  • ctxt (NetworkContext) – The network context containing buffer and type information.

  • executionBlock (ExecutionBlock) – The execution block to instrument with filtered input printing code.

  • name (str) – The name of the operation being instrumented.

  • verbose (CodeGenVerbosity, optional) – The verbosity level for code generation. Default is _NoVerbosity.

Returns:

A tuple containing: - The unchanged network context - The modified execution block with filtered input print statements

Return type:

Tuple[NetworkContext, ExecutionBlock]

Notes

The transformation: 1. Extracts all dynamic references from the execution block 2. Filters references based on memory level regex matching 3. Further filters for tensors that are inputs to this operation 4. Adds debug print statements for qualifying tensors

static dereferenceVars(template: Template, varNames: List[str]) None

Dereference the specified variables in the given template.

This function modifies the provided template in place by dereferencing the variables listed in varNames. The template is modified in place.

Parameters:
  • template (Template) – The template object to be modified.

  • varNames (list of str) – List of variable names to dereference within the template.

extractDynamicReferences(ctxt: NetworkContext, executionBlock: ExecutionBlock = None, unrollStructs=False, includeGlobalReferences=False)

Extract all dynamic references from the given execution block.

Parameters:
  • ctxt (NetworkContext) – The network context.

  • executionBlock (ExecutionBlock, optional) – The execution block.

  • unrollStructs (bool, optional) – Whether to unroll structs.

  • includeGlobalReferences (bool, optional) – Whether to include global references.

Returns:

A list of dynamic references.

Return type:

List[str]

static indexVars(template: Template, varNames: List[str], index: str) None

Index the specified variables in the given template.

Modifies the template in place by indexing the specified variable names.

Parameters:
  • template (Template) – The template to modify.

  • varNames (List[str]) – The variable names to index.

  • index (str) – The index to use.