Deeploy.CommonExtensions.CodeTransformationPasses.Closure.ClosureExecutionBlock
- class Deeploy.CommonExtensions.CodeTransformationPasses.Closure.ClosureExecutionBlock(nodeTemplate=None, closureBlock: ExecutionBlock | None = None)
Bases:
ExecutionBlockExecution block wrapper for closure-based code generation.
This class extends ExecutionBlock to support closure-based code generation patterns, where functions are wrapped in closures with argument structures. It maintains a reference to the base execution block that contains the actual code to be wrapped.
Notes
This class is used in the closure generation process to maintain the relationship between the closure wrapper and the original execution block.
Methods
- __init__(nodeTemplate=None, closureBlock: ExecutionBlock | None = None)
Initialize a ClosureExecutionBlock.
- Parameters:
nodeTemplate (NodeTemplate, optional) – The node template for this execution block. Default is None.
closureBlock (ExecutionBlock, optional) – The execution block to be wrapped in a closure. Default is None.
__init__([nodeTemplate, closureBlock])Initialize a ClosureExecutionBlock.
addLeft(template, operatorRepresentation)Adds a code snippet that is generated BEFORE any of the other code snippets in this ExecutionBlock
addRight(template, operatorRepresentation)Adds a code snippet that is generated AFTER any of the other code snippets in this ExecutionBlock
generate(ctxt, **kwargs)Generates the code for all registered NodeTemplates and joins it to construct a single snippet
hoisting(ctxt, **kwargs)Helper function to run the underlying NodeTemplate's hooks to add TransientBuffers into the NetworkContext and call their alignToContext methods
Attributes
Get the base execution block, unwrapping nested closures.
ordered list of code snippets that need to be generated to implemented the associated operator
Tiling information of the operator which is annotated in the midend
- property baseBlock
Get the base execution block, unwrapping nested closures.
Recursively unwraps ClosureExecutionBlock instances to find the underlying base execution block that contains the actual code.
- Returns:
The base execution block without closure wrappers.
- Return type:
Notes
This property handles nested closures by recursively calling baseBlock until a non-ClosureExecutionBlock is found.
- addLeft(template: NodeTemplate, operatorRepresentation: Dict[str, str | Any])
Adds a code snippet that is generated BEFORE any of the other code snippets in this ExecutionBlock
- Parameters:
template (NodeTemplate) – NodeTemplate that represents the code snippet to be added
operatorRepresentation (OperatorRepresentation) – Dictionary that holds all expressions to generate code from the template
- addRight(template: NodeTemplate, operatorRepresentation: Dict[str, str | Any])
Adds a code snippet that is generated AFTER any of the other code snippets in this ExecutionBlock
- Parameters:
template (NodeTemplate) – NodeTemplate that represents the code snippet to be added
operatorRepresentation (OperatorRepresentation) – Dictionary that holds all expressions to generate code from the template
- generate(ctxt: NetworkContext, **kwargs) str
Generates the code for all registered NodeTemplates and joins it to construct a single snippet
- Parameters:
ctxt (NetworkContext) – Current NetworkContext
- Returns:
Code snippet that represent the entire ExecutionBlock
- Return type:
str
- hoisting(ctxt: NetworkContext, **kwargs) Tuple[NetworkContext, List[str]]
Helper function to run the underlying NodeTemplate’s hooks to add TransientBuffers into the NetworkContext and call their alignToContext methods
- Parameters:
ctxt (NetworkContext) – Current NetworkContext
- Returns:
Updated NetworkContext and a list of newly registered buffer names
- Return type:
Tuple[NetworkContext, List[str]]
- codeSnippets
ordered list of code snippets that need to be generated to implemented the associated operator
- Type:
Sequence[CodeSnippet]
- patternMemoryConstraint
Tiling information of the operator which is annotated in the midend
- Type:
Optional[PatternMemoryConstraint]