error* program__kind(clobj_t prog, int *kind) { return c_handle_error([&] { *kind = static_cast<program*>(prog)->kind(); }); }
// Memory Object error* memory_object__release(clobj_t obj) { return c_handle_error([&] { static_cast<memory_object*>(obj)->release(); }); }
error* enqueue_copy_buffer(clobj_t *evt, clobj_t _queue, clobj_t _src, clobj_t _dst, ptrdiff_t byte_count, size_t src_offset, size_t dst_offset, const clobj_t *_wait_for, uint32_t num_wait_for) { auto queue = static_cast<command_queue*>(_queue); auto src = static_cast<memory_object*>(_src); auto dst = static_cast<memory_object*>(_dst); return c_handle_error([&] { if (byte_count < 0) { size_t byte_count_src = 0; size_t byte_count_dst = 0; pyopencl_call_guarded( clGetMemObjectInfo, src, CL_MEM_SIZE, sizeof(byte_count), &byte_count_src, nullptr); pyopencl_call_guarded( clGetMemObjectInfo, src, CL_MEM_SIZE, sizeof(byte_count), &byte_count_dst, nullptr); byte_count = std::min(byte_count_src, byte_count_dst); } const auto wait_for = buf_from_class<event>(_wait_for, num_wait_for); retry_mem_error([&] { pyopencl_call_guarded( clEnqueueCopyBuffer, queue, src, dst, src_offset, dst_offset, byte_count, wait_for, event_out(evt)); }); }); }
error* enqueue_migrate_mem_object_ext(clobj_t *evt, clobj_t _queue, const clobj_t *_mem_obj, uint32_t num_mem_obj, cl_mem_migration_flags_ext flags, const clobj_t *_wait_for, uint32_t num_wait_for) { const auto wait_for = buf_from_class<event>(_wait_for, num_wait_for); const auto mem_obj = buf_from_class<memory_object>(_mem_obj, num_mem_obj); auto queue = static_cast<command_queue*>(_queue); return c_handle_error([&] { #if PYOPENCL_CL_VERSION >= 0x1020 // {{{ get platform cl_device_id dev; pyopencl_call_guarded(clGetCommandQueueInfo, queue, CL_QUEUE_DEVICE, size_arg(dev), nullptr); cl_platform_id plat; pyopencl_call_guarded(clGetDeviceInfo, dev, CL_DEVICE_PLATFORM, size_arg(plat), nullptr); // }}} #endif auto clEnqueueMigrateMemObjectEXT = pyopencl_get_ext_fun(plat, clEnqueueMigrateMemObjectEXT); retry_mem_error([&] { pyopencl_call_guarded(clEnqueueMigrateMemObjectsEXT, queue, mem_obj, flags, wait_for, event_out(evt)); }); }); }
error* platform__get_devices(clobj_t _plat, clobj_t **_devices, uint32_t *num_devices, cl_device_type devtype) { auto plat = static_cast<platform*>(_plat); return c_handle_error([&] { *num_devices = 0; try { pyopencl_call_guarded(clGetDeviceIDs, plat, devtype, 0, nullptr, buf_arg(*num_devices)); } catch (const clerror &e) { if (e.code() != CL_DEVICE_NOT_FOUND) throw e; *num_devices = 0; } if (*num_devices == 0) { *_devices = nullptr; return; } pyopencl_buf<cl_device_id> devices(*num_devices); pyopencl_call_guarded(clGetDeviceIDs, plat, devtype, devices, buf_arg(*num_devices)); *_devices = buf_to_base<device>(devices).release(); }); }
error* image__get_image_info(clobj_t _img, cl_image_info param, generic_info *out) { auto img = static_cast<image*>(_img); return c_handle_error([&] { *out = img->get_image_info(param); }); }
error* platform__unload_compiler(clobj_t plat) { return c_handle_error([&] { pyopencl_call_guarded(clUnloadPlatformCompiler, static_cast<platform*>(plat)); }); }
error* kernel__get_arg_info(clobj_t _knl, cl_uint idx, cl_kernel_arg_info param, generic_info *out) { auto knl = static_cast<kernel*>(_knl); return c_handle_error([&] { *out = knl->get_arg_info(idx, param); }); }
error* kernel__set_arg_null(clobj_t _knl, cl_uint arg_index) { auto knl = static_cast<kernel*>(_knl); return c_handle_error([&] { const cl_mem m = 0; pyopencl_call_guarded(clSetKernelArg, knl, arg_index, size_arg(m)); }); }
error* get_gl_object_info(clobj_t mem, cl_gl_object_type *otype, GLuint *gl_name) { auto globj = static_cast<memory_object*>(mem); return c_handle_error([&] { pyopencl_call_guarded(clGetGLObjectInfo, globj, buf_arg(*otype), buf_arg(*gl_name)); }); }
// Kernel error* create_kernel(clobj_t *knl, clobj_t _prog, const char *name) { auto prog = static_cast<const program*>(_prog); return c_handle_error([&] { *knl = new kernel(pyopencl_call_guarded(clCreateKernel, prog, name), false); }); }
error* program__get_build_info(clobj_t _prog, clobj_t _dev, cl_program_build_info param, generic_info *out) { auto prog = static_cast<program*>(_prog); auto dev = static_cast<device*>(_dev); return c_handle_error([&] { *out = prog->get_build_info(dev, param); }); }
error* kernel__get_work_group_info(clobj_t _knl, cl_kernel_work_group_info param, clobj_t _dev, generic_info *out) { auto knl = static_cast<kernel*>(_knl); auto dev = static_cast<device*>(_dev); return c_handle_error([&] { *out = knl->get_work_group_info(param, dev); }); }
error* kernel__set_arg_buf(clobj_t _knl, cl_uint arg_index, const void *buffer, size_t size) { auto knl = static_cast<kernel*>(_knl); return c_handle_error([&] { pyopencl_call_guarded(clSetKernelArg, knl, arg_index, size_arg(buffer, size)); }); }
error* kernel__set_arg_mem(clobj_t _knl, cl_uint arg_index, clobj_t _mem) { auto knl = static_cast<kernel*>(_knl); auto mem = static_cast<memory_object*>(_mem); return c_handle_error([&] { pyopencl_call_guarded(clSetKernelArg, knl, arg_index, size_arg(mem->data())); }); }
error* kernel__set_arg_sampler(clobj_t _knl, cl_uint arg_index, clobj_t _samp) { auto knl = static_cast<kernel*>(_knl); auto samp = static_cast<sampler*>(_samp); return c_handle_error([&] { pyopencl_call_guarded(clSetKernelArg, knl, arg_index, size_arg(samp->data())); }); }
error* program__all_kernels(clobj_t _prg, clobj_t **_knl, uint32_t *size) { auto prg = static_cast<program*>(_prg); return c_handle_error([&] { auto knls = prg->all_kernels(); *size = knls.len(); *_knl = knls.release(); }); }
error* program__compile(clobj_t _prg, const char *opts, const clobj_t *_devs, size_t num_devs, const clobj_t *_prgs, const char *const *names, size_t num_hdrs) { auto prg = static_cast<program*>(_prg); return c_handle_error([&] { prg->compile(opts, _devs, num_devs, _prgs, names, num_hdrs); }); }
error* create_from_gl_buffer(clobj_t *ptr, clobj_t _ctx, cl_mem_flags flags, GLuint bufobj) { auto ctx = static_cast<context*>(_ctx); return c_handle_error([&] { cl_mem mem = pyopencl_call_guarded(clCreateFromGLBuffer, ctx, flags, bufobj); *ptr = pyopencl_convert_obj(gl_buffer, clReleaseMemObject, mem); }); }
error* create_image_from_desc(clobj_t *img, clobj_t _ctx, cl_mem_flags flags, cl_image_format *fmt, cl_image_desc *desc, void *buf) { auto ctx = static_cast<context*>(_ctx); return c_handle_error([&] { auto mem = pyopencl_call_guarded(clCreateImage, ctx, flags, fmt, desc, buf); *img = new_image(mem, fmt); }); }
error* program__build(clobj_t _prog, const char *options, cl_uint num_devices, const clobj_t *_devices) { auto prog = static_cast<const program*>(_prog); const auto devices = buf_from_class<device>(_devices, num_devices); return c_handle_error([&] { pyopencl_call_guarded(clBuildProgram, prog, devices, options, nullptr, nullptr); }); }
error* kernel__set_arg_svm_pointer(clobj_t _knl, cl_uint arg_index, void *value) { #if PYOPENCL_CL_VERSION >= 0x2000 auto knl = static_cast<kernel*>(_knl); return c_handle_error([&] { pyopencl_call_guarded(clSetKernelArgSVMPointer, knl, arg_index, value); }); #else PYOPENCL_UNSUPPORTED_BEFORE(clSetKernelArgSVMPointer, "CL 2.0") #endif }
error* enqueue_acquire_gl_objects(clobj_t *evt, clobj_t queue, const clobj_t *mem_objects, uint32_t num_mem_objects, const clobj_t *wait_for, uint32_t num_wait_for) { return c_handle_error([&] { enqueue_gl_objects( Acquire, evt, static_cast<command_queue*>(queue), mem_objects, num_mem_objects, wait_for, num_wait_for); }); }
// Program error* create_program_with_source(clobj_t *prog, clobj_t _ctx, const char *_src) { auto ctx = static_cast<context*>(_ctx); return c_handle_error([&] { const auto &src = _src; const size_t length = strlen(src); cl_program result = pyopencl_call_guarded( clCreateProgramWithSource, ctx, len_arg(src), buf_arg(length)); *prog = new_program(result, KND_SOURCE); }); }
error* kernel__get_arg_info(clobj_t _knl, cl_uint idx, cl_kernel_arg_info param, generic_info *out) { #if PYOPENCL_CL_VERSION >= 0x1020 auto knl = static_cast<kernel*>(_knl); return c_handle_error([&] { *out = knl->get_arg_info(idx, param); }); #else PYOPENCL_UNSUPPORTED(clKernelGetArgInfo, "CL 1.1 and below") #endif }
// 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* get_platforms(clobj_t **_platforms, uint32_t *num_platforms) { return c_handle_error([&] { *num_platforms = 0; pyopencl_call_guarded(clGetPlatformIDs, 0, nullptr, buf_arg(*num_platforms)); pyopencl_buf<cl_platform_id> platforms(*num_platforms); pyopencl_call_guarded(clGetPlatformIDs, platforms, buf_arg(*num_platforms)); *_platforms = buf_to_base<platform>(platforms).release(); }); }
error* program__create_with_builtin_kernels(clobj_t *_prg, clobj_t _ctx, const clobj_t *_devs, uint32_t num_devs, const char *names) { const auto devs = buf_from_class<device>(_devs, num_devs); auto ctx = static_cast<context*>(_ctx); return c_handle_error([&] { auto prg = pyopencl_call_guarded(clCreateProgramWithBuiltInKernels, ctx, devs, names); *_prg = new_program(prg); }); }
error* buffer__get_sub_region(clobj_t *_sub_buf, clobj_t _buf, size_t orig, size_t size, cl_mem_flags flags) { #if PYOPENCL_CL_VERSION >= 0x1010 auto buf = static_cast<buffer*>(_buf); return c_handle_error([&] { *_sub_buf = buf->get_sub_region(orig, size, flags); }); #else PYOPENCL_UNSUPPORTED(clCreateSubBuffer, "CL 1.0") #endif }
// Context error* 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*>(props), devices, nullptr, nullptr), false); }); }