srdatalog.ir.dialects.relation.sorted_array.ops¶
Sorted-array dialect ops — M1 subset.
Each op references its operands by name (string) for M1 pragmatism. The legacy emitter passes view/handle variable names through string keys; matching that lets the byte-equivalence gate compare directly. A later milestone replaces this with lexical binding (D8) once the gate has been validated end-to-end.
Operand naming convention:
view_name — name of a previously-declared view variable
(auto view_<rel>_<cols>_<ver> = views[<slot>];).
handle_name — name of a previously-bound handle variable (declared
via iir.cf.Bind).
Module Contents¶
Classes¶
Narrowed child range from a handle. |
|
Branching factor / row count at a handle position. |
|
Get the value at column |
|
Get the value at column position |
|
Get the value at a column for a row inside a narrowed handle’s begin-offset. |
|
Range-narrowed root handle constructor (expression-shaped). |
|
Iterator pair for a handle, suitable to hand to
|
|
Cooperative prefix-narrowing on a parent handle expression. |
|
Sequential (per-thread) prefix-narrowing on a parent handle. |
|
Root handle into the sorted-array’s full row-range. |
|
2-source nested CartesianJoin with tiled smem pre-load + ballot writes. |
|
Whether a handle is non-empty / non-degenerate. |
API¶
- class srdatalog.ir.dialects.relation.sorted_array.ops.SaChildRange[source]¶
Bases:
srdatalog.ir.core.OpNarrowed child range from a handle.
Lowers (target.cuda) to:
<handle>.child_range(<pos_expr>, <key_var>, tile, <view>).Used inside an IntersectIter body to produce per-source child handles for the next nesting level.
- class srdatalog.ir.dialects.relation.sorted_array.ops.SaDegree[source]¶
Bases:
srdatalog.ir.core.OpBranching factor / row count at a handle position.
Lowers (target.cuda) to:
<handle_name>.degree().
- class srdatalog.ir.dialects.relation.sorted_array.ops.SaGetVal[source]¶
Bases:
srdatalog.ir.core.OpGet the value at column
col, rowidx_var_name, in the view.Used inside a root scan: each var binding fetches its column.
Lowers (target.cuda) to:
<view_name>.get_value(<col>, <idx_var_name>).
- class srdatalog.ir.dialects.relation.sorted_array.ops.SaGetValAt[source]¶
Bases:
srdatalog.ir.core.OpGet the value at column position
colof a narrowed handle’s child at slotidx_var_name. Used in nested ColumnJoin paths; M1 declares the op for completeness but doesn’t yet lower it.Lowers (target.cuda) to:
<view_name>.get_value_at(<handle_name>.begin(), <idx_var_name>).
- class srdatalog.ir.dialects.relation.sorted_array.ops.SaGetValAtPos[source]¶
Bases:
srdatalog.ir.core.OpGet the value at a column for a row inside a narrowed handle’s begin-offset.
Lowers (target.cuda) to:
<view>.get_value(<col>, <handle>.begin() + <idx_var>).Used by the nested CartesianJoin to bind per-source vars from the flat-decomposed indices.
- class srdatalog.ir.dialects.relation.sorted_array.ops.SaHint[source]¶
Bases:
srdatalog.ir.core.OpRange-narrowed root handle constructor (expression-shaped).
Lowers (target.cuda) to:
HandleType(<lo_var>, <hi_var>, <depth>).Typically composed with SaPrefCoop:
HandleType(lo, hi, 0).prefix(root_val, tile, view).
- class srdatalog.ir.dialects.relation.sorted_array.ops.SaIterators[source]¶
Bases:
srdatalog.ir.core.OpIterator pair for a handle, suitable to hand to
intersect_handles.Lowers (target.cuda) to:
<handle>.iterators(<view>).
- class srdatalog.ir.dialects.relation.sorted_array.ops.SaPrefCoop[source]¶
Bases:
srdatalog.ir.core.OpCooperative prefix-narrowing on a parent handle expression.
Lowers (target.cuda) to:
<parent>.prefix(<key>, tile, <view>).Used in multi-source root CJ where 32 threads cooperatively binary-search the parent handle for
key.- parent: srdatalog.ir.core.Op¶
None
- class srdatalog.ir.dialects.relation.sorted_array.ops.SaPrefSeq[source]¶
Bases:
srdatalog.ir.core.OpSequential (per-thread) prefix-narrowing on a parent handle.
Lowers (target.cuda) to:
<parent>.prefix_seq(<key>, <view>).Used inside a Cartesian loop where each thread already has its own (idx0, idx1, …) decomposition and runs the prefix narrowing independently — the cooperative form would be wrong because the threads don’t agree on
key.- parent: srdatalog.ir.core.Op¶
None
- class srdatalog.ir.dialects.relation.sorted_array.ops.SaRoot[source]¶
Bases:
srdatalog.ir.core.OpRoot handle into the sorted-array’s full row-range.
Lowers (target.cuda) to:
HandleType(0, <view_name>.num_rows_, 0).
- class srdatalog.ir.dialects.relation.sorted_array.ops.SaTiledCartesian2D[source]¶
Bases:
srdatalog.ir.core.Op2-source nested CartesianJoin with tiled smem pre-load + ballot writes.
Lowers to the legacy
_emit_tiled_cartesianshape:if (<total_var> > 32) { // Tiled Cartesian: smem pre-load reads, standard emit_direct writes for (uint32_t <t0_base> = 0; <t0_base> < <degree_var0>; <t0_base> += kCartTileSize) { uint32_t <t0_len> = min(<t0_base> + (uint32_t)kCartTileSize, <degree_var0>) - <t0_base>; for (uint32_t _ti = <lane_var>; _ti < <t0_len>; _ti += <group_size_var>) s_cart[warp_in_block][0][_ti] = <view_var0>.get_value(<col0>, <handle_var0>.begin() + <t0_base> + _ti); for (uint32_t <t1_base> = 0; <t1_base> < <degree_var1>; <t1_base> += kCartTileSize) { uint32_t <t1_len> = min(<t1_base> + (uint32_t)kCartTileSize, <degree_var1>) - <t1_base>; for (uint32_t _ti = <lane_var>; _ti < <t1_len>; _ti += <group_size_var>) s_cart[warp_in_block][1][_ti] = <view_var1>.get_value(<col1>, <handle_var1>.begin() + <t1_base> + _ti); <tile_var>.sync(); uint32_t <tile_total> = <t0_len> * <t1_len>; for (uint32_t <batch_var> = 0; <batch_var> < <tile_total>; <batch_var> += <group_size_var>) { uint32_t <flat_idx_var> = <batch_var> + <lane_var>; bool <valid_var> = <flat_idx_var> < <tile_total>; auto <var_name0> = <valid_var> ? s_cart[warp_in_block][0][<flat_idx_var> / <t1_len>] : ValueType{0}; auto <var_name1> = <valid_var> ? s_cart[warp_in_block][1][<flat_idx_var> % <t1_len>] : ValueType{0}; <tiled_body> } <tile_var>.sync(); } } } else { for (uint32_t <fb_batch_var> = 0; <fb_batch_var> < <total_var>; <fb_batch_var> += <group_size_var>) { uint32_t <flat_idx_var> = <fb_batch_var> + <lane_var>; bool <valid_var> = <flat_idx_var> < <total_var>; const bool <major_var> = (<degree_var1> >= <degree_var0>); uint32_t <idx0_var>, <idx1_var>; if (<major_var>) { <idx0_var> = <flat_idx_var> / <degree_var1>; <idx1_var> = <flat_idx_var> % <degree_var1>; } else { <idx1_var> = <flat_idx_var> / <degree_var0>; <idx0_var> = <flat_idx_var> % <degree_var0>; } auto <var_name0> = <view_var0>.get_value(<col0>, <handle_var0>.begin() + <idx0_var>); auto <var_name1> = <view_var1>.get_value(<col1>, <handle_var1>.begin() + <idx1_var>); <fallback_body> } }bodyis the trailing-InsertInto run rendered as a TiledBallotBlock (thectx.tiled_cartesian_valid_var-driven InsertInto variant). The legacy_emit_tiled_cartesianemitstiled_bodyin both branches when set — so the dialect carries one body and uses it twice. Body emits at the surrounding scope’s indent (legacy quirk where body was rendered before the tiled wrap textually surrounded it).- body: srdatalog.ir.core.Op¶
None