srdatalog.ir.codegen.cuda.plugin

Index-type plugin registry + default DSAI (DeviceSortedArrayIndex) hooks.

Port of src/srdatalog/index_plugin.nim. Every C++ expression the JIT backend emits for handle/view operations dispatches through an IndexPlugin so custom index types (e.g., Device2LevelIndex used by polonius_test) can override behavior. The default plugin matches DSAI and is what every existing integration fixture uses.

Module Contents

Classes

IndexPlugin

Codegen hooks for one index family. Each field is a callable that emits a C++ expression string. Plugins register themselves by C++ type (cpp_type) and the resolver falls back to the default (DSAI) when no plugin is registered for a given type.

PrefixMode

How a prefix() / prefix_lower_bound() call is dispatched.

Functions

get_extra_headers_for_types

Collect unique C++ headers declared by the plugins resolving from index_types. Empty strings are skipped.

new_default_plugin

Baseline DSAI plugin — matches every built-in integration fixture.

plugin_chained_prefix_calls

Emit chained .prefix(key, …) calls. For each v in prefix_vars:

plugin_chained_prefix_with_last_lower_bound

Like plugin_chained_prefix_calls but the LAST key uses prefix_lower_bound instead of prefix. Used for range intersection.

plugin_gen_child

plugin_gen_child_range

plugin_gen_degree

plugin_gen_get_value

plugin_gen_get_value_at

plugin_gen_host_view_setup

plugin_gen_iterators

plugin_gen_prefix

plugin_gen_prefix_lower_bound

plugin_gen_root_handle

plugin_gen_valid

plugin_view_count

register_index_plugin

Register a plugin by its cpp_type string. Called from each index module at import time (mirroring Nim’s compile-time registration).

resolve_plugin

Look up plugin by C++ type; empty string / unknown type returns the default (DSAI). Substring match lets partial type strings resolve, matching Nim’s resolvePlugin behavior.

API

class srdatalog.ir.codegen.cuda.plugin.IndexPlugin[source]

Codegen hooks for one index family. Each field is a callable that emits a C++ expression string. Plugins register themselves by C++ type (cpp_type) and the resolver falls back to the default (DSAI) when no plugin is registered for a given type.

cpp_headers: list[str]

‘field(…)’

cpp_type: str

None

gen_child: collections.abc.Callable[[str, str], str]

None

gen_child_range: collections.abc.Callable[[str, str, str, str, str], str]

None

gen_degree: collections.abc.Callable[[str], str]

None

gen_get_value: collections.abc.Callable[[str, int, str], str]

None

gen_get_value_at: collections.abc.Callable[[str, str, str], str]

None

gen_host_view_setup: collections.abc.Callable[[str, str], list[str]]

None

gen_iterators: collections.abc.Callable[[str, str], str]

None

gen_prefix: collections.abc.Callable[[str, str, str, srdatalog.ir.codegen.cuda.plugin.PrefixMode], str]

None

gen_prefix_lower_bound: collections.abc.Callable[[str, str, str, srdatalog.ir.codegen.cuda.plugin.PrefixMode], str]

None

gen_root_handle: collections.abc.Callable[[str], str]

None

gen_valid: collections.abc.Callable[[str], str]

None

name: str

None

view_count: collections.abc.Callable[[str], int]

None

class srdatalog.ir.codegen.cuda.plugin.PrefixMode(*args, **kwds)[source]

Bases: enum.Enum

How a prefix() / prefix_lower_bound() call is dispatched.

Initialization

COOPERATIVE

‘cooperative’

SEQUENTIAL

‘sequential’

srdatalog.ir.codegen.cuda.plugin.get_extra_headers_for_types(index_types: list[str]) list[str][source]

Collect unique C++ headers declared by the plugins resolving from index_types. Empty strings are skipped.

srdatalog.ir.codegen.cuda.plugin.new_default_plugin() srdatalog.ir.codegen.cuda.plugin.IndexPlugin[source]

Baseline DSAI plugin — matches every built-in integration fixture.

srdatalog.ir.codegen.cuda.plugin.plugin_chained_prefix_calls(parent_handle: str, prefix_vars: list[str], view_var: str, cartesian_bound_vars: list[str] | None = None, scalar_mode: bool = False, index_type: str = '') str[source]

Emit chained .prefix(key, …) calls. For each v in prefix_vars:

  • Sequential mode (per-thread), or cartesian_bound_vars containing v: use .prefix_seq(v, view)

  • Else cooperative: .prefix(v, tile, view)

Matches Nim’s pluginChainedPrefixCalls exactly.

srdatalog.ir.codegen.cuda.plugin.plugin_chained_prefix_with_last_lower_bound(parent_handle: str, prefix_vars: list[str], view_var: str, cartesian_bound_vars: list[str] | None = None, scalar_mode: bool = False, index_type: str = '') str[source]

Like plugin_chained_prefix_calls but the LAST key uses prefix_lower_bound instead of prefix. Used for range intersection.

srdatalog.ir.codegen.cuda.plugin.plugin_gen_child(handle: str, idx: str, index_type: str = '') str[source]
srdatalog.ir.codegen.cuda.plugin.plugin_gen_child_range(handle: str, pos: str, key: str, tile: str, view_var: str, index_type: str = '') str[source]
srdatalog.ir.codegen.cuda.plugin.plugin_gen_degree(handle: str, index_type: str = '') str[source]
srdatalog.ir.codegen.cuda.plugin.plugin_gen_get_value(view_var: str, col: int, pos: str, index_type: str = '') str[source]
srdatalog.ir.codegen.cuda.plugin.plugin_gen_get_value_at(handle: str, view_var: str, idx: str, index_type: str = '') str[source]
srdatalog.ir.codegen.cuda.plugin.plugin_gen_host_view_setup(idx_expr: str, version: str, index_type: str = '') list[str][source]
srdatalog.ir.codegen.cuda.plugin.plugin_gen_iterators(handle: str, view_var: str, index_type: str = '') str[source]
srdatalog.ir.codegen.cuda.plugin.plugin_gen_prefix(handle: str, key: str, view_var: str, mode: srdatalog.ir.codegen.cuda.plugin.PrefixMode, index_type: str = '') str[source]
srdatalog.ir.codegen.cuda.plugin.plugin_gen_prefix_lower_bound(handle: str, key: str, view_var: str, mode: srdatalog.ir.codegen.cuda.plugin.PrefixMode, index_type: str = '') str[source]
srdatalog.ir.codegen.cuda.plugin.plugin_gen_root_handle(view_var: str, index_type: str = '') str[source]
srdatalog.ir.codegen.cuda.plugin.plugin_gen_valid(handle: str, index_type: str = '') str[source]
srdatalog.ir.codegen.cuda.plugin.plugin_view_count(version: str, index_type: str = '') int[source]
srdatalog.ir.codegen.cuda.plugin.register_index_plugin(plugin: srdatalog.ir.codegen.cuda.plugin.IndexPlugin) None[source]

Register a plugin by its cpp_type string. Called from each index module at import time (mirroring Nim’s compile-time registration).

srdatalog.ir.codegen.cuda.plugin.resolve_plugin(index_type: str) srdatalog.ir.codegen.cuda.plugin.IndexPlugin[source]

Look up plugin by C++ type; empty string / unknown type returns the default (DSAI). Substring match lets partial type strings resolve, matching Nim’s resolvePlugin behavior.