cuda
codegen.cuda
CUDA Adapter for TVBO.
Run generated CUDA kernels using PyCUDA.
Usage
from tvbo import SimulationExperiment
exp = SimulationExperiment.from_file(“experiment.yaml”) result = exp.run(‘cuda’)
Functions
| Name | Description |
|---|---|
| compile_cuda | Compile CUDA kernel for experiment. |
| run_cuda | Run CUDA simulation for experiment. |
| save_cuda | Save CUDA source to file. |
compile_cuda
codegen.cuda.compile_cuda(experiment)Compile CUDA kernel for experiment.
Compiled with no_extern_c=True. The kernel includes <curand_kernel.h> for its noise, and the block SourceModule otherwise wraps a whole source in gives those headers C linkage — which their templates may not have, so every compile failed with 33 errors out of curand rather than anything to do with the model. The kernels declare extern "C" themselves instead, which is what keeps get_function able to find them under their unmangled names.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| experiment | SimulationExperiment | SimulationExperiment instance | required |
Returns
| Name | Type | Description |
|---|---|---|
| tuple[Any, Any] | Tuple of (module, kernel_func) |
run_cuda
codegen.cuda.run_cuda(
experiment,
n_steps=None,
dt=None,
n_work_items=1,
global_speed=1.0,
global_coupling=0.1,
buffer_length=None,
swept_params=None,
)Run CUDA simulation for experiment.
All configuration comes from experiment metadata.
The kernel integrates in the model’s own time unit — it multiplies dt straight into the model’s equations — while indexing the delay ring as length / speed / dt, which is millimetres over metres-per-second and so is milliseconds. The two agree only for a model whose time unit is ms; anything else gets the right trajectory on the wrong delays, so dt is passed through in model units rather than converted onto either.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| experiment | SimulationExperiment | SimulationExperiment instance | required |
| n_steps | int | None | Number of integration steps (default from experiment.integration) | None |
| dt | float | None | Integration time step in the model’s own time unit (default: its step_size) |
None |
| n_work_items | int | Number of parallel parameter configurations | 1 |
| global_speed | float | Conduction speed (m/s) | 1.0 |
| global_coupling | float | Global coupling strength | 0.1 |
| buffer_length | int | None | History buffer length (auto-calculated if None) | None |
| swept_params | dict[str, np.ndarray] | None | Dict mapping param names to arrays of values per work item | None |
Returns
| Name | Type | Description |
|---|---|---|
| dict[str, np.ndarray] | Dict with ‘tavg’, ‘n_node’, ‘n_steps’, ‘dt’ |
save_cuda
codegen.cuda.save_cuda(experiment, path)Save CUDA source to file.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| experiment | SimulationExperiment | SimulationExperiment instance | required |
| path | str | Output file path (.cu) | required |
Returns
| Name | Type | Description |
|---|---|---|
| str | Path to saved file |