From 6c8e41c5b1ee1e9444c83dcc75bf234c070f20cf Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Mon, 17 Oct 2011 01:25:24 -0400 Subject: [PATCH] Suppress verbose compiler output unless asked not to. --- pyopencl/__init__.py | 19 +++++++++++++++++-- pyopencl/cache.py | 6 ++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/pyopencl/__init__.py b/pyopencl/__init__.py index 9bb014c2..256d1c14 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 f0f3988b..cb9af2c3 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 -- GitLab