Deeploy.CommonExtensions.CodeTransformationPasses.PrintInputs.PrintInputGeneration
- class Deeploy.CommonExtensions.CodeTransformationPasses.PrintInputs.PrintInputGeneration
Bases:
CodeTransformationPass,IntrospectiveCodeTransformationMixInCode transformation pass for generating debug print statements for input tensors.
This class extends CodeTransformationPass to automatically insert debug printing code that displays the contents of input tensors before operation execution. It’s useful for debugging, verification, and analysis of neural network operations by showing the actual data values being processed.
The generated print statements include tensor metadata (name, type, shape, memory address) and formatted tensor contents with proper indexing for multi-dimensional arrays.
Notes
This transformation only processes tensors that are actual inputs to the operation (not transient, constant, or struct buffers) and that have the operation in their user list. The printing is added before the operation execution.
The generated C code uses nested loops to iterate through all tensor dimensions and prints values with appropriate formatting based on the data type (integer vs floating-point).
Methods
- __init__()
__init__()apply(ctxt, executionBlock, name[, verbose])Apply input 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 input tensor printing transformation to an execution block.
Analyzes all dynamic references in the execution block and adds debug print statements for input tensors before the operation execution.
- Parameters:
ctxt (NetworkContext) – The network context containing buffer and type information.
executionBlock (ExecutionBlock) – The execution block to instrument with input printing code.
name (str) – The name of the operation being instrumented, used for filtering which tensors are considered inputs.
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 input 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 inputs to this operation 3. Adds debug print statements before 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.