diff --git a/pyopencl/__init__.py b/pyopencl/__init__.py
index 9bb014c2dada4c155b93d7284110a31fbe4c99af..256d1c1437ac91b09f78092ef48130bedc69e40a 100644
--- a/pyopencl/__init__.py
+++ b/pyopencl/__init__.py
@@ -22,6 +22,22 @@ CONSTANT_CLASSES = [
         if _inspect.isclass(getattr(_cl, name))
         and name[0].islower()]
 
+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)
+
+
+
+
 def _add_functionality():
     cls_to_info_cls = {
             _cl.Platform:
@@ -160,8 +176,7 @@ def _add_functionality():
             else:
                 raise RuntimeError("unexpected kind of program")
 
-            from warnings import warn
-            warn("%s succeeded, but resulted in non-empty logs:\n%s"
+            compiler_output("%s succeeded, but resulted in non-empty logs:\n%s"
                     % (build_type, message))
 
         return self
diff --git a/pyopencl/cache.py b/pyopencl/cache.py
index f0f3988b42c2710026252836d0ad3c6b2cac96e4..cb9af2c3646b657071fe886778f6a7eeaf212a18 100644
--- a/pyopencl/cache.py
+++ b/pyopencl/cache.py
@@ -349,8 +349,10 @@ def _create_built_program_from_source_cached(ctx, src, options, devices, cache_d
             if log is not None and log.strip())
 
     if message:
-        from warnings import warn
-        warn("Built kernel retrieved from cache. Original from-source build had warnings:\n"+message)
+        from pyopencl import compiler_output
+        compiler_output(
+                "Built kernel retrieved from cache. Original from-source "
+                "build had warnings:\n"+message)
 
     # {{{ build on the build-needing devices, in one go