srdatalog.ir.codegen.cuda.helpers¶
Shared codegen helpers for the batchfile emitter.
Ported from batchfile_gen_helpers.py on python-api-notemplate. The
view-spec collection and pipeline walk now consume our mir_types
nodes directly (ColumnSource/Scan/etc. use rel_name+index rather
than a bundled FactIndex); CodeGenContext keeps the same state
shape so follow-up batchfile emission can slot in unchanged.
Also fixes a latent bug in the original single-source branch of
collect_unique_view_specs: isinstance(op, Scan, Negation, Aggregate)
was missing the tuple parens and would have raised TypeError the
moment the code actually ran. Rewritten as isinstance(op, (m.Scan, m.Negation, m.Aggregate)).
Module Contents¶
Classes¶
State threaded through batchfile emission. |
|
One distinct |
Functions¶
Placeholder: assign |
|
Walk pipeline body ops and extract a de-duplicated list of the source views they consume. Order is first-occurrence (keeps the view-declaration layout stable). |
|
Top-of-kernel view declarations: emit |
|
Locate a source node in a pipeline’s |
|
Canonical key for a (rel, ver, idx) triple used by the view-spec dedupe table and by downstream handle-to-view lookups. |
API¶
- class srdatalog.ir.codegen.cuda.helpers.CodeGenContext[source]¶
State threaded through batchfile emission.
Mirrors mhk’s
CodeGenContextshape so handlers that get ported later can slot in without further adaptation.view_varsis intentionally typed as an unconstraineddict— mhk’s code stores both spec-key strings and integer cursor handles in it.- set_output_vars(dests: collections.abc.Sequence[srdatalog.ir.mir.types.InsertInto]) None[source]¶
Each dest relation points at an OutputContext var; the first dest is the “active” one named
output_ctx, subsequent dests share the buffer and record nothing during the count phase.
- class srdatalog.ir.codegen.cuda.helpers.ViewSpec[source]¶
One distinct
(rel_name, version, index)tuple read by a pipeline.handle_idxis the pipeline-local slot the node was assigned (carried over from the MIR node’shandle_startfield; -1 means unassigned).- version: srdatalog.ir.hir.types.Version¶
None
- srdatalog.ir.codegen.cuda.helpers.assign_handles(pipeline: srdatalog.ir.mir.types.ExecutePipeline) srdatalog.ir.mir.types.ExecutePipeline[source]¶
Placeholder: assign
handle_startslots to each source/op in the pipeline. Stub matches mhk’s TODO-only version; a proper pass will live alongside batchfile codegen.
- srdatalog.ir.codegen.cuda.helpers.collect_unique_view_specs(ops: list[srdatalog.ir.mir.types.MirNode]) list[srdatalog.ir.codegen.cuda.helpers.ViewSpec][source]¶
Walk pipeline body ops and extract a de-duplicated list of the source views they consume. Order is first-occurrence (keeps the view-declaration layout stable).
- srdatalog.ir.codegen.cuda.helpers.emit_view_declarations(pipeline: srdatalog.ir.mir.types.ExecutePipeline, ctx: srdatalog.ir.codegen.cuda.helpers.CodeGenContext) str[source]¶
Top-of-kernel view declarations: emit
using ViewType/HandleTypealiases then oneauto view_X = views[i];per unique source spec.Side effects on
ctx.view_vars:spec_key(rel, ver, idx)->view_<rel>_<idx>_<VER>for every unique source, so downstream handlers can resolve a view by spec.Each body-op’s
handle_startint is mapped to its owning view_var, letting later handle-based codegen look up the C++ name directly.
- srdatalog.ir.codegen.cuda.helpers.find_source_idx(specs: collections.abc.Sequence[srdatalog.ir.mir.types.MirNode], rel_name: str, index: list[int], version: srdatalog.ir.hir.types.Version | None) int[source]¶
Locate a source node in a pipeline’s
source_specs.version=Noneignores version when matching. Returns -1 on miss.