From d46e511f316784ece0f6d2153c0c9b07b054ba4b Mon Sep 17 00:00:00 2001 From: Yichao Yu <yyc1992@gmail.com> Date: Mon, 16 Jun 2014 05:57:55 -0400 Subject: [PATCH] use correct type (unsigned char) for binaries; use implicit cffi cast when calling functions; use list comprehension since it is faster --- pyopencl/c_wrapper/wrap_cl_core.h | 3 ++- pyopencl/cffi_cl.py | 10 +++++----- src/c_wrapper/program.cpp | 5 ++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pyopencl/c_wrapper/wrap_cl_core.h b/pyopencl/c_wrapper/wrap_cl_core.h index 5427fa3c..efd836fd 100644 --- a/pyopencl/c_wrapper/wrap_cl_core.h +++ b/pyopencl/c_wrapper/wrap_cl_core.h @@ -88,7 +88,8 @@ error *create_program_with_source(clobj_t *program, clobj_t context, const char *src); error *create_program_with_binary(clobj_t *program, clobj_t context, cl_uint num_devices, const clobj_t *devices, - char **binaries, size_t *binary_sizes); + const unsigned char **binaries, + size_t *binary_sizes); error *program__build(clobj_t program, const char *options, cl_uint num_devices, const clobj_t *devices); error *program__kind(clobj_t program, int *kind); diff --git a/pyopencl/cffi_cl.py b/pyopencl/cffi_cl.py index e4bd87b7..9138b46e 100644 --- a/pyopencl/cffi_cl.py +++ b/pyopencl/cffi_cl.py @@ -749,14 +749,14 @@ class _Program(_Common): "device and binary counts don't match") ptr_program = _ffi.new('clobj_t*') - ptr_devices = _ffi.new('clobj_t[]', [device.ptr for device in devices]) - ptr_binaries = [_ffi.new('char[]', binary) for binary in binaries] - binary_sizes = _ffi.new('size_t[]', map(len, binaries)) + ptr_devices = [device.ptr for device in devices] + ptr_binaries = [_ffi.new('unsigned char[]', binary) + for binary in binaries] + binary_sizes = [len(b) for b in binaries] - # TODO correct type for binaries _handle_error(_lib.create_program_with_binary( ptr_program, context.ptr, len(ptr_devices), ptr_devices, - _ffi.new('char*[]', ptr_binaries), binary_sizes)) + ptr_binaries, binary_sizes)) self.ptr = ptr_program[0] diff --git a/src/c_wrapper/program.cpp b/src/c_wrapper/program.cpp index 2aa6efe7..2500fd63 100644 --- a/src/c_wrapper/program.cpp +++ b/src/c_wrapper/program.cpp @@ -113,7 +113,7 @@ create_program_with_source(clobj_t *prog, clobj_t _ctx, const char *src) error* create_program_with_binary(clobj_t *prog, clobj_t _ctx, cl_uint num_devices, const clobj_t *devices, - char **binaries, size_t *binary_sizes) + const unsigned char **binaries, size_t *binary_sizes) { auto ctx = static_cast<context*>(_ctx); const auto devs = buf_from_class<device>(devices, num_devices); @@ -121,8 +121,7 @@ create_program_with_binary(clobj_t *prog, clobj_t _ctx, return c_handle_error([&] { cl_program result = pyopencl_call_guarded( clCreateProgramWithBinary, ctx, devs, - binary_sizes, reinterpret_cast<const unsigned char**>( - const_cast<const char**>(binaries)), binary_statuses.get()); + binary_sizes, binaries, binary_statuses.get()); // for (cl_uint i = 0; i < num_devices; ++i) // std::cout << i << ":" << binary_statuses[i] << std::endl; *prog = new_program(result, KND_BINARY); -- GitLab