diff --git a/contrib/fortran-to-opencl/translate.py b/contrib/fortran-to-opencl/translate.py index 18f8478627fc3b0ff591271b09ea96891fbd4a13..d0355423e10b274ecfc658ed3f1b7c722586bb82 100644 --- a/contrib/fortran-to-opencl/translate.py +++ b/contrib/fortran-to-opencl/translate.py @@ -1344,7 +1344,7 @@ def f2cl(source, free_form=False, strict=True, import pyopencl as cl ctx = cl.create_some_context() cl.Program(ctx, """ - #ifndef cl_khr_fp64 + #if __OPENCL_VERSION__ <= CL_VERSION_1_1 #pragma OPENCL EXTENSION cl_khr_fp64: enable #endif #include <pyopencl-complex.h> diff --git a/pyopencl/_cluda.py b/pyopencl/_cluda.py index f4aaec215c91c920180cc101b3d5c6b7ca055bbd..40b2fad7bcdc8b38c3c580647f28dac8d65f3a40 100644 --- a/pyopencl/_cluda.py +++ b/pyopencl/_cluda.py @@ -50,7 +50,7 @@ CLUDA_PREAMBLE = """ #define GDIM_2 get_num_groups(2) % if double_support: - #ifndef cl_khr_fp64 + #if __OPENCL_VERSION__ <= CL_VERSION_1_1 #pragma OPENCL EXTENSION cl_khr_fp64: enable #endif % endif diff --git a/pyopencl/algorithm.py b/pyopencl/algorithm.py index 72975b79a9a6054d058e693255cf12481cfc8995..286fdbddcd7b58cd41e05143be1f6ca2b124bb08 100644 --- a/pyopencl/algorithm.py +++ b/pyopencl/algorithm.py @@ -558,7 +558,7 @@ class RadixSort(object): _LIST_BUILDER_TEMPLATE = Template("""//CL// % if double_support: - #ifndef cl_khr_fp64 + #if __OPENCL_VERSION__ <= CL_VERSION_1_1 #pragma OPENCL EXTENSION cl_khr_fp64: enable #endif #define PYOPENCL_DEFINE_CDOUBLE diff --git a/pyopencl/clrandom.py b/pyopencl/clrandom.py index f05994eecf5da331ae04ecad8d49cc4545fe9a0b..b8176c4c19bc8aced1f1d596083692f12c628b38 100644 --- a/pyopencl/clrandom.py +++ b/pyopencl/clrandom.py @@ -168,7 +168,7 @@ class RanluxGenerator(object): lines = [] if include_double_pragma and self.support_double: lines.append(""" - #ifndef cl_khr_fp64 + #if __OPENCL_VERSION__ <= CL_VERSION_1_1 #pragma OPENCL EXTENSION cl_khr_fp64: enable #endif """) diff --git a/pyopencl/elementwise.py b/pyopencl/elementwise.py index 2661b35e5a4049a99397df0b786d1c1e4ebef6ad..0291d4bde0e25dfb639b04d866b648e6c3401917 100644 --- a/pyopencl/elementwise.py +++ b/pyopencl/elementwise.py @@ -127,7 +127,7 @@ def get_elwise_kernel_and_types(context, arguments, operation, if arg.dtype in [np.float64, np.complex128]: if not have_double_pragma: pragmas.append(""" - #ifndef cl_khr_fp64 + #if __OPENCL_VERSION__ <= CL_VERSION_1_1 #pragma OPENCL EXTENSION cl_khr_fp64: enable #endif #define PYOPENCL_DEFINE_CDOUBLE @@ -846,7 +846,7 @@ def get_float_binary_func_kernel(context, func_name, x_dtype, y_dtype, if (np.array(0, x_dtype) * np.array(0, y_dtype)).itemsize > 4: arg_type = 'double' preamble = """ - #ifndef cl_khr_fp64 + #if __OPENCL_VERSION__ <= CL_VERSION_1_1 #pragma OPENCL EXTENSION cl_khr_fp64: enable #endif #define PYOPENCL_DEFINE_CDOUBLE @@ -920,7 +920,7 @@ def get_bessel_kernel(context, which_func, out_dtype=np.float64, "z[i] = bessel_%sn(ord_n, x[i])" % which_func, name="bessel_%sn_kernel" % which_func, preamble=""" - #ifndef cl_khr_fp64 + #if __OPENCL_VERSION__ <= CL_VERSION_1_1 #pragma OPENCL EXTENSION cl_khr_fp64: enable #endif #define PYOPENCL_DEFINE_CDOUBLE diff --git a/pyopencl/reduction.py b/pyopencl/reduction.py index 74d9f9641aa6bc445bf2b1198941db1dd9ca7644..99ebbc39e620ebea26fb65ef9778f466a8015296 100644 --- a/pyopencl/reduction.py +++ b/pyopencl/reduction.py @@ -47,7 +47,7 @@ KERNEL = """//CL// #define REDUCE(a, b) (${reduce_expr}) % if double_support: - #ifndef cl_khr_fp64 + #if __OPENCL_VERSION__ <= CL_VERSION_1_1 #pragma OPENCL EXTENSION cl_khr_fp64: enable #endif #define PYOPENCL_DEFINE_CDOUBLE diff --git a/pyopencl/tools.py b/pyopencl/tools.py index 03946779d258d4ed3c47b382fddc1804af3cad27..990838df0ec94f26970794e795473045171044b6 100644 --- a/pyopencl/tools.py +++ b/pyopencl/tools.py @@ -506,7 +506,7 @@ class _CDeclList: if self.saw_double: result = ( """ - #ifndef cl_khr_fp64 + #if __OPENCL_VERSION__ <= CL_VERSION_1_1 #pragma OPENCL EXTENSION cl_khr_fp64: enable #endif #define PYOPENCL_DEFINE_CDOUBLE @@ -523,6 +523,7 @@ else: key=lambda device, name, dtype, context=None: (device, name, _dtype_to_key(dtype), context)) + @_memoize_match_dtype_to_c_struct def match_dtype_to_c_struct(device, name, dtype, context=None): """Return a tuple `(dtype, c_decl)` such that the C struct declaration @@ -674,10 +675,11 @@ def match_dtype_to_c_struct(device, name, dtype, context=None): if _dtype_hashable: _memoize_dtype_to_c_struct = memoize else: - import json as _json + import json as _json # noqa _memoize_dtype_to_c_struct = memoize( key=lambda device, dtype: (device, _dtype_to_key(dtype))) + @_memoize_dtype_to_c_struct def dtype_to_c_struct(device, dtype): matched_dtype, c_decl = match_dtype_to_c_struct(