Deeploy.CommonExtensions.CodeTransformationPasses.MemoryAllocation.MemoryManagementGeneration
- class Deeploy.CommonExtensions.CodeTransformationPasses.MemoryAllocation.MemoryManagementGeneration(memoryLevelRegex: str | None = None)
Bases:
CodeTransformationPass,IntrospectiveCodeTransformationMixInA code transformation pass that manages memory allocation and deallocation for buffers.
This pass is responsible for ensuring that memory is allocated for buffers when they are needed and deallocated when they are no longer in use.
Methods
- __init__(memoryLevelRegex: str | None = None)
Initialize the memory management generation pass.
- Parameters:
memoryLevelRegex (str, optional) – A regular expression to match memory levels.
__init__([memoryLevelRegex])Initialize the memory management generation pass.
apply(ctxt, executionBlock, name[, verbose])Apply the memory management generation 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.
is_final_input(buffer, nodeName)Check if the given buffer is a final input buffer.
is_memory_level(buffer)Check if the given buffer is a memory level buffer.
is_output(buffer, nodeName)Check if the given buffer is an output buffer.
is_transient(buffer, nodeName)Check if the given buffer is a transient buffer.
topologicallySortBuffers(buffers)Topologically sorts a list of VariableBuffer objects based on their reference dependencies.
Attributes
parseTreeDict- is_memory_level(buffer: VariableBuffer) bool
Check if the given buffer is a memory level buffer.
- Parameters:
buffer (VariableBuffer) – The buffer to check.
- Returns:
True if the buffer is a memory level buffer, False otherwise.
- Return type:
bool
- static is_final_input(buffer: VariableBuffer, nodeName: str) bool
Check if the given buffer is a final input buffer.
- Parameters:
buffer (VariableBuffer) – The buffer to check.
nodeName (str) – The name of the node to check against.
- Returns:
True if the buffer is a final input buffer, False otherwise.
- Return type:
bool
- static is_output(buffer: VariableBuffer, nodeName: str) bool
Check if the given buffer is an output buffer.
- static is_transient(buffer: VariableBuffer, nodeName: str) bool
Check if the given buffer is a transient buffer.
- Parameters:
buffer (VariableBuffer) – The buffer to check.
nodeName (str) – The name of the node to check against.
- Returns:
True if the buffer is a transient buffer, False otherwise.
- Return type:
bool
- static topologicallySortBuffers(buffers: List[VariableBuffer]) List[VariableBuffer]
Topologically sorts a list of VariableBuffer objects based on their reference dependencies.
This method iteratively identifies buffers that are not referenced by any other buffer in the list, adding them to the sorted result. Buffers that reference others (via _ReferenceBuffer and _referenceName) are deferred until their dependencies are resolved. The process continues until all buffers are sorted, or a circular reference is detected (which raises an assertion error).
The first buffers in the sorted list are those that do not have any dependencies, while the last buffers are those that are only referenced by others.
- Raises:
AssertionError – If a circular reference is detected among the buffers, preventing a valid topological sort.
- Parameters:
buffers (List[VariableBuffer]) – The list of buffers to sort.
- Returns:
The topologically sorted list of buffers.
- Return type:
List[VariableBuffer]
- apply(ctxt: NetworkContext, executionBlock: ExecutionBlock, name: str, verbose: CodeGenVerbosity = CodeGenVerbosity(tilingProfiling=None, untiledProfiling=None)) Tuple[NetworkContext, ExecutionBlock]
Apply the memory management generation transformation.
This function is responsible for analyzing the memory usage of the given execution block and generating the necessary memory allocation and deallocation commands. It also takes care of managing the lifetimes of the buffers involved and ensuring that they are properly released when no longer needed.
- Parameters:
ctxt (NetworkContext) – The network context to use.
executionBlock (ExecutionBlock) – The execution block to analyze.
name (str) – The name of the node to check against.
verbose (CodeGenVerbosity, optional) – The verbosity level for code generation.
- Returns:
The updated network context and execution block.
- Return type:
Tuple[NetworkContext, ExecutionBlock]
- 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.