Deeploy.MemoryLevelExtension.CodeTransformationPasses.PrintInputs.MemoryAwarePrintOutputGeneration

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

Bases: _MemoryAwareGeneration, PrintOutputGeneration

Memory-aware output tensor debug printing transformation.

This class combines MemoryAwareGeneration and PrintOutputGeneration to provide selective debug printing of output tensors based on their memory level assignments. It enables focused debugging of output data in specific memory regions within multi-level memory architectures.

The class inherits filtering capabilities from MemoryAwareGeneration and output printing logic from PrintOutputGeneration, applying memory-based filtering before generating debug print statements for output tensors.

Notes

This transformation is particularly valuable for verifying that output data is correctly written to the intended memory levels in complex memory hierarchies, and for debugging memory management issues in embedded neural network deployments.

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 output 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 output tensor printing transformation.

Filters output 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 output 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 output 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 outputs from this operation 4. Adds debug print statements for qualifying tensors after execution

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.