diff --git a/doc/source/index.rst b/doc/source/index.rst index a695b9dddb06f1c7012613e346bf9cedf3e5c6a6..3050965906ddcdfe12b71f5be5b3f3bc4d1e37a9 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -36,7 +36,7 @@ Here's an example, to give you an impression:: a = numpy.random.rand(50000).astype(numpy.float32) b = numpy.random.rand(50000).astype(numpy.float32) - ctx = cl.create_context_from_type(cl.device_type.ALL) + ctx = cl.Context() queue = cl.CommandQueue(ctx) mf = cl.mem_flags diff --git a/doc/source/reference.rst b/doc/source/reference.rst index cbbfbb14ac9ee79d42181b1f5a0d4892f03a8015..3f56e764c1aceda71699bea8dc5c9fd9bb7fea96 100644 --- a/doc/source/reference.rst +++ b/doc/source/reference.rst @@ -93,13 +93,15 @@ Platforms, Devices and Contexts Two instances of this class may be compared using *=="* and *"!="*. -.. class:: Context(devices, properties=None, dev_type=None) +.. class:: Context(devices=None, properties=None, dev_type=None) Create a new context. *properties* is a list of key-value tuples, where each key must be one of :class:`context_properties`. - Exactly one of *devices* and *dev_type* must be not `None`, where + 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. .. versionchanged:: 0.91.2 Constructor arguments *dev_type* added. diff --git a/examples/demo.py b/examples/demo.py index f93054f8a1a371b84fc8a82c05b64925781edd1f..fb1499a7e82574353df119c5b4f310fe3627c83d 100644 --- a/examples/demo.py +++ b/examples/demo.py @@ -5,7 +5,7 @@ import numpy.linalg as la a = numpy.random.rand(50000).astype(numpy.float32) b = numpy.random.rand(50000).astype(numpy.float32) -ctx = cl.Context(dev_type=cl.device_type.ALL) +ctx = cl.Context() queue = cl.CommandQueue(ctx) mf = cl.mem_flags diff --git a/src/wrapper/wrap_cl.hpp b/src/wrapper/wrap_cl.hpp index 8199ba87b569d5508854a3f578b83b7f978ed237..426a8d4d112c0bd955c53c6804dcce3192a9ebce 100644 --- a/src/wrapper/wrap_cl.hpp +++ b/src/wrapper/wrap_cl.hpp @@ -675,18 +675,16 @@ namespace pyopencl PYOPENCL_PRINT_CALL_TRACE("clCreateContext"); } // from dev_type - else if (py_dev_type.ptr() != Py_None) + else { - py::extract dev_type(py_dev_type); - ctx = clCreateContextFromType( - props_ptr, dev_type, - 0, 0, &status_code); + cl_device_type dev_type = CL_DEVICE_TYPE_DEFAULT; + if (py_dev_type.ptr() != Py_None) + dev_type = py::extract(py_dev_type)(); + + ctx = clCreateContextFromType(props_ptr, dev_type, 0, 0, &status_code); PYOPENCL_PRINT_CALL_TRACE("clCreateContextFromType"); } - else - throw error("Context", CL_INVALID_VALUE, - "one of 'devices' or 'dev_type' must be not None"); if (status_code != CL_SUCCESS) throw pyopencl::error("Context", status_code);