srdatalog.ir.codegen.cuda.view_slots¶
View/handle slot mapping + view-declaration emission.
Port of src/srdatalog/codegen/target_jit/jit_view_management.nim.
Deduplicates pipeline source views by (rel_name, index, version),
computes view-slot offsets for multi-view sources (e.g. Device2LevelIndex
contributes >1 slot per source via the plugin), and emits the
auto view_X = views[i]; block at the top of each generated kernel.
A “view spec” is the triple (rel_name, index cols, version) plus the handle_idx of the first op that referenced it. Two uses of the same relation with different index orderings are distinct views; two uses with the same (rel, idx, ver) share one view slot even across nested CJ / Cartesian handles.
Module Contents¶
Classes¶
(rel_name, index, version, handle_idx) — handle_idx is the index of the FIRST op that referenced this view. |
Functions¶
Map |
|
Walk the pipeline body and collect a de-duplicated list of
|
|
Total view slots needed for all unique sources. Nested CJ/Cart handles for the same (rel, version, index) share slots. |
|
Map |
|
Extract column ordering from a source-bearing node. |
|
Emit the top-of-kernel |
|
Walk the pipeline body and register every ColumnSource |
|
Unique key for a source spec: |
|
|
API¶
- class srdatalog.ir.codegen.cuda.view_slots.ViewSpec[source]¶
(rel_name, index, version, handle_idx) — handle_idx is the index of the FIRST op that referenced this view.
- srdatalog.ir.codegen.cuda.view_slots.build_root_slot_map(source_specs: collections.abc.Sequence[srdatalog.ir.mir.types.MirNode], rel_index_types: dict[str, str]) dict[str, int][source]¶
Map
<relName>_<VER>_<cols>→ view-slot base for each root source. First occurrence wins; subsequent duplicates share the first’s slot.
- srdatalog.ir.codegen.cuda.view_slots.collect_unique_view_specs(ops: list[srdatalog.ir.mir.types.MirNode]) list[srdatalog.ir.codegen.cuda.view_slots.ViewSpec][source]¶
Walk the pipeline body and collect a de-duplicated list of
ViewSpecs, first-occurrence order. Covers every op kind that references a view: ColumnJoin, CartesianJoin, Scan, Negation, Aggregate, BalancedScan, PositionedExtract.
- srdatalog.ir.codegen.cuda.view_slots.compute_total_view_count(source_specs: collections.abc.Sequence[srdatalog.ir.mir.types.MirNode], rel_index_types: dict[str, str]) int[source]¶
Total view slots needed for all unique sources. Nested CJ/Cart handles for the same (rel, version, index) share slots.
- srdatalog.ir.codegen.cuda.view_slots.compute_view_slot_offsets(source_specs: collections.abc.Sequence[srdatalog.ir.mir.types.MirNode], rel_index_types: dict[str, str]) dict[int, int][source]¶
Map
handle_idx→ base slot inviews[].Multiple handles for the same relation+version+index share one slot — nested CJ/Cart handles reference the same physical view as the root handle.
- srdatalog.ir.codegen.cuda.view_slots.get_source_index(src_spec: srdatalog.ir.mir.types.MirNode) list[int][source]¶
Extract column ordering from a source-bearing node.
- srdatalog.ir.codegen.cuda.view_slots.jit_emit_view_declarations(specs: list[srdatalog.ir.codegen.cuda.view_slots.ViewSpec], ops: list[srdatalog.ir.mir.types.MirNode], ep_source_specs: collections.abc.Sequence[srdatalog.ir.mir.types.MirNode], ctx: srdatalog.ir.codegen.cuda.context.CodeGenContext) str[source]¶
Emit the top-of-kernel
auto view_X = views[i];block.Populates
ctx.view_varswith both:spec key (
rel_idx_VER) → view_varstr(handle_idx) → view_var (so nested op emitters can resolve “which view is this handle referring to?” directly)
- srdatalog.ir.codegen.cuda.view_slots.register_pipeline_handles(offsets: dict[int, int], pipeline: list[srdatalog.ir.mir.types.MirNode], rel_index_types: dict[str, str], root_slots: dict[str, int]) None[source]¶
Walk the pipeline body and register every ColumnSource
handle_startagainst theroot_slotstable. Mutatesoffsetsin place — matches Nim’sregisterPipelineHandlesvar-param signature.
- srdatalog.ir.codegen.cuda.view_slots.source_spec_key(src_spec: srdatalog.ir.mir.types.MirNode) str[source]¶
Unique key for a source spec:
<relName>_<VERSION>_<cols_joined>. Two uses of the same relation with different index orderings → distinct keys. Includes version to keep DELTA / FULL views distinct.