srdatalog.ir.codegen.cuda.pipeline_utils

Pipeline-shape utilities used by complete_runner.

Originally ported from src/srdatalog/codegen/target_jit/ jit_emit_helpers.nim — the legacy Filter / ConstantBind / InsertInto emit procs (jit_filter, jit_constant_bind, jit_insert_into) used to live here too. They’ve been retired alongside the rest of the legacy ir/dialects/target/cuda/pipeline.py chain; the dialect now owns those emits via dialects.relation.sorted_array.lowerings._lower_inner_chain and _lower_insert_into.

What remains:

  • has_balanced_scan / get_balanced_scan_info — used to decide whether to emit a balanced-scan kernel variant.

  • has_tiled_cartesian_eligible — runner uses this to decide whether to enable the tiled-Cartesian materialize path.

  • assign_handle_positions / count_handles_in_pipeline — pipeline pre-pass + view-slot counting. Note: dialects.target.cuda. envelope has its own assign_handle_positions for the dialect path; this one stays for the runner-side prepass that mutates mutable_pipe before kernel emission.

Module Contents

Classes

BalancedScanInfo

Lightweight struct returned by get_balanced_scan_info.

Functions

assign_handle_positions

Assign handle_start to every source-bearing node in pipeline order starting from 0. Mutates ops in place. Mirrors Nim’s assignHandlePositions.

count_handles_in_pipeline

Max handle_start + 1 seen across the pipeline — the number of view slots the kernel’s views[] array needs. Zero when no op carries a handle_start (caller should still allocate 1 slot in that case; this function faithfully returns 0 to match Nim).

get_balanced_scan_info

Extract group var + per-source (rel, index, handle_idx) from the root BalancedScan. Returns an all-empty BalancedScanInfo when the root op isn’t a BalancedScan (matching Nim’s sentinel return).

has_balanced_scan

True if the pipeline’s first op is a BalancedScan (root level).

has_tiled_cartesian_eligible

Pipeline contains a 2-source CartesianJoin where each source binds exactly one variable — eligible for the atomic-free tiled/coalesced write optimization.

API

class srdatalog.ir.codegen.cuda.pipeline_utils.BalancedScanInfo[source]

Lightweight struct returned by get_balanced_scan_info.

group_var: str = <Multiline-String>
src1_handle_idx: int

None

src1_index: list[int]

‘field(…)’

src1_rel_name: str = <Multiline-String>
src2_handle_idx: int

None

src2_index: list[int]

‘field(…)’

src2_rel_name: str = <Multiline-String>
srdatalog.ir.codegen.cuda.pipeline_utils.assign_handle_positions(ops: list[srdatalog.ir.mir.types.MirNode]) None[source]

Assign handle_start to every source-bearing node in pipeline order starting from 0. Mutates ops in place. Mirrors Nim’s assignHandlePositions.

srdatalog.ir.codegen.cuda.pipeline_utils.count_handles_in_pipeline(ops: list[srdatalog.ir.mir.types.MirNode]) int[source]

Max handle_start + 1 seen across the pipeline — the number of view slots the kernel’s views[] array needs. Zero when no op carries a handle_start (caller should still allocate 1 slot in that case; this function faithfully returns 0 to match Nim).

srdatalog.ir.codegen.cuda.pipeline_utils.get_balanced_scan_info(ops: list[srdatalog.ir.mir.types.MirNode]) srdatalog.ir.codegen.cuda.pipeline_utils.BalancedScanInfo[source]

Extract group var + per-source (rel, index, handle_idx) from the root BalancedScan. Returns an all-empty BalancedScanInfo when the root op isn’t a BalancedScan (matching Nim’s sentinel return).

srdatalog.ir.codegen.cuda.pipeline_utils.has_balanced_scan(ops: list[srdatalog.ir.mir.types.MirNode]) bool[source]

True if the pipeline’s first op is a BalancedScan (root level).

srdatalog.ir.codegen.cuda.pipeline_utils.has_tiled_cartesian_eligible(ops: list[srdatalog.ir.mir.types.MirNode]) bool[source]

Pipeline contains a 2-source CartesianJoin where each source binds exactly one variable — eligible for the atomic-free tiled/coalesced write optimization.