Deeploy.MLIRAIETypes.MLIRNodeTemplate

class Deeploy.MLIRAIETypes.MLIRNodeTemplate

Bases: NodeTemplate

NodeTemplate subclass that emits MLIR instead of C code.

Subclasses must override emit() to add dialect operations to an mlir.ir.Module (or region / insertion point provided via kwargs).

generate() is overridden as a convenience that constructs a standalone module, calls emit(), and returns the MLIR text. The base-class alignToContext / hoistTransientBuffers hooks are retained and work unchanged.

Methods

__init__()

Initialize a NodeTemplate object

Parameters:

templateStr (str) – Mako template string. If tiling is supposed to be supported, this template string may only contain direct expressions that get added by either the operator’s parser or the alignToContext method.

__init__()

Initialize a NodeTemplate object

alignToContext(ctxt, operatorRepresentation)

Helper method to extract Mako template expressions used in the backend's code generation step.

computeTransientBuffersSize(ctxt, ...)

Computes the size of transient buffers hoisted by this template given expressions for each variable added by the operator's parser.

emit(operatorRepresentation, **kwargs)

Populate an MLIR module with the operations for this node.

generate([operatorRepresentation])

Generate an MLIR string for this node.

hoistTransientBuffers(ctxt, ...)

Registers the transient buffers required by this template.

internalSize()

Return the byte size of internal memory buffers used by this template

abstractmethod emit(operatorRepresentation: OperatorRepresentation, **kwargs) None

Populate an MLIR module with the operations for this node.

The caller (typically the deployer) sets up an mlir.ir.Module with the appropriate device wrapper and passes dialect-specific context through kwargs (e.g. insertion point, tile references, ObjectFifo handles).

Parameters:
  • operatorRepresentation (OperatorRepresentation) – The parser’s node representation (buffer names, sizes, types …).

  • **kwargs – Dialect-specific context provided by the deployer.

generate(operatorRepresentation={}, **kwargs) str

Generate an MLIR string for this node.

This default implementation is a thin wrapper: it delegates to emit(). Deployers that need to build a single module from multiple nodes should call emit() directly with the shared module context and then stringify the complete module themselves.

Returns:

MLIR text (printable module or fragment).

Return type:

str

alignToContext(ctxt: NetworkContext, operatorRepresentation: Dict[str, str | Any]) Tuple[NetworkContext, Dict[str, str | Any], List[str]]

Helper method to extract Mako template expressions used in the backend’s code generation step. Also hoists transient buffers.

Parameters:
  • ctxt (NetworkContext) – Current NetworkContext. Modifying is allowed within this method.

  • operatorRepresentation (OperatorRepresentation) – Current node representation. Modifying is allowed within this method.

Returns:

Tuple of the updated NetworkContext, operatorRepresentation and a list of the names of hoisted transient buffers

Return type:

Tuple[NetworkContext, OperatorRepresentation, List[str]]

computeTransientBuffersSize(ctxt: NetworkContext, operatorRepresentation: Dict[str, str | Any]) List[Tuple[str, int | IntVar]]

Computes the size of transient buffers hoisted by this template given expressions for each variable added by the operator’s parser.

Parameters:
  • ctxt (NetworkContext) – Current NetworkContext

  • operatorRepresentation (OperatorRepresentation) – The parser’s node representation

Returns:

Returns a list of tuples containing the hoisted buffer’s name and either a symbolic expression or an integer representing its size.

Return type:

List[Tuple[str, Union[int, IntVar]]]

hoistTransientBuffers(ctxt: NetworkContext, operatorRepresentation: Dict[str, str | Any]) Tuple[NetworkContext, Dict[str, str | Any], List[str]]

Registers the transient buffers required by this template. If tiling is applied, this method is called AFTER tiling.

Parameters:
  • ctxt (NetworkContext) – Current NetworkContext

  • operatorRepresentation (OperatorRepresentation) – The parser’s node representation

Returns:

Tuple containing the updated NetworkContext object, updated node representation and a list of names of all hoisted TransientBuffers

Return type:

Tuple[NetworkContext, OperatorRepresentation, List[str]]

internalSize() int

Return the byte size of internal memory buffers used by this template

Returns:

byte size of all transient internal buffers

Return type:

int