Deeploy.CommonExtensions.CodeTransformationPasses.MemoryAllocation.MemoryPassthroughGeneration
- class Deeploy.CommonExtensions.CodeTransformationPasses.MemoryAllocation.MemoryPassthroughGeneration(memoryHierarchyRegex: str | None = None)
Bases:
MemoryManagementGenerationA code transformation pass that implements a ‘passthrough’ memory management strategy.
In the context of code generation and memory management, ‘passthrough’ means that this pass does not perform any actual allocation or deallocation of memory buffers. Instead, it simply marks buffers as live or dead based on their usage, without modifying the underlying memory state and eventually generating code that reflects these changes.
Methods
- __init__(memoryHierarchyRegex: str | None = None)
Initialize the memory management passthrough pass.
- Parameters:
memoryHierarchyRegex (Optional[str], optional) – A regex pattern to match memory hierarchy.
None. (Defaults to)
__init__([memoryHierarchyRegex])Initialize the memory management passthrough pass.
apply(ctxt, executionBlock, name[, verbose])Apply the memory management passthrough 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- apply(ctxt: NetworkContext, executionBlock: ExecutionBlock, name: str, verbose: CodeGenVerbosity = CodeGenVerbosity(tilingProfiling=None, untiledProfiling=None)) Tuple[NetworkContext, ExecutionBlock]
Apply the memory management passthrough transformation.
This function marks buffers as live or dead based on their usage, without performing any actual memory allocation or deallocation.
- Parameters:
ctxt (NetworkContext) – The network context.
executionBlock (ExecutionBlock) – The execution block.
name (str) – The name of the buffer.
verbose (CodeGenVerbosity, optional) – The verbosity level for code generation. Defaults to _NoVerbosity.
- 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.
- 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
- 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_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]