# OpenCL¶

Export to an OpenCL simulation. A driver is provided to run cable simulations and a quick plot script is included.

Notes:

• The generated code requires OpenCL enabled drivers for the GPU or CPU it’s runnning on to be pre-installed, as well as an implementation of the OpenCL libraries. These can be downloaded from various hardware manufacturers’ websites.

## API¶

The standard interface for exporting and accessing expression writers is provided:

myokit.formats.opencl.exporters()

Returns a dict of all exporters available in this module.

class myokit.formats.opencl.OpenCLExporter

This Exporter creates a cable simulation that can run on any OpenCL environment (GPU or CPU).

A value must be bound to diffusion_current which represents the current flowing from cell to cell. This is defined as positive when the cell is acting as a source, negative when it acts like a sink. In other words, it is defined as an outward current.

The membrane potential must be labelled as membrane_potential.

By default, the simulation is set to log all state variables. This is nice to explore results with, but quite slow…

Please keep in mind that CellML and other downloaded formats are typically not directly suitable for GPU simulation. Specifically, when simulating on single-precision devices a lot of divide-by-zero errors might crop up that remain hidden when using double precision single cell simulations on the CPU.

info()

This should be implemented by each subclass.

class myokit.formats.opencl.OpenCLRLExporter

Like OpenCLExporter but uses a Rush-Larsen update step where applicable.

myokit.formats.opencl.ewriters()

Returns a dict of all expression writers available in this module.

class myokit.formats.opencl.OpenCLExpressionWriter(precision=32, native_math=True)

This ExpressionWriter translates Myokit expressions to OpenCL syntax.

eq(q)

Converts an equation to a string

ex(e)

Converts an Expression to a string.

set_lhs_function(f)
Sets a naming function, will be called to get the variable name from a
myokit.LhsExpression object.

The argument f should be a function that takes an LhsExpression as input and returns a string.