diff --git a/pyopencl/c_wrapper/wrap_cl_core.h b/pyopencl/c_wrapper/wrap_cl_core.h index 6aa06a18442172ba8b814621a141f1991dff89d4..9dc2921b608d0e0f418c11148d2348119d0e4f52 100644 --- a/pyopencl/c_wrapper/wrap_cl_core.h +++ b/pyopencl/c_wrapper/wrap_cl_core.h @@ -66,6 +66,9 @@ error *platform__unload_compiler(clobj_t plat); error *device__create_sub_devices(clobj_t _dev, clobj_t **_devs, uint32_t *num_devices, const cl_device_partition_property *props); +error *device__create_sub_devices_ext(clobj_t _dev, clobj_t **_devs, + uint32_t *num_devices, + const cl_device_partition_property_ext*); // Context error *create_context(clobj_t *ctx, const cl_context_properties *props, cl_uint num_devices, const clobj_t *ptr_devices); diff --git a/pyopencl/cffi_cl.py b/pyopencl/cffi_cl.py index 568e61f1683f36291b72a6779f90a5233ffef178..32a37354695c30ef174c01c7707ea5ec6cf30291 100644 --- a/pyopencl/cffi_cl.py +++ b/pyopencl/cffi_cl.py @@ -510,7 +510,14 @@ class Device(_Common): self.ptr, devices.ptr, devices.size, props)) return [Device._create(devices.ptr[0][i]) for i in xrange(devices.size[0])] - # TODO create_sub_devices_ext + def create_sub_devices_ext(self, props): + props = (tuple(props) + + (device_partition_property_ext.PROPERTIES_LIST_END,)) + devices = _CArray(_ffi.new('clobj_t**')) + _handle_error(_lib.device__create_sub_devices_ext( + self.ptr, devices.ptr, devices.size, props)) + return [Device._create(devices.ptr[0][i]) + for i in xrange(devices.size[0])] # }}} diff --git a/src/c_wrapper/device.cpp b/src/c_wrapper/device.cpp index 06697a3e59744717c929197c000975b1bfc4acac..49e27e2cddc58106ec25ac65a5381de00426b26e 100644 --- a/src/c_wrapper/device.cpp +++ b/src/c_wrapper/device.cpp @@ -253,14 +253,36 @@ device::get_info(cl_uint param_name) const PYOPENCL_USE_RESULT pyopencl_buf<clobj_t> device::create_sub_devices(const cl_device_partition_property *props) { - // TODO debug print cl_device_partition_property + // TODO debug print props cl_uint num_devices; pyopencl_call_guarded(clCreateSubDevices, this, props, 0, nullptr, buf_arg(num_devices)); pyopencl_buf<cl_device_id> devices(num_devices); pyopencl_call_guarded(clCreateSubDevices, this, props, devices, buf_arg(num_devices)); - return buf_to_base<device>(devices); + return buf_to_base<device>(devices, true, device::REF_CL_1_2); +} +#endif +#if defined(cl_ext_device_fission) && defined(PYOPENCL_USE_DEVICE_FISSION) +PYOPENCL_USE_RESULT pyopencl_buf<clobj_t> +device::create_sub_devices_ext(const cl_device_partition_property_ext *props) +{ +#if PYOPENCL_CL_VERSION >= 0x1020 + cl_platform_id plat; + pyopencl_call_guarded(clGetDeviceInfo, this, CL_DEVICE_PLATFORM, + size_arg(plat), nullptr); +#endif + auto clCreateSubDevicesEXT = + pyopencl_get_ext_fun(plat, clCreateSubDevicesEXT); + + // TODO debug print props + cl_uint num_devices; + pyopencl_call_guarded(clCreateSubDevicesEXT, this, props, 0, nullptr, + buf_arg(num_devices)); + pyopencl_buf<cl_device_id> devices(num_devices); + pyopencl_call_guarded(clCreateSubDevicesEXT, this, props, devices, + buf_arg(num_devices)); + return buf_to_base<device>(devices, true, device::REF_FISSION_EXT); } #endif @@ -284,3 +306,18 @@ device__create_sub_devices(clobj_t _dev, clobj_t **_devs, }); } #endif + +#if defined(cl_ext_device_fission) && defined(PYOPENCL_USE_DEVICE_FISSION) +error* +device__create_sub_devices_ext(clobj_t _dev, clobj_t **_devs, + uint32_t *num_devices, + const cl_device_partition_property_ext *props) +{ + auto dev = static_cast<device*>(_dev); + return c_handle_error([&] { + auto devs = dev->create_sub_devices_ext(props); + *num_devices = (uint32_t)devs.len(); + *_devs = devs.release(); + }); +} +#endif diff --git a/src/c_wrapper/device.h b/src/c_wrapper/device.h index c3a622fa58d3285b8328eb27db6b903e45f17ff7..274e972d9e2f3dba031e3fcb89e7cd240daf7ae7 100644 --- a/src/c_wrapper/device.h +++ b/src/c_wrapper/device.h @@ -19,9 +19,7 @@ public: enum reference_type_t { REF_NOT_OWNABLE, REF_FISSION_EXT, -#if PYOPENCL_CL_VERSION >= 0x1020 REF_CL_1_2, -#endif }; private: @@ -70,41 +68,8 @@ public: #endif #if defined(cl_ext_device_fission) && defined(PYOPENCL_USE_DEVICE_FISSION) - // py::list create_sub_devices_ext(py::object py_properties) - // { - // std::vector<cl_device_partition_property_ext> properties; - - // #if PYOPENCL_CL_VERSION >= 0x1020 - // cl_platform_id plat; - // PYOPENCL_CALL_GUARDED(clGetDeviceInfo, (m_device, CL_DEVICE_PLATFORM, - // sizeof(plat), &plat, nullptr)); - // #endif - - // PYOPENCL_GET_EXT_FUN(plat, clCreateSubDevicesEXT, create_sub_dev); - - // COPY_PY_LIST(cl_device_partition_property_ext, properties); - // properties.push_back(CL_PROPERTIES_LIST_END_EXT); - - // cl_device_partition_property_ext *props_ptr - // = properties.empty( ) ? nullptr : &properties.front(); - - // cl_uint num_entries; - // PYOPENCL_CALL_GUARDED(create_sub_dev, - // (m_device, props_ptr, 0, nullptr, &num_entries)); - - // std::vector<cl_device_id> result; - // result.resize(num_entries); - - // PYOPENCL_CALL_GUARDED(create_sub_dev, - // (m_device, props_ptr, num_entries, &result.front(), nullptr)); - - // py::list py_result; - // BOOST_FOREACH(cl_device_id did, result) - // py_result.append(handle_from_new_ptr( - // new pyopencl::device(did, /*retain*/true, - // device::REF_FISSION_EXT))); - // return py_result; - // } + PYOPENCL_USE_RESULT pyopencl_buf<clobj_t> + create_sub_devices_ext(const cl_device_partition_property_ext *props); #endif };