From 0986571541c52bac641cd757a676eb5789ba36e1 Mon Sep 17 00:00:00 2001
From: Yichao Yu <yyc1992@gmail.com>
Date: Sat, 21 Jun 2014 00:04:57 +0800
Subject: [PATCH] create_sub_devices

---
 pyopencl/c_wrapper/wrap_cl_core.h | 4 ++--
 pyopencl/cffi_cl.py               | 8 +++++++-
 src/c_wrapper/device.cpp          | 4 ++--
 3 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/pyopencl/c_wrapper/wrap_cl_core.h b/pyopencl/c_wrapper/wrap_cl_core.h
index fb4770c0..6aa06a18 100644
--- a/pyopencl/c_wrapper/wrap_cl_core.h
+++ b/pyopencl/c_wrapper/wrap_cl_core.h
@@ -64,8 +64,8 @@ error *platform__get_devices(clobj_t platform, clobj_t **ptr_devices,
 error *platform__unload_compiler(clobj_t plat);
 // Device
 error *device__create_sub_devices(clobj_t _dev, clobj_t **_devs,
-                                  const cl_device_partition_property *props,
-                                  uint32_t *num_devices);
+                                  uint32_t *num_devices,
+                                  const cl_device_partition_property *props);
 // 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 c4172b63..568e61f1 100644
--- a/pyopencl/cffi_cl.py
+++ b/pyopencl/cffi_cl.py
@@ -503,7 +503,13 @@ def get_platforms():
 
 class Device(_Common):
     _id = 'device'
-    # TODO create_sub_devices
+    def create_sub_devices(self, props):
+        props = tuple(props) + (0,)
+        devices = _CArray(_ffi.new('clobj_t**'))
+        _handle_error(_lib.device__create_sub_devices(
+            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
 
 # }}}
diff --git a/src/c_wrapper/device.cpp b/src/c_wrapper/device.cpp
index b4ba4575..06697a3e 100644
--- a/src/c_wrapper/device.cpp
+++ b/src/c_wrapper/device.cpp
@@ -273,8 +273,8 @@ using namespace pyopencl;
 #if PYOPENCL_CL_VERSION >= 0x1020
 error*
 device__create_sub_devices(clobj_t _dev, clobj_t **_devs,
-                           const cl_device_partition_property *props,
-                           uint32_t *num_devices)
+                           uint32_t *num_devices,
+                           const cl_device_partition_property *props)
 {
     auto dev = static_cast<device*>(_dev);
     return c_handle_error([&] {
-- 
GitLab