# API¶

This page details the methods and classes provided by the cudapyint module.

## CudaPyInt Solver¶

class cudapyint.Solver.Solver[source]

‘Abstract’ base class for gpu based solver implementations.

_getOptimalGPUParam(compiledKernel=None)[source]

Returns the optimal size of blocks and threads for the given compiled source

Parameters: compiledKernel – sourceModule The kernel to use to determine the optimal param config blocks, threads
solve(y0, t, args=None, timing=False, info=False, write_code=False, full_output=False, **kwargs)[source]

Integrate a system of ordinary differential equations.

Solves the initial value problem for stiff or non-stiff systems of first order ode-s:

dy/dt = func(y,t0,...)


where y can be a vector.

Parameters: y0 – array Initial condition on y (can be a vector). t – array A sequence of time points for which to solve for y. The initial value point should be the first element of this sequence. args – array Extra arguments to pass to function. timing – bool True if timing output should be printed info – bool True if additional infos should be printed write_code – bool True if the generated code should be written to the disk full_output – boolean True if to return a dictionary of optional outputs as the second output use_jacobian – bool Flag indicating if a jacobian matrix is provided. Requires an implementation in the kernel atol (rtol,) – float The input parameters rtol and atol determine the error control performed by the solver. The solver will control the vector, e, of estimated local errors in y, according to an inequality of the form max-norm of (e / ewt) <= 1, where ewt is a vector of positive error weights computed as: ewt = rtol * abs(y) + atol rtol and atol can be either vectors the same length as y or scalars. Defaults to 1.49012e-8. h0 – float, (0: solver-determined) The step size to be attempted on the first step. mxstep – integer, (0: solver-determined) Maximum number of (internally defined) steps allowed for each integration point in t.
y : array, shape (len(t), len(y0))
Array containing the value of y for each desired time in t, with the initial value y0 in the first row.
infodict : dict, only returned if full_output == True

key meaning
‘message’ message representing state of system
‘system’ index of system
‘nst’ cumulative number of time steps
‘nfe’ cumulative number of function evaluations for each time step
‘nje’ cumulative number of jacobian evaluations for each time step

## CudaPyInt ODE Solvers¶

Standard usage of CudaPyint involves instantiating an ODESolver.

class cudapyint.ODESolver.ODESolver(cudaCodePath, constants, compile_options=None)[source]

Solver implementation to solve ODE using CULSODA. Manages the compilation and execution of the CUDA kernel

__init__(cudaCodePath, constants, compile_options=None)[source]

Constructor for the ode solver.

Parameters: cudaCodePath – string Path to the cuda kernel. constants – dict Dictionary containing constants value used for the integration. Supported values are: int, float, numpy.float32, numpy.float64, numpy.array compile_options – list (optional) List of options passed to the compiler
_compile(write_code)[source]

Generates and compiles the cuda kernel.

Parameters: write_code – bool True if the generated code should be written to the disk
_compileSourceModule(code, options)[source]

Compiles the given code with pycuda using the given options.

Parameters: code – string valid CUDA C code to compile options – list List of options passed to the compiler
_solve_internal(initValues, args, blocks, threads, full_output=False, use_jacobian=False, in_atol=1e-12, in_rtol=1e-06, mxstep=500, h0=0.0)[source]

Integrates the ODE system for the current blocks. Initializes all required fields on the host and device, executes the gpu computations and returns the integrated values.

Parameters: initValues – array Values of y at t0 args – array Array of arguments used for the integration. blocks – int Number of threadblocks to launch threads – int Number of threads to launch per block full_output – bool (optional) True if to return a dictionary of optional infodicts as the second output use_jacobian – bool (optional) True if a jacobian is provided and should be used for the integration atol (rtol,) – float (optional) Used for error control mxstep – integer, (0: solver-determined) Maximum number of (internally defined) steps h0 – float, (0: solver-determined) The step size to be attempted on the first step.
_post_process_results(results, infodicts, nsystems, blocks, threads, full_output)[source]

Template method to post process the results

Parameters: results – array Values of the integrated ODE’s infodicts – array Additional infodicts nsystems – int Number of ode systems blocks – int Number of executed blocks threads – int Number of executed threads per block full_output – bool True if additional output is required
_copy_constants()[source]

Copies the constants from the host to the device using PyCuda

To run CudaPyint with CUDA shared memory involves instantiating an ODESolverSharedMemory.

class cudapyint.ODESolverSharedMemory.ODESolverSharedMemory(cudaCodePath, constants, compile_options=None)[source]

Extends the ODESolver the enable CUDA shared memory.

## CudaPyInt ODE Solvers for parallel integration¶

To run CudaPyInt with parallel computation of equations within a system involves instantiating an ParallelODESolver.

Extension of the ODESolver for parallel computation of the equations within one ODE System

To run CudaPyInt with parallel computation of equations within a system with CUDA shared memory involves instantiating an ParallelODESolver.

Extends the ParallelODESolver the enable CUDA shared memory.

## CudaPyInt Generator¶

Every CudaPyInt Solver uses an instance of the CodeGenerator.

class cudapyint.CodeGenerator.CodeGenerator(cudaCodePath, constants)[source]

Abstract code generator. Provides function for type conversion and file persisting

__init__(cudaCodePath, constants)[source]

Constructor for the ode solver.

Parameters: cudaCodePath – string Path to the cuda kernel. constants – dict Dictionary containing constants value used for the integration. Supported values are: int, float, numpy.float32, numpy.float64, numpy.array
_writeCode(code)[source]

Writes the given code to the disk

Parameters: code – string The code to be written
_create_constants_fields()[source]

Generates CUDA C code to store the constants. The Python structures are automatically converted in C structures. See _SUPPORTED_DATA_TYPES for the supported data types

Generated code for constants

The CudaPyInt ODE Solver uses an Instance of the CulsodaCodeGenerator.

class cudapyint.CulsodaCodeGenerator.CulsodaCodeGenerator(cudaCodePath, constants, culsoda_file_name, culsoda_main_file_name, args_tex_name)[source]

Extends the cudapyint.CodeGenerator in order to generate Culsoda specific code.

__init__(cudaCodePath, constants, culsoda_file_name, culsoda_main_file_name, args_tex_name)[source]

Constructor for the ode solver.

Parameters: cudaCodePath – string Path to the cuda kernel. constants – dict Dictionary containing constants value used for the integration. Supported values are: int, float, numpy.float32, numpy.float64, numpy.array culsoda_file_name – string name of the culsoda source file culsoda_main_file_name – string name of the culsoda main source file args_tex_name – string name of the arguments texture

Generates the complete culsoda code

Parameters: blocks – int (optional) The number of blocks threads – int (optional) The number of threads / block write_code – bool (optional) True if the generated code should be written to the disc

The generated code

## CudaPyInt PyCudaUtils¶

Simple util class Pycuda.

cudapyint.PyCudaUtils.create_2D_array(mat)[source]

Creates a 2D array on the GPU which can be used to assign texture memory from 2D numpy array

Parameters: mat – the 2D array to use
cudapyint.PyCudaUtils.copy2D_host_to_array(arr, host, width, height)[source]

Copies the array from the host to the device

Parameters: arr – the GPU array host – the source on the host width – width of the array height – height of the array
cudapyint.PyCudaUtils.copy_host_to_device(src)[source]

Allocates the memory on the device and copies the data

Parameters: src – the source data structure

y: handle to data structure on device