Deeploy.MemoryLevelExtension.CodeTransformationPasses.Closure.MemoryAwareClosureGeneration

class Deeploy.MemoryLevelExtension.CodeTransformationPasses.Closure.MemoryAwareClosureGeneration(closureCallTemplate: NodeTemplate = <Deeploy.DeeployTypes.NodeTemplate object>, closureSuffix='_closure', writeback: bool = True, generateStruct: bool = True, startRegion: str = 'L2', endRegion: str = 'L1')

Bases: ClosureGeneration

Memory-aware closure generation for multi-level memory hierarchies.

This class extends ClosureGeneration to handle memory-aware closure generation where only certain memory levels are included in the closure arguments. It filters buffers based on their memory level, including only those that belong to specific memory regions in the hierarchy.

Notes

This class is useful for multi-level memory systems where different memory levels have different access patterns and only certain levels should be passed as closure arguments. Buffers are included if they: - Have no memory level annotation - Belong to the start region - Do not belong to the end region (are in higher levels)

Methods

__init__(closureCallTemplate: NodeTemplate = <Deeploy.DeeployTypes.NodeTemplate object>, closureSuffix='_closure', writeback: bool = True, generateStruct: bool = True, startRegion: str = 'L2', endRegion: str = 'L1')

Initialize the MemoryAwareClosureGeneration transformation pass.

Parameters:
  • closureCallTemplate (NodeTemplate, optional) – Template for generating closure function calls. Default is the global _closureCallTemplate.

  • closureSuffix (str, optional) – Suffix to append to closure function names. Default is “_closure”.

  • writeback (bool, optional) – Whether to generate writeback code for closure arguments. Default is True.

  • generateStruct (bool, optional) – Whether to generate argument structure definitions. Default is True.

  • startRegion (str, optional) – The starting memory region to include in closures. Default is “L2”.

  • endRegion (str, optional) – The ending memory region to include in closures. Default is “L1”.

__init__(closureCallTemplate[, closureSuffix])

Initialize the MemoryAwareClosureGeneration transformation pass.

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

Apply the closure 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.

Attributes

parseTreeDict

closureStructArgType

closureStructArgs

apply(ctxt: NetworkContext, executionBlock: ExecutionBlock, name: str, verbose: CodeGenVerbosity = CodeGenVerbosity(tilingProfiling=None, untiledProfiling=None)) Tuple[NetworkContext, ExecutionBlock]

Apply the closure generation transformation.

Transforms the given execution block into a closure-based pattern by generating the necessary struct, closure function, and call site. This is the main entry point for the closure transformation.

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

  • executionBlock (ExecutionBlock) – The execution block to transform into a closure pattern.

  • name (str) – The base name for generating closure-related identifiers.

  • verbose (CodeGenVerbosity, optional) – The verbosity level for code generation. Default is _NoVerbosity.

Returns:

A tuple containing: - The modified network context with closure definitions - The new ClosureExecutionBlock with closure call patterns

Return type:

Tuple[NetworkContext, ExecutionBlock]

Notes

The transformation process includes: 1. Generating a unique closure name with the specified suffix 2. Capturing the original function call code 3. Creating the closure argument struct 4. Generating the closure function definition in global scope 5. Replacing the original call with a closure call pattern

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.