OpenCL Runtime: Platforms, Devices and Contexts
Platform
|comparable|
Device
Two instances of this class may be compared using ==" and "!=".
Context
Create a new context. properties is a list of key-value tuples, where each key must be one of :class:`context_properties`. At most one of devices and dev_type may be not None, where devices is a list of :class:`Device` instances, and dev_type is one of the :class:`device_type` constants. If neither is specified, a context with a dev_type of :attr:`device_type.DEFAULT` is created.
If cache_dir is not None - it will be used as default cache_dir for all its' :class:`Program` instances builds (see also :meth:`Program.build`).
Note
Calling the constructor with no arguments will fail for recent CL drivers that support the OpenCL ICD. If you want similar, just-give-me-a-context-already behavior, we recommend :func:`create_some_context`. See, e.g. this explanation by AMD.
Note
Because of how OpenCL changed in order to support Installable Client Drivers (ICDs) in OpenCL 1.1, the following will look reasonable but often actually not work:
import pyopencl as cl
ctx = cl.Context(dev_type=cl.device_type.ALL)
Instead, make sure to choose a platform when choosing a device by type:
import pyopencl as cl
platforms = cl.get_platforms()
ctx = cl.Context(
dev_type=cl.device_type.ALL,
properties=[(cl.context_properties.PLATFORM, platforms[0])])
Note
For
context_properties.CL_GL_CONTEXT_KHR
,
context_properties.CL_EGL_DISPLAY_KHR
,
context_properties.CL_GLX_DISPLAY_KHR
,
context_properties.CL_WGL_HDC_KHR
, and
context_properties.CL_CGL_SHAREGROUP_KHR
context_properties.CL_CGL_SHAREGROUP_APPLE
the value in the key-value pair is a PyOpenGL context or display
instance.
|comparable|