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; the interpolation settings and compile flags reach the driver interpolator.
- 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.- _compute_launch_geometry(blocksize: int, runs: int, resident: int | None) tuple[int, int][source]
Return the geometry holding
residentblocks per SM.
- _default_launch(runs: int) 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) 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) 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. While timing is on they are kept between runs and rebuilt when the chunk count or logger verbosity changes; with timing off each run gets fresh no-op events.
- _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.
- _validate_timing_parameters(duration: float) None[source]
Validate timing parameters to prevent invalid array accesses.
- Parameters:
duration – Integration duration in time units.
- Raises:
ValueError – When timing parameters would result in no outputs or invalid sampling.
Notes
Uses dt_min as an absolute tolerance when comparing floating point timing parameters by adding dt_min to the requested duration. Small in-loop timing oversteps smaller than dt_min are treated as valid and do not trigger validation errors.
- _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=...).
- compile(inits: NDArray[floating], params: NDArray[floating], duration: float, warmup: float = 0.0, t0: float = 0.0) None[source]
Compile the batch kernel for these inputs without launching.
- property compile_flags: OutputCompileFlags
Boolean compile-time controls for which output features are enabled.
- configure_drivers(drivers: Dict[str, Any]) None[source]
Update the owned driver interpolator and dependent settings.
- Parameters:
drivers – Driver samples plus interpolation settings, as accepted by
ArrayInterpolator.update_from_dict().
- 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.
- driver_inputs() Dict[str, Any] | None[source]
Drivers as passed to
configure_drivers;Nonewhen unset.
- 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) 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.
runstypes the shapes;Noneuses the staged batch.
- 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 – Total number of runs queued for the launch.
- 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.
- 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.Falseskips the copy so results stay in the device output buffers; 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', 'cache_dir', 'cache_enabled', 'cache_mode', '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.
- update(updates_dict: Dict[str, Any] | None = None, silent: bool = False, **kwargs: Any) set[str][source]
Update solver configuration parameters.
- Parameters:
updates_dict – Mapping of parameter updates forwarded to the single integrator and compile settings.
silent – Flag suppressing errors when unrecognised parameters remain.
**kwargs – Additional parameter overrides merged into
updates_dict.
- Returns:
Names of parameters successfully applied.
- Return type:
- Raises:
KeyError – Raised when unknown parameters persist and
silentisFalse.
Notes
Order: memory manager, interpolator, run, then this kernel’s settings with the run’s
loop_fnand compile flags.