diff --git a/doc/source/.gitignore b/doc/source/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..afaa1ea072c3dffe7dbd76616873fcd491ef8959 --- /dev/null +++ b/doc/source/.gitignore @@ -0,0 +1 @@ +constants.inc diff --git a/doc/source/constants.inc b/doc/source/constants.inc deleted file mode 100644 index 6052535e89b13481c3448b94a1bda7ac3a52be71..0000000000000000000000000000000000000000 --- a/doc/source/constants.inc +++ /dev/null @@ -1,276 +0,0 @@ -.. This is an automatically generated file. DO NOT EDIT -.. class :: addressing_mode - - .. attribute :: CLAMP - .. attribute :: CLAMP_TO_EDGE - .. attribute :: NONE - .. attribute :: REPEAT - -.. class :: channel_order - - .. attribute :: A - .. attribute :: BGRA - .. attribute :: INTENSITY - .. attribute :: LUMINANCE - .. attribute :: R - .. attribute :: RA - .. attribute :: RG - .. attribute :: RGB - .. attribute :: RGBA - -.. class :: channel_type - - .. attribute :: FLOAT - .. attribute :: HALF_FLOAT - .. attribute :: SIGNED_INT16 - .. attribute :: SIGNED_INT32 - .. attribute :: SIGNED_INT8 - .. attribute :: SNORM_INT16 - .. attribute :: SNORM_INT8 - .. attribute :: UNORM_INT16 - .. attribute :: UNORM_INT8 - .. attribute :: UNORM_INT_101010 - .. attribute :: UNORM_SHORT_555 - .. attribute :: UNORM_SHORT_565 - .. attribute :: UNSIGNED_INT16 - .. attribute :: UNSIGNED_INT32 - .. attribute :: UNSIGNED_INT8 - -.. class :: command_execution_status - - .. attribute :: COMPLETE - .. attribute :: QUEUED - .. attribute :: RUNNING - .. attribute :: SUBMITTED - -.. class :: command_queue_info - - .. attribute :: CONTEXT - .. attribute :: DEVICE - .. attribute :: PROPERTIES - .. attribute :: REFERENCE_COUNT - -.. class :: command_queue_properties - - .. attribute :: OUT_OF_ORDER_EXEC_MODE_ENABLE - .. attribute :: PROFILING_ENABLE - -.. class :: command_type - - .. attribute :: ACQUIRE_GL_OBJECTS - .. attribute :: COPY_BUFFER - .. attribute :: COPY_BUFFER_TO_IMAGE - .. attribute :: COPY_IMAGE - .. attribute :: COPY_IMAGE_TO_BUFFER - .. attribute :: MAP_BUFFER - .. attribute :: MAP_IMAGE - .. attribute :: MARKER - .. attribute :: NATIVE_KERNEL - .. attribute :: NDRANGE_KERNEL - .. attribute :: READ_BUFFER - .. attribute :: READ_IMAGE - .. attribute :: RELEASE_GL_OBJECTS - .. attribute :: TASK - .. attribute :: UNMAP_MEM_OBJECT - .. attribute :: WRITE_BUFFER - .. attribute :: WRITE_IMAGE - -.. class :: context_info - - .. attribute :: DEVICES - .. attribute :: PROPERTIES - .. attribute :: REFERENCE_COUNT - -.. class :: context_properties - - .. attribute :: PLATFORM - -.. class :: device_exec_capabilities - - .. attribute :: KERNEL - .. attribute :: NATIVE_KERNEL - -.. class :: device_fp_config - - .. attribute :: DENORM - .. attribute :: FMA - .. attribute :: INF_NAN - .. attribute :: ROUND_TO_INF - .. attribute :: ROUND_TO_NEAREST - .. attribute :: ROUND_TO_ZERO - -.. class :: device_info - - .. attribute :: ADDRESS_BITS - .. attribute :: AVAILABLE - .. attribute :: COMPILER_AVAILABLE - .. attribute :: ENDIAN_LITTLE - .. attribute :: ERROR_CORRECTION_SUPPORT - .. attribute :: EXECUTION_CAPABILITIES - .. attribute :: EXTENSIONS - .. attribute :: GLOBAL_MEM_CACHELINE_SIZE - .. attribute :: GLOBAL_MEM_CACHE_SIZE - .. attribute :: GLOBAL_MEM_CACHE_TYPE - .. attribute :: GLOBAL_MEM_SIZE - .. attribute :: IMAGE2D_MAX_HEIGHT - .. attribute :: IMAGE2D_MAX_WIDTH - .. attribute :: IMAGE3D_MAX_DEPTH - .. attribute :: IMAGE3D_MAX_HEIGHT - .. attribute :: IMAGE3D_MAX_WIDTH - .. attribute :: IMAGE_SUPPORT - .. attribute :: LOCAL_MEM_SIZE - .. attribute :: LOCAL_MEM_TYPE - .. attribute :: MAX_CLOCK_FREQUENCY - .. attribute :: MAX_COMPUTE_UNITS - .. attribute :: MAX_CONSTANT_ARGS - .. attribute :: MAX_CONSTANT_BUFFER_SIZE - .. attribute :: MAX_MEM_ALLOC_SIZE - .. attribute :: MAX_PARAMETER_SIZE - .. attribute :: MAX_READ_IMAGE_ARGS - .. attribute :: MAX_SAMPLERS - .. attribute :: MAX_WORK_GROUP_SIZE - .. attribute :: MAX_WORK_ITEM_DIMENSIONS - .. attribute :: MAX_WORK_ITEM_SIZES - .. attribute :: MAX_WRITE_IMAGE_ARGS - .. attribute :: MEM_BASE_ADDR_ALIGN - .. attribute :: MIN_DATA_TYPE_ALIGN_SIZE - .. attribute :: NAME - .. attribute :: PLATFORM - .. attribute :: PREFERRED_VECTOR_WIDTH_CHAR - .. attribute :: PREFERRED_VECTOR_WIDTH_DOUBLE - .. attribute :: PREFERRED_VECTOR_WIDTH_FLOAT - .. attribute :: PREFERRED_VECTOR_WIDTH_INT - .. attribute :: PREFERRED_VECTOR_WIDTH_LONG - .. attribute :: PREFERRED_VECTOR_WIDTH_SHORT - .. attribute :: PROFILE - .. attribute :: PROFILING_TIMER_RESOLUTION - .. attribute :: QUEUE_PROPERTIES - .. attribute :: SINGLE_FP_CONFIG - .. attribute :: TYPE - .. attribute :: VENDOR - .. attribute :: VENDOR_ID - .. attribute :: VERSION - -.. class :: device_local_mem_type - - .. attribute :: GLOBAL - .. attribute :: LOCAL - -.. class :: device_mem_cache_type - - .. attribute :: NONE - .. attribute :: READ_ONLY_CACHE - .. attribute :: READ_WRITE_CACHE - -.. class :: device_type - - .. attribute :: ACCELERATOR - .. attribute :: ALL - .. attribute :: CPU - .. attribute :: DEFAULT - .. attribute :: GPU - -.. class :: event_info - - .. attribute :: COMMAND_EXECUTION_STATUS - .. attribute :: COMMAND_QUEUE - .. attribute :: COMMAND_TYPE - .. attribute :: REFERENCE_COUNT - -.. class :: filter_mode - - .. attribute :: LINEAR - .. attribute :: NEAREST - -.. class :: image_info - - .. attribute :: DEPTH - .. attribute :: ELEMENT_SIZE - .. attribute :: FORMAT - .. attribute :: HEIGHT - .. attribute :: ROW_PITCH - .. attribute :: SLICE_PITCH - .. attribute :: WIDTH - -.. class :: kernel_info - - .. attribute :: CONTEXT - .. attribute :: FUNCTION_NAME - .. attribute :: NUM_ARGS - .. attribute :: PROGRAM - .. attribute :: REFERENCE_COUNT - -.. class :: kernel_work_group_info - - .. attribute :: COMPILE_WORK_GROUP_SIZE - .. attribute :: WORK_GROUP_SIZE - -.. class :: map_flags - - .. attribute :: READ - .. attribute :: WRITE - -.. class :: mem_flags - - .. attribute :: ALLOC_HOST_PTR - .. attribute :: COPY_HOST_PTR - .. attribute :: READ_ONLY - .. attribute :: READ_WRITE - .. attribute :: USE_HOST_PTR - .. attribute :: WRITE_ONLY - -.. class :: mem_info - - .. attribute :: CONTEXT - .. attribute :: FLAGS - .. attribute :: HOST_PTR - .. attribute :: MAP_COUNT - .. attribute :: REFERENCE_COUNT - .. attribute :: SIZE - .. attribute :: TYPE - -.. class :: mem_object_type - - .. attribute :: BUFFER - .. attribute :: IMAGE2D - .. attribute :: IMAGE3D - -.. class :: platform_info - - .. attribute :: EXTENSIONS - .. attribute :: NAME - .. attribute :: PROFILE - .. attribute :: VENDOR - .. attribute :: VERSION - -.. class :: profiling_info - - .. attribute :: END - .. attribute :: QUEUED - .. attribute :: START - .. attribute :: SUBMIT - -.. class :: program_build_info - - .. attribute :: LOG - .. attribute :: OPTIONS - .. attribute :: STATUS - -.. class :: program_info - - .. attribute :: BINARIES - .. attribute :: BINARY_SIZES - .. attribute :: CONTEXT - .. attribute :: DEVICES - .. attribute :: NUM_DEVICES - .. attribute :: REFERENCE_COUNT - .. attribute :: SOURCE - -.. class :: sampler_info - - .. attribute :: ADDRESSING_MODE - .. attribute :: CONTEXT - .. attribute :: FILTER_MODE - .. attribute :: NORMALIZED_COORDS - .. attribute :: REFERENCE_COUNT - diff --git a/doc/source/reference.rst b/doc/source/reference.rst index dcdd024cb4d0f322ae081e783c28d5de49f7d1f2..1d2de8bb7ff95cf7804bac85c298b80007907612 100644 --- a/doc/source/reference.rst +++ b/doc/source/reference.rst @@ -69,7 +69,7 @@ Platforms, Devices and Contexts may be used as attributes on instances of this class to directly query info attributes. - .. method:: get_devices(device_type) + .. method:: get_devices(device_type=device_type.ALL) Return a list of devices matching *device_type*. See :class:`device_type` for values of *device_type*. @@ -90,7 +90,7 @@ Platforms, Devices and Contexts Two instances of this class may be compared using *=="* and *"!="*. -.. class:: Context(devices, properties=[]) +.. class:: Context(devices, properties=None) Create a new context. *properties* is a list of key-value tuples, where each key must be one of :class:`context_properties`. @@ -112,7 +112,7 @@ Platforms, Devices and Contexts Command Queues and Events ------------------------- -.. class:: CommandQueue(context, device=None, properties=[]) +.. class:: CommandQueue(context, device=None, properties=None) Create a new command queue. *properties* is a list of key-value tuples, where each key must be one of :class:`command_queue_properties`. diff --git a/examples/demo.py b/examples/demo.py index f1c2d46f617df275bade5b4bfe491f97d6aa7bca..0fb13624787b26619b9254b9acf919e1c16cbcb9 100644 --- a/examples/demo.py +++ b/examples/demo.py @@ -29,4 +29,4 @@ prg.sum(queue, a.shape, a_buf, b_buf, dest_buf) a_plus_b = numpy.empty_like(a) cl.enqueue_read_buffer(queue, dest_buf, a_plus_b).wait() -print la.norm(a_plus_b - (a+b)) +print la.norm(a_plus_b - (a+b)), la.norm(a_plus_b) diff --git a/src/wrapper/wrap_cl.cpp b/src/wrapper/wrap_cl.cpp index 9905d6906a0e58c1c817ac6f82668870cb554364..89bd5835efc9560e4c969e4f6baa627a536b3259 100644 --- a/src/wrapper/wrap_cl.cpp +++ b/src/wrapper/wrap_cl.cpp @@ -405,7 +405,8 @@ BOOST_PYTHON_MODULE(_cl) typedef platform cls; py::class_<cls, boost::noncopyable>("Platform", py::no_init) .DEF_SIMPLE_METHOD(get_info) - .DEF_SIMPLE_METHOD(get_devices) + .def("get_devices", &cls::get_devices, + py::arg("device_type")=CL_DEVICE_TYPE_ALL) .def(py::self == py::self) .def(py::self != py::self) ; @@ -423,7 +424,7 @@ BOOST_PYTHON_MODULE(_cl) { typedef context cls; py::class_<cls, boost::noncopyable>("Context", - py::init<py::list, py::optional<py::list> >()) + py::init<py::list, py::optional<py::object> >()) .DEF_SIMPLE_METHOD(get_info) .def(py::self == py::self) .def(py::self != py::self) @@ -431,7 +432,7 @@ BOOST_PYTHON_MODULE(_cl) } py::def("create_context_from_type", create_context_from_type, - (py::arg("dev_type"), py::arg("properties")=py::list()), + (py::arg("dev_type"), py::arg("properties")=py::object()), py::return_value_policy<py::manage_new_object>()); { diff --git a/src/wrapper/wrap_cl.hpp b/src/wrapper/wrap_cl.hpp index 262453cf31eb1953f0114cba4ae77a58a2272b7f..905acc571a685ee21cf58940bf1b379e69c2fbab 100644 --- a/src/wrapper/wrap_cl.hpp +++ b/src/wrapper/wrap_cl.hpp @@ -488,26 +488,31 @@ namespace pyopencl // context ------------------------------------------------------------------ #define PYOPENCL_PARSE_CONTEXT_PROPERTIES \ + cl_context_properties *props_ptr = 0; \ std::vector<cl_context_properties> props; \ - \ - PYTHON_FOREACH(prop_tuple, py_properties) \ + \ + if (py_properties.ptr() != Py_None) \ { \ - if (len(prop_tuple) != 2) \ - throw error("Context", CL_INVALID_VALUE, "property tuple must have length 2"); \ - cl_context_properties prop = \ - py::extract<cl_context_properties>(prop_tuple[0]); \ - props.push_back(prop); \ - \ - if (prop == CL_CONTEXT_PLATFORM) \ + PYTHON_FOREACH(prop_tuple, py_properties) \ { \ - py::extract<const platform &> value(prop_tuple[1]); \ - props.push_back( \ - reinterpret_cast<cl_context_properties>(value().data())); \ + if (len(prop_tuple) != 2) \ + throw error("Context", CL_INVALID_VALUE, "property tuple must have length 2"); \ + cl_context_properties prop = \ + py::extract<cl_context_properties>(prop_tuple[0]); \ + props.push_back(prop); \ + \ + if (prop == CL_CONTEXT_PLATFORM) \ + { \ + py::extract<const platform &> value(prop_tuple[1]); \ + props.push_back( \ + reinterpret_cast<cl_context_properties>(value().data())); \ + } \ + else \ + throw error("Context", CL_INVALID_VALUE, "invalid context property"); \ } \ - else \ - throw error("Context", CL_INVALID_VALUE, "invalid context property"); \ - } \ - props.push_back(0); \ + props.push_back(0); \ + props_ptr = &props.front(); \ + } @@ -527,7 +532,7 @@ namespace pyopencl context( py::list py_devices, - py::list py_properties=py::list()) + py::object py_properties=py::object()) { PYOPENCL_PARSE_CONTEXT_PROPERTIES; @@ -540,7 +545,7 @@ namespace pyopencl cl_int status_code; m_context = clCreateContext( - &props.front(), + props_ptr, devices.size(), &devices.front(), 0, 0, &status_code); @@ -621,19 +626,19 @@ namespace pyopencl context *create_context_from_type( cl_device_type dev_type, - py::list py_properties) + py::object py_properties) { PYOPENCL_PARSE_CONTEXT_PROPERTIES; cl_int status_code; cl_context ctx = clCreateContextFromType( - &props.front(), + props_ptr, dev_type, 0, 0, &status_code); PYOPENCL_PRINT_CALL_TRACE("clCreateContextFromType"); if (status_code != CL_SUCCESS) - throw pyopencl::error("Context", status_code); + throw pyopencl::error("clCreateContextFromType", status_code); try {