From ef3ca8e331264980ff44a7c8be060794305d9e4a Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Keck <Jean-Baptiste.Keck@imag.fr> Date: Mon, 19 Nov 2018 20:28:32 +0100 Subject: [PATCH] fixed for old pyopencl implementation --- .../device/codegen/kernels/tests/test_transpose.py | 4 ++-- hysop/backend/device/opencl/__init__.py | 8 ++++++++ hysop/backend/device/opencl/opencl_allocator.py | 5 ++--- hysop/backend/device/opencl/opencl_device.py | 4 ++-- hysop/backend/device/opencl/opencl_kernel_autotuner.py | 4 ++-- 5 files changed, 16 insertions(+), 9 deletions(-) diff --git a/hysop/backend/device/codegen/kernels/tests/test_transpose.py b/hysop/backend/device/codegen/kernels/tests/test_transpose.py index 8ec832c65..f5281606e 100644 --- a/hysop/backend/device/codegen/kernels/tests/test_transpose.py +++ b/hysop/backend/device/codegen/kernels/tests/test_transpose.py @@ -6,7 +6,7 @@ from hysop.deps import np, it from hysop.tools.misc import upper_pow2_or_3, prod from hysop.tools.types import check_instance from hysop.tools.numerics import is_integer -from hysop.backend.device.opencl import cl, clTools +from hysop.backend.device.opencl import cl, cl_api, clTools from hysop.backend.device.codegen.base.test import _test_typegen from hysop.backend.device.codegen.base.variables import dtype_to_ctype from hysop.backend.device.codegen.kernels.transpose import TransposeKernelGenerator @@ -365,7 +365,7 @@ class TestTranspose(object): buffers = (('Tin', Tin_cpu, Tin, in_view), ('Tout', Tout_cpu, Tout, out_view)) good, err_buffers = self._cmp_buffers(buffers,dak,dim) - except cl._cl.RuntimeError as error: + except cl_api.RuntimeError as error: e = error print 'ERROR: ',e good = False diff --git a/hysop/backend/device/opencl/__init__.py b/hysop/backend/device/opencl/__init__.py index 07d478dcd..f0cab9042 100644 --- a/hysop/backend/device/opencl/__init__.py +++ b/hysop/backend/device/opencl/__init__.py @@ -16,6 +16,14 @@ import pyopencl.clrandom import pyopencl.elementwise import pyopencl.scan +try: + # old pyopencl interface using the cffi + from pyopencl import cffi_cl as cl_api +except ImportError: + # new interface using pybind11 + from pyopencl import _cl as cl_api + + from hysop import __DEFAULT_PLATFORM_ID__, __DEFAULT_DEVICE_ID__ from hysop.tools.io_utils import IO from hysop.backend.device import KERNEL_DUMP_FOLDER diff --git a/hysop/backend/device/opencl/opencl_allocator.py b/hysop/backend/device/opencl/opencl_allocator.py index e3137b8bb..17a8d500a 100644 --- a/hysop/backend/device/opencl/opencl_allocator.py +++ b/hysop/backend/device/opencl/opencl_allocator.py @@ -1,7 +1,7 @@ from abc import ABCMeta, abstractmethod from hysop.deps import np -from hysop.backend.device.opencl import cl +from hysop.backend.device.opencl import cl, cl_api from hysop.core.memory.allocator import AllocatorBase from hysop.backend.device.opencl.opencl_buffer import OpenClBuffer @@ -85,8 +85,7 @@ class OpenClImmediateAllocator(OpenClAllocator): buf = OpenClBuffer(context=self.context, mem_flags=self.mem_flags, size=nbytes) try: - from pyopencl._cl import _enqueue_write_buffer - _enqueue_write_buffer( + cl_api._enqueue_write_buffer( self.queue, buf, self._zero[:min(len(self._zero), nbytes)], is_blocking=True) diff --git a/hysop/backend/device/opencl/opencl_device.py b/hysop/backend/device/opencl/opencl_device.py index 6539b6cac..cdd329047 100644 --- a/hysop/backend/device/opencl/opencl_device.py +++ b/hysop/backend/device/opencl/opencl_device.py @@ -2,7 +2,7 @@ import re, fractions from hysop.tools.types import check_instance from hysop import vprint from hysop.deps import np -from hysop.backend.device.opencl import cl +from hysop.backend.device.opencl import cl, cl_api from hysop.constants import DeviceType, CacheType, MemoryType, FpConfig from hysop.tools.units import bytes2str, freq2str, time2str from hysop.backend.device.logical_device import LogicalDevice, UnknownDeviceAttribute @@ -152,7 +152,7 @@ class OpenClDevice(LogicalDevice): if isinstance(val, str): val = val.strip() setattr(self, '_'+attr, val) - except (cl._cl.LogicError, AttributeError): + except (cl_api.LogicError, AttributeError): _not_found += (attr,) setattr(self, '_'+attr, UnknownDeviceAttribute()) except RuntimeError as e: diff --git a/hysop/backend/device/opencl/opencl_kernel_autotuner.py b/hysop/backend/device/opencl/opencl_kernel_autotuner.py index dd9256ff9..c01af580a 100644 --- a/hysop/backend/device/opencl/opencl_kernel_autotuner.py +++ b/hysop/backend/device/opencl/opencl_kernel_autotuner.py @@ -1,7 +1,7 @@ from hysop.tools.types import check_instance from hysop.tools.units import bytes2str from hysop.tools.misc import prod -from hysop.backend.device.opencl import cl +from hysop.backend.device.opencl import cl, cl_api from hysop.backend.device.kernel_autotuner import KernelAutotuner, KernelGenerationError from hysop.backend.device.opencl.opencl_autotunable_kernel import OpenClAutotunableKernel from hysop.backend.device.opencl.opencl_kernel_statistics import OpenClKernelStatistics @@ -145,7 +145,7 @@ class OpenClKernelAutotuner(KernelAutotuner): while(stats.nruns < target_nruns) and (not pruned): try: evt = cl.enqueue_nd_range_kernel(queue, kernel, global_size, local_size) - except cl._cl.RuntimeError: + except cl_api.RuntimeError: raise KernelGenerationError() evt.wait() stats += OpenClKernelStatistics(events=[evt]) -- GitLab