diff --git a/contrib/fortran-to-opencl/translate.py b/contrib/fortran-to-opencl/translate.py
index d373888a36bec0e27a7a87f745efaaffe43864ac..18f8478627fc3b0ff591271b09ea96891fbd4a13 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 <pyopencl-complex.h>
             """).build()
     return str_mod
diff --git a/pyopencl/_cluda.py b/pyopencl/_cluda.py
index 9fb9ab900d5d313a6e8d2664e27c9c9735d2d9cb..f4aaec215c91c920180cc101b3d5c6b7ca055bbd 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 23d336e6a354ef1947f8179b22870d1386b50bda..72975b79a9a6054d058e693255cf12481cfc8995 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 5636039421e8c7a368145800b9046840f68d792f..f05994eecf5da331ae04ecad8d49cc4545fe9a0b 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 03c37024489a57b70860f71f8d0a99fd1edf7159..2661b35e5a4049a99397df0b786d1c1e4ebef6ad 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 <pyopencl-bessel-%s.cl>
         """ % which_func)
diff --git a/pyopencl/reduction.py b/pyopencl/reduction.py
index 489be1105b2d126fbc2ee0865417c51e25bcf15f..74d9f9641aa6bc445bf2b1198941db1dd9ca7644 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 cd784df84da786b7d8a4982c41df299061ea7e47..4b311e865709bbecb05aa4a79a18eb4213f6837b 100644
--- a/pyopencl/tools.py
+++ b/pyopencl/tools.py
@@ -490,8 +490,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