diff --git a/pyopencl/__init__.py b/pyopencl/__init__.py
index 46e5266e0ea3a79a630d8e17f9c2932649299a4b..15ec5b1bc4f0980dc8fb611f21945a92cd184372 100644
--- a/pyopencl/__init__.py
+++ b/pyopencl/__init__.py
@@ -221,9 +221,27 @@ if _cl.have_gl():
         pass
 
 
+# {{{ diagnostics
+
 class _ErrorRecord(Record):
     pass
 
+class CompilerWarning(UserWarning):
+    pass
+
+
+def compiler_output(text):
+    import os
+    from warnings import warn
+    if int(os.environ.get("PYOPENCL_COMPILER_OUTPUT", "0")):
+        warn(text, CompilerWarning)
+    else:
+        warn("Non-empty compiler output encountered. Set the "
+                "environment variable PYOPENCL_COMPILER_OUTPUT=1 "
+                "to see more.", CompilerWarning)
+
+# }}}
+
 
 # {{{ find pyopencl shipped source code