ejkernel.ops.registry

ejkernel.ops.registry#

Global registry for tracking kernel invocations across devices.

This module provides a simple in-memory registry that tracks all kernel invocations organized by device, operation, and call signature. This information is used for batch autotuning and cross-run optimization analysis.

Registry Structure:

device_fingerprint -> operation_id -> call_key -> (kernel, args, kwargs)

The registry enables:
  • Batch autotuning of all recorded operations

  • Analysis of operation patterns and frequencies

  • Cross-device optimization comparison

  • Debugging and profiling of kernel usage

Example Usage:
>>>
>>> record_invocation('gpu|cuda_12.0', 'matmul@v1', 'abc123', kernel, args, kwargs)
>>>
>>>
>>> invocations = get_invocations('gpu|cuda_12.0')
>>> for op_id, calls in invocations.items():
...     print(f"Operation {op_id} has {len(calls)} recorded calls")

Note

The registry is stored in memory and does not persist across program runs. For persistent optimization data, use the PersistentCache system.

ejkernel.ops.registry.get_invocations(dev: str)[source]#

Retrieve all recorded invocations for a specific device.

Returns all kernel invocations that have been recorded for the given device, organized by operation ID and call signature.

Parameters

dev – Device fingerprint to query

Returns

Dictionary mapping operation_id -> call_key -> (kernel, args, kwargs) Returns empty dict if no invocations recorded for this device

Example

>>> invocations = get_invocations('gpu|cuda_12.0')
>>> for op_id, calls in invocations.items():
...     for call_key, (kernel, args, kwargs) in calls.items():
...         print(f"Found {op_id} call {call_key[:8]}...")
ejkernel.ops.registry.record_invocation(dev: str, op_id_v: str, call_key: str, kernel, args, kwargs)[source]#

Record a kernel invocation in the global registry.

Stores the kernel instance and its arguments for later analysis or batch autotuning. The invocation is indexed by device, operation ID, and call signature hash.

Parameters
  • dev – Device fingerprint (e.g., ‘gpu|cuda_12.0’)

  • op_id_v – Operation identifier with version (e.g., ‘matmul@v1’)

  • call_key – Call signature hash from Invocation.call_key

  • kernel – Kernel instance that was invoked

  • args – Positional arguments used in the call

  • kwargs – Keyword arguments used in the call

Note

Arguments are copied (tuple/dict) to prevent mutation of stored data. This function is typically called automatically by the execution system.