From 48d7f87db4c3323179f29080c12892d3f74761df Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Mon, 28 Sep 2009 02:37:34 -0400 Subject: [PATCH] Allow constructing contexts with no arguments. --- doc/source/index.rst | 2 +- doc/source/reference.rst | 6 ++++-- examples/demo.py | 2 +- src/wrapper/wrap_cl.hpp | 14 ++++++-------- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/doc/source/index.rst b/doc/source/index.rst index a695b9dd..30509659 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 cbbfbb14..3f56e764 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 f93054f8..fb1499a7 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 8199ba87..426a8d4d 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); -- GitLab