From aad2cfb806c6c7b9cad1107add7421dcfbb4de83 Mon Sep 17 00:00:00 2001 From: "gw0 [http://gw.tnode.com/]" Date: Sun, 15 Jun 2014 14:29:36 +0200 Subject: [PATCH] Fix warning for `cl_khr_fp64` in OpenCL 1.2. --- contrib/fortran-to-opencl/translate.py | 2 ++ pyopencl/_cluda.py | 2 ++ pyopencl/algorithm.py | 2 ++ pyopencl/clrandom.py | 6 +++++- pyopencl/elementwise.py | 13 ++++++++++--- pyopencl/reduction.py | 2 ++ pyopencl/tools.py | 8 ++++++-- 7 files changed, 29 insertions(+), 6 deletions(-) diff --git a/contrib/fortran-to-opencl/translate.py b/contrib/fortran-to-opencl/translate.py index d373888a..18f84786 100644 --- a/contrib/fortran-to-opencl/translate.py +++ b/contrib/fortran-to-opencl/translate.py @@ -1344,7 +1344,9 @@ def f2cl(source, free_form=False, strict=True, import pyopencl as cl ctx = cl.create_some_context() cl.Program(ctx, """ + #ifndef cl_khr_fp64 #pragma OPENCL EXTENSION cl_khr_fp64: enable + #endif #include """).build() return str_mod diff --git a/pyopencl/_cluda.py b/pyopencl/_cluda.py index 9fb9ab90..f4aaec21 100644 --- a/pyopencl/_cluda.py +++ b/pyopencl/_cluda.py @@ -50,7 +50,9 @@ CLUDA_PREAMBLE = """ #define GDIM_2 get_num_groups(2) % if double_support: + #ifndef cl_khr_fp64 #pragma OPENCL EXTENSION cl_khr_fp64: enable + #endif % endif """ diff --git a/pyopencl/algorithm.py b/pyopencl/algorithm.py index 23d336e6..72975b79 100644 --- a/pyopencl/algorithm.py +++ b/pyopencl/algorithm.py @@ -558,7 +558,9 @@ class RadixSort(object): _LIST_BUILDER_TEMPLATE = Template("""//CL// % if double_support: + #ifndef cl_khr_fp64 #pragma OPENCL EXTENSION cl_khr_fp64: enable + #endif #define PYOPENCL_DEFINE_CDOUBLE % endif diff --git a/pyopencl/clrandom.py b/pyopencl/clrandom.py index 56360394..f05994ee 100644 --- a/pyopencl/clrandom.py +++ b/pyopencl/clrandom.py @@ -167,7 +167,11 @@ class RanluxGenerator(object): def generate_settings_defines(self, include_double_pragma=True): lines = [] if include_double_pragma and self.support_double: - lines.append("#pragma OPENCL EXTENSION cl_khr_fp64 : enable") + lines.append(""" + #ifndef cl_khr_fp64 + #pragma OPENCL EXTENSION cl_khr_fp64: enable + #endif + """) lines.append("#define RANLUXCL_LUX %d" % self.luxury) diff --git a/pyopencl/elementwise.py b/pyopencl/elementwise.py index 03c37024..2661b35e 100644 --- a/pyopencl/elementwise.py +++ b/pyopencl/elementwise.py @@ -126,9 +126,12 @@ def get_elwise_kernel_and_types(context, arguments, operation, for arg in parsed_args: if arg.dtype in [np.float64, np.complex128]: if not have_double_pragma: - pragmas.append( - "#pragma OPENCL EXTENSION cl_khr_fp64: enable\n" - "#define PYOPENCL_DEFINE_CDOUBLE\n") + pragmas.append(""" + #ifndef cl_khr_fp64 + #pragma OPENCL EXTENSION cl_khr_fp64: enable + #endif + #define PYOPENCL_DEFINE_CDOUBLE + """) have_double_pragma = True if arg.dtype.kind == 'c': if not have_complex_include: @@ -843,7 +846,9 @@ 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 #pragma OPENCL EXTENSION cl_khr_fp64: enable + #endif #define PYOPENCL_DEFINE_CDOUBLE """ + preamble else: @@ -915,7 +920,9 @@ 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 #pragma OPENCL EXTENSION cl_khr_fp64: enable + #endif #define PYOPENCL_DEFINE_CDOUBLE #include """ % which_func) diff --git a/pyopencl/reduction.py b/pyopencl/reduction.py index 489be110..74d9f964 100644 --- a/pyopencl/reduction.py +++ b/pyopencl/reduction.py @@ -47,7 +47,9 @@ KERNEL = """//CL// #define REDUCE(a, b) (${reduce_expr}) % if double_support: + #ifndef cl_khr_fp64 #pragma OPENCL EXTENSION cl_khr_fp64: enable + #endif #define PYOPENCL_DEFINE_CDOUBLE % endif diff --git a/pyopencl/tools.py b/pyopencl/tools.py index ceaa2350..03946779 100644 --- a/pyopencl/tools.py +++ b/pyopencl/tools.py @@ -505,8 +505,12 @@ class _CDeclList: if self.saw_double: result = ( - "#pragma OPENCL EXTENSION cl_khr_fp64: enable\n" - "#define PYOPENCL_DEFINE_CDOUBLE\n" + """ + #ifndef cl_khr_fp64 + #pragma OPENCL EXTENSION cl_khr_fp64: enable + #endif + #define PYOPENCL_DEFINE_CDOUBLE + """ + result) return result -- GitLab