diff --git a/pyopencl/c_wrapper/wrap_cl_core.h b/pyopencl/c_wrapper/wrap_cl_core.h index 9292378aed983af8159dc3070458d3afd871df75..b9f5f30c093ce0d1a8c9da932609b3b24af00e8a 100644 --- a/pyopencl/c_wrapper/wrap_cl_core.h +++ b/pyopencl/c_wrapper/wrap_cl_core.h @@ -63,8 +63,11 @@ error *platform__get_devices(clobj_t platform, clobj_t **ptr_devices, uint32_t *num_devices, cl_device_type devtype); error *platform__unload_compiler(clobj_t plat); // Context -error *create_context(clobj_t *ctx, const cl_context_properties *properties, +error *create_context(clobj_t *ctx, const cl_context_properties *props, cl_uint num_devices, const clobj_t *ptr_devices); +error *create_context_from_type(clobj_t *_ctx, + const cl_context_properties *props, + cl_device_type dev_type); error *context__get_supported_image_formats(clobj_t context, cl_mem_flags flags, cl_mem_object_type image_type, generic_info *out); diff --git a/pyopencl/cffi_cl.py b/pyopencl/cffi_cl.py index cf6248e9c1a72f5927e963d7dc562abc14746d95..706fb1bccb2910ae60a2ca444cfb5e079ae30a09 100644 --- a/pyopencl/cffi_cl.py +++ b/pyopencl/cffi_cl.py @@ -487,10 +487,10 @@ class Device(_Common): # {{{ Context def _parse_context_properties(properties): - props = [] if properties is None: return _ffi.NULL + props = [] for prop_tuple in properties: if len(prop_tuple) != 2: raise RuntimeError("property tuple must have length 2", @@ -526,7 +526,7 @@ def _parse_context_properties(properties): raise RuntimeError("invalid context property", status_code.INVALID_VALUE, "Context") props.append(0) - return _ffi.new('cl_context_properties[]', props) + return props class Context(_Common): @@ -536,22 +536,26 @@ class Context(_Common): c_props = _parse_context_properties(properties) status_code = _ffi.new('cl_int*') - # from device list + _ctx = _ffi.new('clobj_t*') if devices is not None: + # from device list if dev_type is not None: raise RuntimeError("one of 'devices' or 'dev_type' " "must be None", status_code.INVALID_VALUE, "Context") - ptr_devices, num_devices = _clobj_list(devices) - ptr_ctx = _ffi.new('clobj_t*') + _devices, num_devices = _clobj_list(devices) # TODO parameter order? (for clobj_list) - _handle_error(_lib.create_context(ptr_ctx, c_props, - num_devices, ptr_devices)) + _handle_error(_lib.create_context(_ctx, c_props, + num_devices, _devices)) - else: # TODO: from dev_type - raise NotImplementedError() + else: + # from device type + if dev_type is None: + dev_type = device_type.DEFAULT + _handle_error(_lib.create_context_from_type(_ctx, c_props, + dev_type)) - self.ptr = ptr_ctx[0] + self.ptr = _ctx[0] # }}} @@ -997,7 +1001,7 @@ def _enqueue_read_buffer(queue, mem, hostbuf, device_offset=0, def _enqueue_write_buffer(queue, mem, hostbuf, device_offset=0, - wait_for=None, is_blocking=True): + wait_for=None, is_blocking=True): c_buf, size, c_ref = _c_buffer_from_obj(hostbuf, retain=True) ptr_event = _ffi.new('clobj_t*') c_wait_for, num_wait_for = _clobj_list(wait_for) @@ -1020,7 +1024,7 @@ def _enqueue_copy_buffer(queue, src, dst, byte_count=-1, src_offset=0, def _enqueue_read_buffer_rect(queue, mem, hostbuf, buffer_origin, host_origin, region, buffer_pitches=None, - host_pitches=None wait_for=None, + host_pitches=None, wait_for=None, is_blocking=True): buffer_origin = tuple(buffer_origin) host_origin = tuple(host_origin) @@ -1053,7 +1057,7 @@ def _enqueue_read_buffer_rect(queue, mem, hostbuf, buffer_origin, def _enqueue_write_buffer_rect(queue, mem, hostbuf, buffer_origin, host_origin, region, buffer_pitches=None, - host_pitches=None wait_for=None, + host_pitches=None, wait_for=None, is_blocking=True): buffer_origin = tuple(buffer_origin) host_origin = tuple(host_origin) @@ -1085,7 +1089,8 @@ def _enqueue_write_buffer_rect(queue, mem, hostbuf, buffer_origin, def _enqueue_copy_buffer_rect(queue, src, dst, src_origin, dst_origin, region, - src_pitches=None, dst_pitches=None wait_for=None): + src_pitches=None, dst_pitches=None, + wait_for=None): src_origin = tuple(src_origin) dst_origin = tuple(dst_origin) region = tuple(region) diff --git a/src/c_wrapper/context.cpp b/src/c_wrapper/context.cpp index 423919e7488166a9e3b575081a62130be568a48b..99d8a530bd43dce2aba956e1f9eed2d8b0ceb4af 100644 --- a/src/c_wrapper/context.cpp +++ b/src/c_wrapper/context.cpp @@ -92,19 +92,35 @@ using namespace pyopencl; // Context error* -create_context(clobj_t *_ctx, const cl_context_properties *properties, +create_context(clobj_t *_ctx, const cl_context_properties *props, cl_uint num_devices, const clobj_t *_devices) { + // TODO debug print properties return c_handle_error([&] { const auto devices = buf_from_class<device>(_devices, num_devices); *_ctx = new context( pyopencl_call_guarded( clCreateContext, - const_cast<cl_context_properties*>(properties), + const_cast<cl_context_properties*>(props), devices, nullptr, nullptr), false); }); } +// Context +error* +create_context_from_type(clobj_t *_ctx, const cl_context_properties *props, + cl_device_type dev_type) +{ + // TODO debug print properties + return c_handle_error([&] { + *_ctx = new context( + pyopencl_call_guarded( + clCreateContextFromType, + const_cast<cl_context_properties*>(props), + dev_type, nullptr, nullptr), false); + }); +} + error* context__get_supported_image_formats(clobj_t _ctx, cl_mem_flags flags, cl_mem_object_type image_type,