From d1c663b0f2e6ba564d999388b050c735947f4f7d Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Sat, 18 Feb 2017 21:55:11 -0600 Subject: [PATCH] Add #ifdefs to allow direct linking to pocl --- src/c_wrapper/command_queue.cpp | 2 +- src/c_wrapper/gl_obj.cpp | 26 +++++++++++++++++++++++++- src/c_wrapper/memory_object.cpp | 2 +- src/c_wrapper/platform.cpp | 2 +- src/c_wrapper/program.cpp | 10 +++++----- src/c_wrapper/svm.cpp | 2 +- 6 files changed, 34 insertions(+), 10 deletions(-) diff --git a/src/c_wrapper/command_queue.cpp b/src/c_wrapper/command_queue.cpp index b8ecef1e..780c495d 100644 --- a/src/c_wrapper/command_queue.cpp +++ b/src/c_wrapper/command_queue.cpp @@ -101,7 +101,7 @@ error* enqueue_barrier_with_wait_list(clobj_t *evt, clobj_t _queue, const clobj_t *_wait_for, uint32_t num_wait_for) { -#if PYOPENCL_CL_VERSION >= 0x1020 +#if PYOPENCL_CL_VERSION >= 0x1020 && !defined(PYOPENCL_LINKED_TO_POCL) auto queue = static_cast(_queue); const auto wait_for = buf_from_class(_wait_for, num_wait_for); return c_handle_error([&] { diff --git a/src/c_wrapper/gl_obj.cpp b/src/c_wrapper/gl_obj.cpp index bd7edf31..bcdb4bf2 100644 --- a/src/c_wrapper/gl_obj.cpp +++ b/src/c_wrapper/gl_obj.cpp @@ -13,6 +13,7 @@ template void print_clobj(std::ostream&, generic_info gl_texture::get_gl_texture_info(cl_gl_texture_info param_name) const { +#if !defined(PYOPENCL_LINKED_TO_POCL) switch (param_name) { case CL_GL_TEXTURE_TARGET: return pyopencl_get_int_info(GLenum, GLTexture, PYOPENCL_CL_CASTABLE_THIS, param_name); @@ -21,6 +22,9 @@ gl_texture::get_gl_texture_info(cl_gl_texture_info param_name) const default: throw clerror("MemoryObject.get_gl_texture_info", CL_INVALID_VALUE); } +#else + throw clerror("GLObject.get_gl_texture_info", CL_INVALID_VALUE, "not supported in pocl"); +#endif } typedef cl_int (CL_API_CALL *clEnqueueGLObjectFunc)(cl_command_queue, cl_uint, @@ -49,7 +53,7 @@ create_from_gl_texture(clobj_t *ptr, clobj_t _ctx, cl_mem_flags flags, GLenum texture_target, GLint miplevel, GLuint texture) { -#if PYOPENCL_CL_VERSION >= 0x1020 +#if PYOPENCL_CL_VERSION >= 0x1020 && !defined(PYOPENCL_LINKED_TO_POCL) auto ctx = static_cast(_ctx); return c_handle_error([&] { cl_mem mem = pyopencl_call_guarded(clCreateFromGLTexture, @@ -65,18 +69,23 @@ error* create_from_gl_buffer(clobj_t *ptr, clobj_t _ctx, cl_mem_flags flags, GLuint bufobj) { +#if !defined(PYOPENCL_LINKED_TO_POCL) auto ctx = static_cast(_ctx); return c_handle_error([&] { cl_mem mem = pyopencl_call_guarded(clCreateFromGLBuffer, ctx, flags, bufobj); *ptr = pyopencl_convert_obj(gl_buffer, clReleaseMemObject, mem); }); +#else + PYOPENCL_UNSUPPORTED(clCreateFromGLBuffer, "POCL") +#endif } error* create_from_gl_renderbuffer(clobj_t *ptr, clobj_t _ctx, cl_mem_flags flags, GLuint bufobj) { +#if !defined(PYOPENCL_LINKED_TO_POCL) auto ctx = static_cast(_ctx); return c_handle_error([&] { cl_mem mem = pyopencl_call_guarded(clCreateFromGLRenderbuffer, @@ -84,6 +93,9 @@ create_from_gl_renderbuffer(clobj_t *ptr, clobj_t _ctx, *ptr = pyopencl_convert_obj(gl_renderbuffer, clReleaseMemObject, mem); }); +#else + PYOPENCL_UNSUPPORTED(clCreateFromGLRenderbuffer, "POCL") +#endif } error* @@ -92,11 +104,15 @@ enqueue_acquire_gl_objects(clobj_t *evt, clobj_t queue, uint32_t num_mem_objects, const clobj_t *wait_for, uint32_t num_wait_for) { +#if !defined(PYOPENCL_LINKED_TO_POCL) return c_handle_error([&] { enqueue_gl_objects( Acquire, evt, static_cast(queue), mem_objects, num_mem_objects, wait_for, num_wait_for); }); +#else + PYOPENCL_UNSUPPORTED(clEnqueueAcquireGLObjects, "POCL") +#endif } error* @@ -105,21 +121,29 @@ enqueue_release_gl_objects(clobj_t *evt, clobj_t queue, uint32_t num_mem_objects, const clobj_t *wait_for, uint32_t num_wait_for) { +#if !defined(PYOPENCL_LINKED_TO_POCL) return c_handle_error([&] { enqueue_gl_objects( Release, evt, static_cast(queue), mem_objects, num_mem_objects, wait_for, num_wait_for); }); +#else + PYOPENCL_UNSUPPORTED(clEnqueueReleaseGLObjects, "POCL") +#endif } error* get_gl_object_info(clobj_t mem, cl_gl_object_type *otype, GLuint *gl_name) { +#if !defined(PYOPENCL_LINKED_TO_POCL) auto globj = static_cast(mem); return c_handle_error([&] { pyopencl_call_guarded(clGetGLObjectInfo, globj, buf_arg(*otype), buf_arg(*gl_name)); }); +#else + PYOPENCL_UNSUPPORTED(clEnqueueReleaseGLObjects, "POCL") +#endif } #endif diff --git a/src/c_wrapper/memory_object.cpp b/src/c_wrapper/memory_object.cpp index 6f1ba321..ef9bfe80 100644 --- a/src/c_wrapper/memory_object.cpp +++ b/src/c_wrapper/memory_object.cpp @@ -102,7 +102,7 @@ enqueue_migrate_mem_objects(clobj_t *evt, clobj_t _queue, cl_mem_migration_flags flags, const clobj_t *_wait_for, uint32_t num_wait_for) { -#if PYOPENCL_CL_VERSION >= 0x1020 +#if PYOPENCL_CL_VERSION >= 0x1020 && !defined(PYOPENCL_LINKED_TO_POCL) const auto wait_for = buf_from_class(_wait_for, num_wait_for); const auto mem_obj = buf_from_class(_mem_obj, num_mem_obj); auto queue = static_cast(_queue); diff --git a/src/c_wrapper/platform.cpp b/src/c_wrapper/platform.cpp index 21a896b2..b39c8117 100644 --- a/src/c_wrapper/platform.cpp +++ b/src/c_wrapper/platform.cpp @@ -98,7 +98,7 @@ platform__get_devices(clobj_t _plat, clobj_t **_devices, error* platform__unload_compiler(clobj_t plat) { -#if PYOPENCL_CL_VERSION >= 0x1020 +#if PYOPENCL_CL_VERSION >= 0x1020 && !defined(PYOPENCL_LINKED_TO_POCL) return c_handle_error([&] { pyopencl_call_guarded(clUnloadPlatformCompiler, static_cast(plat)); diff --git a/src/c_wrapper/program.cpp b/src/c_wrapper/program.cpp index d50d9680..7545cf3b 100644 --- a/src/c_wrapper/program.cpp +++ b/src/c_wrapper/program.cpp @@ -99,7 +99,7 @@ program::get_build_info(const device *dev, cl_program_build_info param) const } } -#if PYOPENCL_CL_VERSION >= 0x1020 +#if PYOPENCL_CL_VERSION >= 0x1020 && !defined(PYOPENCL_LINKED_TO_POCL) void program::compile(const char *opts, const clobj_t *_devs, size_t num_devs, const clobj_t *_prgs, const char *const *names, @@ -143,7 +143,7 @@ create_program_with_source(clobj_t *prog, clobj_t _ctx, const char *_src) error* create_program_with_il(clobj_t *prog, clobj_t _ctx, void *il, size_t length) { -#if PYOPENCL_CL_VERSION >= 0x2010 +#if PYOPENCL_CL_VERSION >= 0x2010 && !defined(PYOPENCL_LINKED_TO_POCL) auto ctx = static_cast(_ctx); return c_handle_error([&] { cl_program result = pyopencl_call_guarded( @@ -209,7 +209,7 @@ program__create_with_builtin_kernels(clobj_t *_prg, clobj_t _ctx, const clobj_t *_devs, uint32_t num_devs, const char *names) { -#if PYOPENCL_CL_VERSION >= 0x1020 +#if PYOPENCL_CL_VERSION >= 0x1020 && !defined(PYOPENCL_LINKED_TO_POCL) const auto devs = buf_from_class(_devs, num_devs); auto ctx = static_cast(_ctx); return c_handle_error([&] { @@ -227,7 +227,7 @@ 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) { -#if PYOPENCL_CL_VERSION >= 0x1020 +#if PYOPENCL_CL_VERSION >= 0x1020 && !defined(PYOPENCL_LINKED_TO_POCL) auto prg = static_cast(_prg); return c_handle_error([&] { prg->compile(opts, _devs, num_devs, _prgs, names, num_hdrs); @@ -242,7 +242,7 @@ program__link(clobj_t *_prg, clobj_t _ctx, const clobj_t *_prgs, size_t num_prgs, const char *opts, const clobj_t *_devs, size_t num_devs) { -#if PYOPENCL_CL_VERSION >= 0x1020 +#if PYOPENCL_CL_VERSION >= 0x1020 && !defined(PYOPENCL_LINKED_TO_POCL) const auto devs = buf_from_class(_devs, num_devs); const auto prgs = buf_from_class(_prgs, num_prgs); auto ctx = static_cast(_ctx); diff --git a/src/c_wrapper/svm.cpp b/src/c_wrapper/svm.cpp index 8452ec99..93a26be3 100644 --- a/src/c_wrapper/svm.cpp +++ b/src/c_wrapper/svm.cpp @@ -158,7 +158,7 @@ enqueue_svm_migrate_mem( cl_mem_migration_flags flags, const clobj_t *_wait_for, uint32_t num_wait_for) { -#if PYOPENCL_CL_VERSION >= 0x2010 +#if PYOPENCL_CL_VERSION >= 0x2010 && !defined(PYOPENCL_LINKED_TO_POCL) const auto wait_for = buf_from_class(_wait_for, num_wait_for); auto queue = static_cast(_queue); return c_handle_retry_mem_error([&] { -- GitLab