BatchSolverKernel
- class cubie.batchsolving.BatchSolverKernel.BatchSolverKernel(system: SymbolicODE, **settings: Any)[source]
Bases:
CUDAFactoryFactory for CUDA kernel which coordinates a batch integration.
- Parameters:
system – ODE system describing the problem to integrate.
**settings – Loop, step, controller, algorithm, output, memory, cache and kernel settings as one flat dict.
- resident_blocks
Blocks per SM on the GPU, set by
auto_performanceandSolver.optimize.
Notes
The kernel delegates integration logic to
SingleIntegratorRuninstances and expects upstream APIs to perform batch construction. It executes the compiled loop function against kernel-managed memory slices and distributes work across GPU threads for each input batch.- _auto_defaults(settings: Dict[str, Any]) Dict[str, Any][source]
Apply and return the built step’s values for the placement and unroll keys
settingsleavesNone.
- _compile_specialization(args: Tuple | None = None) Callable[source]
Compile the selected specialization and return the kernel.
- _compute_launch_geometry(blocksize: int, runs: int | None, resident: int | None) tuple[int, int][source]
Return the geometry holding
residentblocks per SM.
- _configured_launch(blocks: int, threads: Tuple[int, int], stream: Any, dynamic_sharedmem: int) Callable[source]
Return the kernel configured for one launch geometry.
- Parameters:
blocks – Blocks in the grid.
threads – Threads per run and runs per block.
stream – Stream to launch on.
dynamic_sharedmem – Dynamic shared memory per block, in bytes.
- Returns:
The configured launch; call it with the kernel arguments.
- Return type:
Callable
- _default_launch(runs: int | None) tuple[int, int | None][source]
Return the block size and resident blocks per SM of a launch with no block size requested.
- _driver_settings() Dict[str, Any][source]
Return the interpolator’s evaluators and coefficient layout.
- _duration_counts(duration: float) DurationCounts[source]
Return the event counts for
duration, memoised per build.
Return the smallest dynamic shared pad holding
blocksper SM.
- _execute_run(inits: NDArray[floating], params: NDArray[floating], duration: float, blocksize: int | None, stream: Any | None, warmup: float, t0: float, transfer_outputs: bool) None[source]
Allocate, chunk, and launch the batch kernel.
- _kernel_launch_args(chunk_run_params: RunParams) Tuple[source]
Return the kernel’s positional arguments for one chunk.
- _launch_shape(blocksize: int, runs: int | None) tuple[int, int][source]
Return a launch’s block size, halved until its shared footprint fits, and dynamic shared bytes.
- _natural_blocks(blocksize: int, dynamic_sharedmem: int) int[source]
Return the blocks per SM the driver fits at this launch shape.
- _on_allocation(response: ArrayResponse) None[source]
Update run parameters with chunking metadata from allocation.
- _prepare_batch(inits: NDArray[floating], params: NDArray[floating], duration: float, warmup: float, t0: float, stream: Any | None, transfer_outputs: bool = True) None[source]
Set run parameters, refresh settings, and queue allocations.
- _setup_cuda_events(chunks: int) None[source]
Provide the timing events for this run.
- Parameters:
chunks (int) – Number of chunks to process
Notes
One workload event plus three per chunk. The kernel keeps them between runs and rebuilds them when the chunk count or logger verbosity changes.
- _setup_memory_manager(settings: Dict[str, Any]) MemoryManager[source]
Register the kernel with a memory manager instance.
- Parameters:
settings – Mapping of memory configuration options recognised by the memory manager.
- Returns:
Memory manager configured for solver allocations.
- Return type:
- _summaries_legend() Dict[int, str][source]
Map summary output rows to labels with units and metric.
- _update(updates: Dict[str, Any], silent: bool) Set[str][source]
Update the memory manager, interpolator, run and kernel.
- Parameters:
updates – Setting names to new values; gains the derived driver settings after an interpolator change.
silent – Whether
update()ignores unrecognised names.
- Returns:
Names the memory manager, interpolator, run and kernel settings recognised.
- Return type:
Notes
The kernel settings take the run’s
loop_fnand output compile flags last.
- _variable_units() Tuple[Dict[str, str], Dict[str, str]][source]
Return the system’s state and observable units by label.
- property active_outputs: ActiveOutputs
Active output array flags derived from compile_flags.
- property chunks
Number of chunks in the most recent run.
- close(shutdown_timeout: float | None = None) None[source]
Release resources after pending transfers finish.
- Parameters:
shutdown_timeout – Maximum seconds to wait. None waits until transfers finish.
- property coefficients_shape: tuple[int, int, int]
Expected driver-coefficient layout for input validation.
A
BatchSolverConfigcompile setting the owningSolverkeeps aligned withArrayInterpolator.coefficients_shape— the exact(num_segments, num_drivers, order + 1)layout baked into the compiled driver evaluators — so supplied coefficient arrays are checked against the shape the kernel was compiled for. Update viaupdate(coefficients_shape=...).
- property compile_flags: OutputCompileFlags
Boolean compile-time controls for which output features are enabled.
- property device_function
Return the compiled CUDA device function.
- Returns:
Compiled CUDA device function.
- Return type:
callable
- property driver_coefficients: NDArray[floating] | None
Horner-ordered driver coefficients on the host.
- property initial_values: Any
Initial state values used in the last run.
A host view, or the caller’s device array when initial values were supplied on device.
- kernel_is_cached() bool[source]
Whether the disk cache holds this configuration’s kernel;
Falsewhen caching is off.
- property kernel_name: str
Name the compiled kernel is given on the device.
- Returns:
The configured name, or
{algorithm}_{system name}when unset, with the LTO state appended and illegal identifier characters replaced.- Return type:
- launch_geometry(blocksize: int | None = None, runs: int | None = None) tuple[int, int][source]
Return the block size and dynamic shared bytes of a launch.
- launchable_shapes(blocksizes: Sequence[int] = (32, 64, 128, 256), runs: int | None = None) Dict[int, Tuple[int, int]][source]
Dynamic shared bytes and blocks per SM per launchable block size.
- Parameters:
blocksizes – Block sizes to consider.
runs – Runs in the launch;
Nonesizes a full block.
- limit_blocksize(blocksize: int, dynamic_sharedmem: int, bytes_per_run: int, numruns: int) tuple[int, int][source]
Halve the block size until dynamic shared memory is launchable.
- Parameters:
blocksize – Requested CUDA block size.
dynamic_sharedmem – Shared-memory footprint per block at the current block size.
bytes_per_run – Shared-memory requirement per run.
numruns – Runs the launch places in one block.
- Returns:
Adjusted block size and shared-memory footprint per block, within the device’s opt-in per-block limit.
- Return type:
- Raises:
ValueError – If a single run’s shared-memory demand exceeds the device’s per-block limit, so no block size can launch.
- property memory_manager: MemoryManager
Registered memory manager for this kernel.
- property output_array_heights: OutputArrayHeights
Height metadata for the batched output arrays.
- property parameters: Any
Parameter tables used in the last run.
A host view, or the caller’s device array when parameters were supplied on device.
- performance_defaults() Dict[str, Any][source]
Return the placements and unroll flags the built step picks.
- property persistent_local_elements: int
Number of elements in the per-thread persistent local array.
- run(inits: NDArray[floating], params: NDArray[floating], duration: float, blocksize: int | None = None, warmup: float = 0.0, t0: float = 0.0, transfer_outputs: bool = True) None[source]
Execute the solver kernel for batch integration.
Chunking is performed along the run axis when memory constraints require splitting the batch.
- Parameters:
inits – Initial conditions with shape
(n_states, n_runs). Host or device arrays are accepted; device arrays are used in place with no host-to-device transfer.params – Parameter table with shape
(n_params, n_runs). Host or device arrays are accepted, as forinits.duration – Duration of the simulation window.
blocksize – CUDA block size for this launch;
Noneuses theblocksizesetting, or the automatic launch when that is unset.warmup – Warmup time before the main simulation.
t0 – Initial integration time.
transfer_outputs – When
True(default), output arrays are copied device-to-host after each chunk.Falseleaves results in the device output buffers and touches no host output buffer; the run must fit in a single chunk.
Notes
The kernel prepares array views, queues allocations, and executes the device loop on each chunked workload. Shared-memory demand may reduce the block size automatically, emitting a warning when the limit drops below a warp. Every launch and transfer runs on this kernel’s memory-manager stream (
stream); there is no per-run stream selection.- Raises:
RuntimeError – If the kernel has been closed.
ValueError – Drivers declared but no evaluator wired; chunked batch with
transfer_outputs=Falseor device inputs.
- property save_every: float | None
Interval between saved samples from the loop, or None if save_last only.
- set_cache_dir(path: str | Path) None[source]
Set a custom cache directory for compiled kernels.
- Parameters:
path – New cache directory path. Can be absolute or relative.
- settings_keys: frozenset | None = frozenset({'auto_performance', 'blocksize', 'cache_dir', 'cache_enabled', 'kernel_name', 'max_cache_entries', 'max_registers'})
Loose keys the factory accepts;
Noneaccepts every field.
Shared-memory footprint per run for the compiled kernel.
Number of precision elements required in shared memory per run.
Indicate whether shared-memory padding is required.
- Returns:
Truewhen a four-byte skew reduces bank conflicts for single precision.- Return type:
Notes
Shared memory load instructions for
float64require eight-byte alignment. Padding in that scenario would misalign alternate runs and trigger misaligned-access faults, so padding only applies to single precision workloads where the skew preserves alignment.