diff --git a/doc/make_constants.py b/doc/make_constants.py index d0ebe1189a107fff51c9fbda620c767718386534..d5b444a5e6668ebf5ae863b866c75924e2f212a6 100644 --- a/doc/make_constants.py +++ b/doc/make_constants.py @@ -10,32 +10,5 @@ def doc_class(cls): print ".. This is an automatically generated file. DO NOT EDIT" -for cls in [ - cl.platform_info, - cl.device_type, - cl.device_info, - cl.device_fp_config, - cl.device_mem_cache_type, - cl.device_local_mem_type, - cl.command_queue_properties, - cl.context_info, - cl.context_properties, - cl.command_queue_info, - cl.mem_flags, - cl.channel_order, - cl.mem_object_type, - cl.mem_info, - cl.image_info, - cl.addressing_mode, - cl.filter_mode, - cl.sampler_info, - cl.map_flags, - cl.program_info, - cl.program_build_info, - cl.kernel_info, - cl.kernel_work_group_info, - cl.event_info, - cl.command_execution_status, - cl.profiling_info, - ]: +for cls in cl.CONSTANT_CLASSES: doc_class(cls) diff --git a/doc/source/constants.inc b/doc/source/constants.inc index 9595f681b2dbdcd18d4afcb4da4489290e760adb..63b4211959cd01fa851fb8cbb2e9b3bcaa82318b 100644 --- a/doc/source/constants.inc +++ b/doc/source/constants.inc @@ -1,4 +1,20 @@ .. This is an automatically generated file. DO NOT EDIT +.. class :: platform_info + + .. attribute :: EXTENSIONS + .. attribute :: NAME + .. attribute :: PROFILE + .. attribute :: VENDOR + .. attribute :: VERSION + +.. class :: device_type + + .. attribute :: ACCELERATOR + .. attribute :: ALL + .. attribute :: CPU + .. attribute :: DEFAULT + .. attribute :: GPU + .. class :: device_info .. attribute :: ADDRESS_BITS @@ -35,6 +51,7 @@ .. 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 @@ -50,3 +67,167 @@ .. attribute :: VENDOR_ID .. attribute :: VERSION +.. 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_mem_cache_type + + .. attribute :: NONE + .. attribute :: READ_ONLY_CACHE + .. attribute :: READ_WRITE_CACHE + +.. class :: device_local_mem_type + + .. attribute :: GLOBAL + .. attribute :: LOCAL + +.. class :: command_queue_properties + + .. attribute :: OUT_OF_ORDER_EXEC_MODE_ENABLE + .. attribute :: PROFILING_ENABLE + +.. class :: context_info + + .. attribute :: DEVICES + .. attribute :: PROPERTIES + .. attribute :: REFERENCE_COUNT + +.. class :: context_properties + + .. attribute :: PLATFORM + +.. class :: command_queue_info + + .. attribute :: CONTEXT + .. attribute :: DEVICE + .. attribute :: PROPERTIES + .. attribute :: REFERENCE_COUNT + +.. 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 :: channel_order + + .. attribute :: A + .. attribute :: BGRA + .. attribute :: INTENSITY + .. attribute :: LUMINANCE + .. attribute :: R + .. attribute :: RA + .. attribute :: RG + .. attribute :: RGB + .. attribute :: RGBA + +.. class :: mem_object_type + + .. attribute :: BUFFER + .. attribute :: IMAGE2D + .. attribute :: IMAGE3D + +.. class :: mem_info + + .. attribute :: CONTEXT + .. attribute :: FLAGS + .. attribute :: HOST_PTR + .. attribute :: MAP_COUNT + .. attribute :: REFERENCE_COUNT + .. attribute :: SIZE + .. attribute :: TYPE + +.. class :: image_info + + .. attribute :: DEPTH + .. attribute :: ELEMENT_SIZE + .. attribute :: FORMAT + .. attribute :: HEIGHT + .. attribute :: ROW_PITCH + .. attribute :: SLICE_PITCH + .. attribute :: WIDTH + +.. class :: addressing_mode + + .. attribute :: CLAMP + .. attribute :: CLAMP_TO_EDGE + .. attribute :: NONE + .. attribute :: REPEAT + +.. class :: filter_mode + + .. attribute :: LINEAR + .. attribute :: NEAREST + +.. class :: sampler_info + + .. attribute :: ADDRESSING_MODE + .. attribute :: CONTEXT + .. attribute :: FILTER_MODE + .. attribute :: NORMALIZED_COORDS + .. attribute :: REFERENCE_COUNT + +.. class :: map_flags + + .. attribute :: READ + .. attribute :: WRITE + +.. class :: program_info + + .. attribute :: BINARIES + .. attribute :: BINARY_SIZES + .. attribute :: CONTEXT + .. attribute :: DEVICES + .. attribute :: NUM_DEVICES + .. attribute :: REFERENCE_COUNT + .. attribute :: SOURCE + +.. class :: program_build_info + + .. attribute :: LOG + .. attribute :: OPTIONS + .. attribute :: STATUS + +.. 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 :: event_info + + .. attribute :: COMMAND_EXECUTION_STATUS + .. attribute :: COMMAND_QUEUE + .. attribute :: COMMAND_TYPE + .. attribute :: REFERENCE_COUNT + +.. class :: command_execution_status + + .. attribute :: COMPLETE + .. attribute :: QUEUED + .. attribute :: RUNNING + .. attribute :: SUBMITTED + +.. class :: profiling_info + + .. attribute :: END + .. attribute :: QUEUED + .. attribute :: START + .. attribute :: SUBMIT + diff --git a/doc/source/misc.rst b/doc/source/misc.rst index 2dcb914f9dda73e57ca28877711e8fb61bce37b7..24caa46ce99b342c13f393243e492e2f3b148de1 100644 --- a/doc/source/misc.rst +++ b/doc/source/misc.rst @@ -12,28 +12,6 @@ Version 0.90 * Initial release. -Acknowledgments -=============== - -* Gert Wohlgemuth ported PyCUDA to MacOS X and contributed large parts of - :class:`pycuda.gpuarray.GPUArray`. -* Alexander Mordvintsev contributed fixes for Windows XP. -* Cosmin Stejerean provided multiple patches for PyCUDA's build system. -* Tom Annau contributed an alternative SourceModule compiler cache as well - as Windows build insight. -* Nicholas Tung improved PyCUDA's documentation. -* Jozef Vesely contributed a massively improved random number generator derived from - the RSA Data Security, Inc. MD5 Message Digest Algorithm. -* Chris Heuser provided a test cases for multi-threaded PyCUDA. -* The reduction templating is based on code by Mark Harris at Nvidia. -* Andrew Wagner provided a test case and contributed the port of the - convolution example. The original convolution code is based on an - example provided by Nvidia. -* Hendrik Riedmann contributed the matrix transpose and list selection - examples. -* Peter Berrington contributed a working example for CUDA-OpenGL - interoperability. - Licensing ========= diff --git a/doc/source/reference.rst b/doc/source/reference.rst index 7e1049fe889b5783eaf74d79a886aae53ff62383..6edd506455094f48b6d044caa1809fab36a136be 100644 --- a/doc/source/reference.rst +++ b/doc/source/reference.rst @@ -43,3 +43,260 @@ Constants --------- .. include:: constants.inc + +Platforms, Devices and Contexts +------------------------------- + +.. |comparable| replace:: Two instances of this class may be compared + using *"=="* and *"!="*. +.. |buf-iface| replace:: must implement the Python buffer interface. + (e.g. by being an :class:`numpy.ndarray`) +.. |enqueue-waitfor| replace:: Returns a new :class:`Event`. + +.. function:: get_platforms() + + Return a list of :class:`Platform` instances. + +.. class:: Platform + + .. method:: get_info(param) + + See :class:`platform_info` for values of *param*. + + .. method:: get_devices(device_type) + + Return a list of devices matching *device_type*. + See :class:`device_type` for values of *device_type*. + + |comparable| + +.. class:: Device + + .. method:: get_info(param) + + See :class:`device_info` for values of *param*. + + Two instances of this class may be compared using *=="* and *"!="*. + +.. class:: Context(devices, properties=[]) + + Create a new context. *properties* is a list of key-value + tuples, where each key must be one of :class:`context_properties`. + + .. method:: get_info(param) + + See :class:`context_info` for values of *param*. + + |comparable| + +Command Queues and Events +------------------------- + +.. class:: CommandQueue(context, device, properties=[]) + + Create a new command queue. *properties* is a list of key-value + tuples, where each key must be one of :class:`command_queue_properties`. + + .. method:: get_info(param) + + See :class:`command_queue_info` for values of *param*. + + .. method:: set_property(prop, enable) + + See :class:`command_queue_properties` for possible values of *prop*. + + .. method:: flush() + .. method:: finish() + + |comparable| + +.. class:: Event + + .. method:: get_info(param) + + See :class:`event_info` for values of *param*. + + .. method:: get_profiling_info(param) + + See :class:`profiling_info` for values of *param*. + + |comparable| + +.. function:: wait_for_events(events) +.. function:: enqueue_marker(queue) + + Returns an :class:`Event`. + +.. function:: enqueue_wait_for_events(queue, events) + + Returns an :class:`Event`. + +Memory +------ + +.. class:: MemoryObject + + .. method:: get_info(param) + + See :class:`mem_info` for values of *param*. + + .. method:: get_image_info(param) + + See :class:`image_info` for values of *param*. + + .. method:: release() + + |comparable| + +Buffers +^^^^^^^ + +.. function:: create_buffer(context, flags, size) + + See :class:`mem_flags` for values of *flags*. + Returns a new buffer-type :class:`MemoryObject`. + +.. function:: create_host_buffer(context, flags, buffer) + + Create a buffer :class:`MemoryObject` using host memory. *host_buffer* |buf-iface|. + + See :class:`mem_flags` for values of *flags*. + +.. function:: enqueue_read_buffer(queue, mem, host_buffer, device_offset=0, wait_for=None, is_blocking=False) + + *host_buffer* |buf-iface| + +.. function:: enqueue_write_buffer(queue, mem, host_buffer, device_offset=0, wait_for=None, is_blocking=False) + + *host_buffer* |buf-iface| + +Image Formats +^^^^^^^^^^^^^ + +.. class:: ImageFormat + + .. attribute:: channel_order + + See :class:`channel_order` for possible values. + + .. attribute:: channel_data_type + + See :class:`channel_type` for possible values. + +.. function:: get_supported_image_formats(context, flags, image_type) + + See :class:`mem_flags` for possible values of *flags* + and :class:`mem_object_type` for possible values of *image_type*. + +Images +^^^^^^ + +.. function:: create_image_2d(context, flags, format, width, height, pitch, host_buffer=None) + + See :class:`mem_flags` for possible values of *flags*. + Returns a new image-type :class:`MemoryObject`. + +.. function:: create_image_3d(context, flags, format, width, height, depth, row_pitch, slice_pitch, host_buffer=None) + + See :class:`mem_flags` for possible values of *flags*. + Returns a new image-type :class:`MemoryObject`. + +.. function:: enqueue_read_image(queue, mem, origin, region, row_pitch, slice_pitch, host_buffer, wait_for=None, is_blocking=False) + + |enqueue-waitfor| + +.. function:: enqueue_write_image(queue, mem, origin, region, row_pitch, slice_pitch, host_buffer, wait_for=None, is_blocking=False) + + |enqueue-waitfor| + +.. function:: enqueue_copy_image(queue, src, dest, src_origin, dest_origin, region, wait_for=None) + + |enqueue-waitfor| + +.. function:: enqueue_copy_image_to_buffer(queue, src, dest, origin, region, offset, wait_for=None) + + |enqueue-waitfor| + +.. function:: enqueue_copy_buffer_to_image(queue, src, dest, offset, origin, region, wait_for=None) + + |enqueue-waitfor| + +Mapping Memory into Host Address Space +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. class:: MemoryMap + + .. method:: release(queue=None, wait_for=None) + +.. function:: enqueue_map_buffer(queue, buf, flags, offset, shape, dtype, order, wait_for=None, is_blocking=False) + + |enqueue-waitfor| + *shape*, *dtype*, and *order* have the same meaning + as in :func:`numpy.empty`. + See :class:`map_flags` for possible values of *flags*. + +.. function:: enqueue_map_image(queue, buf, flags, origin, region, shape, dtype, order, wait_for=None, is_blocking=False) + + |enqueue-waitfor| + *shape*, *dtype*, and *order* have the same meaning + as in :func:`numpy.empty`. + See :class:`map_flags` for possible values of *flags*. + +Samplers +^^^^^^^^ + +.. class:: Sampler(context, normalized_coords, addressing_mode, filter_mode) + + See :class:`addressing_mode` and :class:`filter_mode` for possible + argument values. + + .. method:: get_info(param) + + See :class:`sampler_info` for values of *param*. + + |comparable| + +Programs and Kernels +-------------------- + +.. class:: Program + + .. method:: get_info(param) + + See :class:`program_info` for values of *param*. + + .. method:: get_build_info(param, device) + + See :class:`program_build_info` for values of *param*. + + .. method:: build(options, devices=None) + + *options* is a string of compiler flags. + + |comparable| + +.. function:: unload_compiler() +.. function:: create_program_with_source(context, src) +.. function:: create_program_with_binary(context, devices, binaries) + + *binaries* must contain one binary for each entry in *devices*. + +.. class:: Kernel(program, name) + + .. method:: get_info(param) + + See :class:`kernel_info` for values of *param*. + + .. method:: get_work_group_info(param, device) + + See :class:`kernel_work_group_info` for values of *param*. + + |comparable| + +.. function:: enqueue_nd_range_kernel(queue, kernel, global_work_size, local_work_size, global_work_offset=None, wait_for=None) + + |enqueue-waitfor| + +.. function:: enqueue_task(queue, kernel, global_work_offset, wait_for=None) + + |enqueue-waitfor| diff --git a/pyopencl/__init__.py b/pyopencl/__init__.py index 1d55cca587762c5bec1f49f09bcf9d551c23bff4..589f1ae741ef6a9509a239c89042d98a4b1632fd 100644 --- a/pyopencl/__init__.py +++ b/pyopencl/__init__.py @@ -2,4 +2,34 @@ VERSION = (0, 90) VERSION_STATUS = "alpha" VERSION_TEXT = ".".join(str(x) for x in VERSION) + VERSION_STATUS +import pyopencl._cl as _cl from pyopencl._cl import * +import inspect as _inspect + +CONSTANT_CLASSES = [ + getattr(_cl, name) for name in dir(_cl) + if _inspect.isclass(getattr(_cl, name)) + and name[0].islower()] + +def _add_functionality(): + cls_to_info_cls = { + _cl.Platform: _cl.platform_info, + _cl.Device: _cl.device_info, + _cl.Context: _cl.context_info, + _cl.CommandQueue: _cl.command_queue_info, + _cl.Event: _cl.event_info, + _cl.MemoryObject: _cl.mem_info, + _cl.Program: _cl.program_info, + _cl.Kernel: _cl.kernel_info, + } + + def make_getattr(info_cls): + def result(self, name): + return self.get_info(getattr(info_cls, name.upper())) + + return result + + for cls, info_cls in cls_to_info_cls.iteritems(): + cls.__getattr__ = make_getattr(info_cls) + +_add_functionality() diff --git a/setup.py b/setup.py index 8420d2a85bad70573b4e17408c76d1892bfc5f3d..3fc148ba5fa4208876698482f637204140890362 100644 --- a/setup.py +++ b/setup.py @@ -13,6 +13,7 @@ def get_config_schema(): BoostLibraries("thread"), Switch("CL_TRACE", False, "Enable OpenCL API tracing"), + Switch("SHIPPED_CL_HEADERS", False, "Use shipped OpenCL headers"), IncludeDir("CL", []), LibraryDir("CL", []), @@ -48,7 +49,10 @@ def main(): if conf["CL_TRACE"]: EXTRA_DEFINES["CLPP_TRACE_CL"] = 1 - INCLUDE_DIRS = ['src/cpp', 'src/cl'] + conf["BOOST_INC_DIR"] + conf["CL_INC_DIR"] + INCLUDE_DIRS = ['src/cpp'] + conf["BOOST_INC_DIR"] + conf["CL_INC_DIR"] + + if conf["SHIPPED_CL_HEADERS"]: + INCLUDE_DIRS.append('src/cl') import sys diff --git a/src/wrapper/wrap_cl.cpp b/src/wrapper/wrap_cl.cpp index 42764b47412cbf32daa7377628b3e13db3d6639c..57e1313b0c48cfb5a000444156b368784fa66400 100644 --- a/src/wrapper/wrap_cl.cpp +++ b/src/wrapper/wrap_cl.cpp @@ -421,7 +421,7 @@ BOOST_PYTHON_MODULE(_cl) { typedef context cls; py::class_("Context", - py::init()) + py::init >()) .DEF_SIMPLE_METHOD(get_info) .def(py::self == py::self) .def(py::self != py::self) @@ -445,6 +445,7 @@ BOOST_PYTHON_MODULE(_cl) typedef event cls; py::class_("Event", py::no_init) .DEF_SIMPLE_METHOD(get_info) + .DEF_SIMPLE_METHOD(get_profiling_info) .def(py::self == py::self) .def(py::self != py::self) ; @@ -471,13 +472,13 @@ BOOST_PYTHON_MODULE(_cl) py::return_value_policy()); py::def("enqueue_read_buffer", enqueue_read_buffer, - (py::args("cq", "mem", "buffer"), + (py::args("queue", "mem", "host_buffer"), py::arg("device_offset")=0, py::arg("wait_for")=py::object(), py::arg("is_blocking")=false), py::return_value_policy()); py::def("enqueue_write_buffer", enqueue_write_buffer, - (py::args("cq", "mem", "buffer"), + (py::args("queue", "mem", "host_buffer"), py::arg("device_offset")=0, py::arg("wait_for")=py::object(), py::arg("is_blocking")=false), @@ -494,38 +495,38 @@ BOOST_PYTHON_MODULE(_cl) DEF_SIMPLE_FUNCTION(get_supported_image_formats); py::def("create_image_2d", create_image_2D, - (py::args("ctx", "flags", "format", "width", "height", "pitch"), - py::arg("buffer")=py::object()), + (py::args("context", "flags", "format", "width", "height", "pitch"), + py::arg("host_buffer")=py::object()), py::return_value_policy()); py::def("create_image_3d", create_image_3D, - (py::args("ctx", "flags", "format", "width", "height", "depth", + (py::args("context", "flags", "format", "width", "height", "depth", "row_pitch", "slice_pitch"), - py::arg("buffer")=py::object()), + py::arg("host_buffer")=py::object()), py::return_value_policy()); py::def("enqueue_read_image", enqueue_read_image, - (py::args("cq", "mem", "origin", "region", - "row_pitch", "slice_pitch", "buffer"), + (py::args("queue", "mem", "origin", "region", + "row_pitch", "slice_pitch", "host_buffer"), py::arg("wait_for")=py::object(), py::arg("is_blocking")=false), py::return_value_policy()); py::def("enqueue_write_image", enqueue_write_image, - (py::args("cq", "mem", "origin", "region", - "row_pitch", "slice_pitch", "buffer"), + (py::args("queue", "mem", "origin", "region", + "row_pitch", "slice_pitch", "host_buffer"), py::arg("wait_for")=py::object(), py::arg("is_blocking")=false), py::return_value_policy()); py::def("enqueue_copy_image", enqueue_copy_image, - (py::args("cq", "src", "dest", "src_origin", "dest_origin", "region"), + (py::args("queue", "src", "dest", "src_origin", "dest_origin", "region"), py::arg("wait_for")=py::object()), py::return_value_policy()); py::def("enqueue_copy_image_to_buffer", enqueue_copy_image_to_buffer, - (py::args("cq", "src", "dest", "origin", "region", "offset"), + (py::args("queue", "src", "dest", "origin", "region", "offset"), py::arg("wait_for")=py::object()), py::return_value_policy()); py::def("enqueue_copy_buffer_to_image", enqueue_copy_image_to_buffer, - (py::args("cq", "src", "dest", "offset", "origin", "region"), + (py::args("queue", "src", "dest", "offset", "origin", "region"), py::arg("wait_for")=py::object()), py::return_value_policy()); @@ -534,19 +535,19 @@ BOOST_PYTHON_MODULE(_cl) typedef memory_map cls; py::class_("MemoryMap", py::no_init) .def("release", &cls::release, - (py::arg("cq")=0, py::arg("wait_for")=py::object()), + (py::arg("queue")=0, py::arg("wait_for")=py::object()), py::return_value_policy()) ; } py::def("enqueue_map_buffer", enqueue_map_buffer, - (py::args("cq", "buf", "flags", + (py::args("queue", "buf", "flags", "offset", "shape", "dtype", "order"), py::arg("wait_for")=py::object(), py::arg("is_blocking")=false)); py::def("enqueue_map_image", enqueue_map_image, - (py::args("cq", "buf", "flags", + (py::args("queue", "img", "flags", "origin", "region", "shape", "dtype", "order"), py::arg("wait_for")=py::object(), @@ -570,7 +571,8 @@ BOOST_PYTHON_MODULE(_cl) py::class_("Program", py::no_init) .DEF_SIMPLE_METHOD(get_info) .DEF_SIMPLE_METHOD(get_build_info) - .DEF_SIMPLE_METHOD(build) + .def("build", &cls::build, + (py::arg("options"), py::arg("devices")=py::object())) .def(py::self == py::self) .def(py::self != py::self) ; @@ -579,10 +581,10 @@ BOOST_PYTHON_MODULE(_cl) py::def("unload_compiler", clUnloadCompiler); py::def("create_program_with_source", create_program_with_source, - py::args("ctx", "src"), + py::args("context", "src"), py::return_value_policy()); py::def("create_program_with_binary", create_program_with_binary, - py::args("ctx", "devices", "binaries"), + py::args("context", "devices", "binaries"), py::return_value_policy()); { @@ -599,7 +601,7 @@ BOOST_PYTHON_MODULE(_cl) DEF_SIMPLE_FUNCTION(create_kernels_in_program); py::def("enqueue_nd_range_kernel", enqueue_nd_range_kernel, - (py::args("cmd_queue", "kernel"), + (py::args("queue", "kernel"), py::arg("global_work_size"), py::arg("local_work_size"), py::arg("global_work_offset")=py::object(), @@ -607,7 +609,7 @@ BOOST_PYTHON_MODULE(_cl) ), py::return_value_policy()); py::def("enqueue_task", enqueue_task, - (py::args("cmd_queue", "kernel"), + (py::args("queue", "kernel"), py::arg("wait_for")=py::object() ), py::return_value_policy()); diff --git a/src/wrapper/wrap_cl.hpp b/src/wrapper/wrap_cl.hpp index 7d0de09d9bbc76bd52cfb52e432f1988c6f3b1b3..39b3f87e3fd91dc229fcb299a47f3038cfbba662 100644 --- a/src/wrapper/wrap_cl.hpp +++ b/src/wrapper/wrap_cl.hpp @@ -4,7 +4,6 @@ -// TODO: Memory mapping // TODO: GL Interop @@ -119,15 +118,15 @@ #define PYOPENCL_GET_VEC_INFO(WHAT, FIRST_ARG, SECOND_ARG, RES_VEC) \ { \ - cl_uint size; \ + size_t size; \ PYOPENCL_CALL_GUARDED(clGet##WHAT##Info, \ (FIRST_ARG, SECOND_ARG, 0, 0, &size)); \ \ - RES_VEC.resize(size / sizeof(*RES_VEC.data())); \ + RES_VEC.resize(size / sizeof(RES_VEC.front())); \ \ PYOPENCL_CALL_GUARDED(clGet##WHAT##Info, \ (FIRST_ARG, SECOND_ARG, size, \ - RES_VEC.data(), &size)); \ + &RES_VEC.front(), &size)); \ } #define PYOPENCL_GET_STR_INFO(WHAT, FIRST_ARG, SECOND_ARG) \ @@ -139,10 +138,10 @@ std::vector param_value(param_value_size); \ PYOPENCL_CALL_GUARDED(clGet##WHAT##Info, \ (FIRST_ARG, SECOND_ARG, param_value_size, \ - 0, ¶m_value_size)); \ + ¶m_value.front(), ¶m_value_size)); \ \ return py::object( \ - std::string(param_value.data(), param_value_size)); \ + std::string(¶m_value.front(), param_value_size-1)); \ } @@ -340,14 +339,14 @@ namespace pyopencl - py::list get_platforms(cl_platform_info param_name) + py::list get_platforms() { cl_uint num_platforms = 0; PYOPENCL_CALL_GUARDED(clGetPlatformIDs, (0, 0, &num_platforms)); std::vector platforms(num_platforms); PYOPENCL_CALL_GUARDED(clGetPlatformIDs, - (num_platforms, platforms.data(), &num_platforms)); + (num_platforms, &platforms.front(), &num_platforms)); py::list result; BOOST_FOREACH(cl_platform_id pid, platforms) @@ -418,8 +417,8 @@ namespace pyopencl case CL_DEVICE_IMAGE3D_MAX_WIDTH: DEV_GET_INT_INF(size_t); case CL_DEVICE_IMAGE3D_MAX_HEIGHT: DEV_GET_INT_INF(size_t); case CL_DEVICE_IMAGE3D_MAX_DEPTH: DEV_GET_INT_INF(size_t); - case CL_DEVICE_IMAGE_SUPPORT: DEV_GET_INT_INF(bool); - case CL_DEVICE_MAX_PARAMETER_SIZE: DEV_GET_INT_INF(bool); + case CL_DEVICE_IMAGE_SUPPORT: DEV_GET_INT_INF(cl_bool); + case CL_DEVICE_MAX_PARAMETER_SIZE: DEV_GET_INT_INF(cl_bool); case CL_DEVICE_MAX_SAMPLERS: DEV_GET_INT_INF(cl_uint); case CL_DEVICE_MEM_BASE_ADDR_ALIGN: DEV_GET_INT_INF(cl_uint); case CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE: DEV_GET_INT_INF(cl_uint); @@ -436,9 +435,9 @@ namespace pyopencl case CL_DEVICE_LOCAL_MEM_SIZE: DEV_GET_INT_INF(cl_ulong); case CL_DEVICE_ERROR_CORRECTION_SUPPORT: DEV_GET_INT_INF(cl_bool); case CL_DEVICE_PROFILING_TIMER_RESOLUTION: DEV_GET_INT_INF(size_t); - case CL_DEVICE_ENDIAN_LITTLE: DEV_GET_INT_INF(bool); - case CL_DEVICE_AVAILABLE: DEV_GET_INT_INF(bool); - case CL_DEVICE_COMPILER_AVAILABLE: DEV_GET_INT_INF(bool); + case CL_DEVICE_ENDIAN_LITTLE: DEV_GET_INT_INF(cl_bool); + case CL_DEVICE_AVAILABLE: DEV_GET_INT_INF(cl_bool); + case CL_DEVICE_COMPILER_AVAILABLE: DEV_GET_INT_INF(cl_bool); case CL_DEVICE_EXECUTION_CAPABILITIES: DEV_GET_INT_INF(cl_device_exec_capabilities); case CL_DEVICE_QUEUE_PROPERTIES: DEV_GET_INT_INF(cl_command_queue_properties); @@ -471,7 +470,7 @@ namespace pyopencl std::vector devices(num_devices); PYOPENCL_CALL_GUARDED(clGetDeviceIDs, (m_platform, devtype, - num_devices, devices.data(), &num_devices)); + num_devices, &devices.front(), &num_devices)); py::list result; BOOST_FOREACH(cl_device_id did, devices) @@ -500,7 +499,7 @@ namespace pyopencl context( py::list py_devices, - py::list py_properties) + py::list py_properties=py::list()) { std::vector props; @@ -532,9 +531,9 @@ namespace pyopencl cl_int status_code; m_context = clCreateContext( - props.data(), + &props.front(), devices.size(), - devices.data(), + &devices.front(), 0, 0, &status_code); PYOPENCL_PRINT_CALL_TRACE("clCreateContext"); @@ -1052,7 +1051,7 @@ namespace pyopencl std::vector formats(num_image_formats); PYOPENCL_CALL_GUARDED(clGetSupportedImageFormats, ( ctx.data(), flags, image_type, - num_image_formats, formats.data(), 0)); + num_image_formats, &formats.front(), 0)); return py::list(formats); } @@ -1155,7 +1154,7 @@ namespace pyopencl mem.data(), PYOPENCL_CAST_BOOL(is_blocking), origin, region, row_pitch, slice_pitch, buf, - num_events_in_wait_list, event_wait_list.data(), &evt + num_events_in_wait_list, &event_wait_list.front(), &evt )); PYOPENCL_RETURN_NEW_EVENT(evt); } @@ -1189,7 +1188,7 @@ namespace pyopencl mem.data(), PYOPENCL_CAST_BOOL(is_blocking), origin, region, row_pitch, slice_pitch, buf, - num_events_in_wait_list, event_wait_list.data(), &evt + num_events_in_wait_list, &event_wait_list.front(), &evt )); PYOPENCL_RETURN_NEW_EVENT(evt); } @@ -1216,7 +1215,7 @@ namespace pyopencl PYOPENCL_CALL_GUARDED(clEnqueueCopyImage, ( cq.data(), src.data(), dest.data(), src_origin, dest_origin, region, - num_events_in_wait_list, event_wait_list.data(), &evt + num_events_in_wait_list, &event_wait_list.front(), &evt )); PYOPENCL_RETURN_NEW_EVENT(evt); } @@ -1242,7 +1241,7 @@ namespace pyopencl PYOPENCL_CALL_GUARDED(clEnqueueCopyImageToBuffer, ( cq.data(), src.data(), dest.data(), origin, region, offset, - num_events_in_wait_list, event_wait_list.data(), &evt + num_events_in_wait_list, &event_wait_list.front(), &evt )); PYOPENCL_RETURN_NEW_EVENT(evt); } @@ -1268,7 +1267,7 @@ namespace pyopencl PYOPENCL_CALL_GUARDED(clEnqueueCopyBufferToImage, ( cq.data(), src.data(), dest.data(), offset, origin, region, - num_events_in_wait_list, event_wait_list.data(), &evt + num_events_in_wait_list, &event_wait_list.front(), &evt )); PYOPENCL_RETURN_NEW_EVENT(evt); } @@ -1307,7 +1306,7 @@ namespace pyopencl cl_event evt; PYOPENCL_CALL_GUARDED(clEnqueueUnmapMemObject, ( cq->data(), m_mem.data(), m_ptr, - num_events_in_wait_list, event_wait_list.data(), &evt + num_events_in_wait_list, &event_wait_list.front(), &evt )); m_valid = false; @@ -1323,7 +1322,7 @@ namespace pyopencl command_queue &cq, memory_object &buf, cl_map_flags flags, - cl_map_flags offset, + size_t offset, py::object py_shape, py::object dtype, py::object order_py, py::object py_wait_for, bool is_blocking @@ -1344,7 +1343,7 @@ namespace pyopencl cq.data(), buf.data(), PYOPENCL_CAST_BOOL(is_blocking), flags, offset, PyArray_NBYTES(result.get()), - num_events_in_wait_list, event_wait_list.data(), &evt, + num_events_in_wait_list, &event_wait_list.front(), &evt, &status_code); if (status_code != CL_SUCCESS) throw pyopencl::error("clEnqueueMapBuffer", status_code); @@ -1401,7 +1400,7 @@ namespace pyopencl cq.data(), img.data(), PYOPENCL_CAST_BOOL(is_blocking), flags, origin, region, &row_pitch, &slice_pitch, - num_events_in_wait_list, event_wait_list.data(), &evt, + num_events_in_wait_list, &event_wait_list.front(), &evt, &status_code); if (status_code != CL_SUCCESS) throw pyopencl::error("clEnqueueMapImage", status_code); @@ -1564,7 +1563,7 @@ namespace pyopencl PYOPENCL_CALL_GUARDED(clGetProgramInfo, (m_program, param_name, sizes.size()*sizeof(unsigned char *), - result_ptrs.data(), 0)); \ + &result_ptrs.front(), 0)); \ py::list py_result; for (unsigned i = 0; i < sizes.size(); ++i) @@ -1663,12 +1662,12 @@ namespace pyopencl std::vector binaries; std::vector sizes; - size_t num_devices = len(py_devices); + int num_devices = len(py_devices); if (len(py_binaries) != num_devices) throw error("create_program_with_binary", CL_INVALID_VALUE, "device and binary counts don't match"); - for (size_t i = 0; i < num_devices; ++i) + for (int i = 0; i < num_devices; ++i) { devices.push_back( py::extract(py_devices[i])().data()); @@ -1686,7 +1685,7 @@ namespace pyopencl cl_int status_code; cl_program result = clCreateProgramWithBinary( ctx.data(), num_devices, - devices.data(), sizes.data(), binaries.data(), + &devices.front(), &sizes.front(), &binaries.front(), /*binary_status*/ 0, &status_code); PYOPENCL_PRINT_CALL_TRACE("clCreateProrgramWithBinary"); if (status_code != CL_SUCCESS) @@ -1847,7 +1846,7 @@ namespace pyopencl std::vector kernels; PYOPENCL_CALL_GUARDED(clCreateKernelsInProgram, ( - pgm.data(), num_kernels, kernels.data(), &num_kernels)); + pgm.data(), num_kernels, &kernels.front(), &num_kernels)); BOOST_FOREACH(cl_kernel knl, kernels) result.append(handle_from_new_ptr(new kernel(knl, true))); @@ -1884,7 +1883,7 @@ namespace pyopencl COPY_PY_LIST(size_t, local_work_size); - local_work_size_ptr = local_work_size.data(); + local_work_size_ptr = &local_work_size.front(); } size_t *global_work_offset_ptr = 0; @@ -1897,7 +1896,7 @@ namespace pyopencl COPY_PY_LIST(size_t, global_work_offset); - global_work_offset_ptr = global_work_offset.data(); + global_work_offset_ptr = &global_work_offset.front(); } cl_event evt; @@ -1906,9 +1905,9 @@ namespace pyopencl knl.data(), work_dim, global_work_offset_ptr, - global_work_size.data(), + &global_work_size.front(), local_work_size_ptr, - num_events_in_wait_list, event_wait_list.data(), &evt + num_events_in_wait_list, &event_wait_list.front(), &evt )); PYOPENCL_RETURN_NEW_EVENT(evt); @@ -1930,7 +1929,7 @@ namespace pyopencl PYOPENCL_CALL_GUARDED(clEnqueueTask, ( cq.data(), knl.data(), - num_events_in_wait_list, event_wait_list.data(), &evt + num_events_in_wait_list, &event_wait_list.front(), &evt )); PYOPENCL_RETURN_NEW_EVENT(evt); diff --git a/src/wrapper/wrap_helpers.hpp b/src/wrapper/wrap_helpers.hpp index f8fb324c0d7d4cf2d6ac6f497a1e96c5dceb8fa8..3561235b825505b52daf6d3ae0b66c12878fd7e8 100644 --- a/src/wrapper/wrap_helpers.hpp +++ b/src/wrapper/wrap_helpers.hpp @@ -70,7 +70,7 @@ namespace py = boost::python; size_t my_len = len(py_##NAME); \ if (my_len > 3) \ throw error("image copy", CL_INVALID_VALUE, #NAME "has too many components"); \ - for (int i = 0; i < std::min(size_t(3), my_len); ++i) \ + for (size_t i = 0; i < std::min(size_t(3), my_len); ++i) \ NAME[i] = py::extract(py_##NAME[i])(); \ } @@ -80,7 +80,7 @@ namespace py = boost::python; size_t my_len = len(py_##NAME); \ if (my_len > 3) \ throw error("image copy", CL_INVALID_VALUE, #NAME "has too many components"); \ - for (int i = 0; i < std::min(size_t(3), my_len); ++i) \ + for (size_t i = 0; i < std::min(size_t(3), my_len); ++i) \ NAME[i] = py::extract(py_##NAME[i])(); \ }