Deeploy.CommonExtensions.CodeTransformationPasses.PrintInputs.PrintOutputGeneration

class Deeploy.CommonExtensions.CodeTransformationPasses.PrintInputs.PrintOutputGeneration

Bases: CodeTransformationPass, IntrospectiveCodeTransformationMixIn

Code transformation pass for generating debug print statements for output tensors.

This class extends CodeTransformationPass to automatically insert debug printing code that displays the contents of output tensors after operation execution. It’s useful for debugging, verification, and analysis of neural network operations by showing the actual data values produced.

The class complements PrintInputGeneration by focusing on outputs rather than inputs, providing a complete view of data flow through operations.

Notes

This transformation only processes tensors that are actual outputs from the operation (not used by the current operation, but either used by other operations or global buffers). The printing is added after the operation execution.

Output tensors are identified by checking that the operation is NOT in their user list, indicating the operation produces rather than consumes the tensor.

Methods

__init__()

__init__()

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

Apply output tensor printing transformation to an execution block.

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 output tensor printing transformation to an execution block.

Analyzes all dynamic references in the execution block and adds debug print statements for output tensors after the operation execution.

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

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

  • name (str) – The name of the operation being instrumented, used for filtering which tensors are considered outputs.

  • 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 output print statements added

Return type:

Tuple[NetworkContext, ExecutionBlock]

Notes

The transformation: 1. Extracts all dynamic references from the execution block 2. Filters for tensors that are outputs from this operation 3. Adds debug print statements after the operation execution 4. Generates formatted output showing tensor metadata and contents

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.