srdatalog.ir.codegen.cuda.render

CUDA renderer registry.

Per docs/stage3a_execution_plan.md §7 task S3A.3, this package replaces codegen/cuda/emit.py’s hardcoded 41-case match with a per-op-class registry that each dialect’s render module opts into. Adding a new IIR dialect now requires adding a codegen/cuda/render/<dialect>.py with @register_render decorators — no edits to this file or to any existing per-dialect render module. P1 fix.

Public API (preserved for external callers — was previously in codegen/cuda/emit.py):

EmitCtx          mutable per-emission state (indent, tile var, ...)
emit(op, ctx)    statement-shaped op → C++ source line(s)
emit_expr(op, ctx) expression-shaped op → C++ source fragment

Each IIR-contributing dialect imports from this module:

from srdatalog.ir.codegen.cuda.render import (
    EmitCtx, register_render, emit, emit_expr,
)

@register_render(Block, mode='stmt')
def _render_block(op: Block, ctx: EmitCtx) -> str:
    return ''.join(emit(s, ctx) for s in op.stmts)

The mode argument distinguishes statement vs expression handlers. A single op class CAN appear in both registries (e.g. RawString is renderable in both modes with different output forms).

Dispatch (emit / emit_expr) raises KeyError with a useful message on an unregistered op — that’s the “did this codegen forget to register a handler” signal. Per S3A.8 (per-Codegen registry + verify_completeness), startup will eventually catch this earlier.

Submodules

Package Contents

Classes

EmitCtx

Mutable emission state during the C++ walk.

Functions

emit

Statement-mode dispatch. Returns C++ source text ending in \n.

emit_expr

Expression-mode dispatch. Returns C++ source fragment with no leading indent or trailing newline.

register_render

Decorator: register fn as the renderer for op_class in the given mode (‘stmt’ or ‘expr’).

Data

API

class srdatalog.ir.codegen.cuda.render.EmitCtx[source]

Mutable emission state during the C++ walk.

  • indent_level: counts of 2-space units. Legacy emitter starts at indent=2 (operator() body); M1 callers pass that in to match.

  • tile_var: name of the tile/thread-group variable. “tile” by default.

  • segment_depth: how many D2lSegmentLoops wrap the current point. Lets IntersectIter reproduce the legacy _nested_column_join_multi indent quirk where segment loops bump the structural indent (alias_binds, intersect at +segs) but the for-iter body lines (auto value, positions, child_binds, body_op) anchor against the outer indent (+1, +1, +1, +0 respectively).

ind() str[source]
indent_level: int

2

segment_depth: int

0

tile_var: str

‘tile’

srdatalog.ir.codegen.cuda.render.RenderFn

None

srdatalog.ir.codegen.cuda.render.__all__

[‘EmitCtx’, ‘RenderFn’, ‘register_render’, ‘emit’, ‘emit_expr’]

srdatalog.ir.codegen.cuda.render.emit(op: srdatalog.ir.core.Op, ctx: srdatalog.ir.codegen.cuda.render.EmitCtx) str[source]

Statement-mode dispatch. Returns C++ source text ending in \n.

srdatalog.ir.codegen.cuda.render.emit_expr(op: srdatalog.ir.core.Op, ctx: srdatalog.ir.codegen.cuda.render.EmitCtx) str[source]

Expression-mode dispatch. Returns C++ source fragment with no leading indent or trailing newline.

srdatalog.ir.codegen.cuda.render.register_render(op_class: type[srdatalog.ir.core.Op], *, mode: str = 'stmt') collections.abc.Callable[[srdatalog.ir.codegen.cuda.render.RenderFn], srdatalog.ir.codegen.cuda.render.RenderFn][source]

Decorator: register fn as the renderer for op_class in the given mode (‘stmt’ or ‘expr’).