Home

3.7. OpenCL model evaluator

«  3.6. Model parser   ::   Contents   ::   3.8. Ctypes model evaluator  »

3.7. OpenCL model evaluator

3.7.1. sasmodels.kernelcl

GPU support through OpenCL

There should be a single GPU environment running on the system. This environment is constructed on the first call to env(), and the same environment is returned on each call.

After retrieving the environment, the next step is to create the kernel. This is done with a call to GpuEnvironment.make_kernel(), which returns the type of data used by the kernel.

Next a GpuData object should be created with the correct kind of data. This data object can be used by multiple kernels, for example, if the target model is a weighted sum of multiple kernels. The data should include any extra evaluation points required to compute the proper data smearing. This need not match the square grid for 2D data if there is an index saying which q points are active.

Together the GpuData, the program, and a device form a GpuKernel. This kernel is used during fitting, receiving new sets of parameters and evaluating them. The output value is stored in an output buffer on the devices, where it can be combined with other structure factors and form factors and have instrumental resolution effects applied.

class sasmodels.kernelcl.GpuEnvironment

Bases: object

GPU context, with possibly many devices, and one queue per device.

compile_program(name, source, dtype)
release_program(name)
class sasmodels.kernelcl.GpuInput(q_vectors, dtype=dtype('float32'))

Bases: object

Make q data available to the gpu.

q_vectors is a list of q vectors, which will be [q] for 1-D data, and [qx, qy] for 2-D data. Internally, the vectors will be reallocated to get the best performance on OpenCL, which may involve shifting and stretching the array to better match the memory architecture. Additional points will be evaluated with q=1e-3.

dtype is the data type for the q vectors. The data type should be set to match that of the kernel, which is an attribute of GpuProgram. Note that not all kernels support double precision, so even if the program was created for double precision, the GpuProgram.dtype may be single precision.

Call release() when complete. Even if not called directly, the buffer will be released when the data object is freed.

release()
class sasmodels.kernelcl.GpuKernel(kernel, info, q_input)

Bases: object

Callable SAS kernel.

kernel is the GpuKernel object to call.

info is the module information

q_input is the DllInput q vectors at which the kernel should be evaluated.

The resulting call method takes the pars, a list of values for the fixed parameters to the kernel, and pd_pars, a list of (value,weight) vectors for the polydisperse parameters. cutoff determines the integration limits: any points with combined weight less than cutoff will not be calculated.

Call release() when done with the kernel instance.

release()
class sasmodels.kernelcl.GpuModel(source, info, dtype=dtype('float32'))

Bases: object

GPU wrapper for a single model.

source and info are the model source and interface as returned from gen.make().

dtype is the desired model precision. Any numpy dtype for single or double precision floats will do, such as ‘f’, ‘float32’ or ‘single’ for single and ‘d’, ‘float64’ or ‘double’ for double. Double precision is an optional extension which may not be available on all devices.

make_input(q_vectors)

Make q input vectors available to the model.

Note that each model needs its own q vector even if the case of mixture models because some models may be OpenCL, some may be ctypes and some may be pure python.

release()
sasmodels.kernelcl.compile_model(context, source, dtype)

Build a model to run on the gpu.

Returns the compiled program and its type. The returned type will be float32 even if the desired type is float64 if any of the devices in the context do not support the cl_khr_fp64 extension.

sasmodels.kernelcl.environment()

Returns a singleton GpuEnvironment.

This provides an OpenCL context and one queue per device.

sasmodels.kernelcl.get_warp(kernel, queue)

Return the size of an execution batch for kernel running on queue.

sasmodels.kernelcl.has_double(device)

Return true if device supports double precision.

sasmodels.kernelcl.make_result(self, size)

«  3.6. Model parser   ::   Contents   ::   3.8. Ctypes model evaluator  »