From cfadb46a20d6c3662870d2ba0f3cf00db7f9bf5e Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner <inform@tiker.net> Date: Fri, 2 Jun 2017 20:17:34 -0400 Subject: [PATCH] Disable PyOpenCL compiler cache when platform compiler cache available --- pyopencl/__init__.py | 23 +++++++++++++++++------ pyopencl/characterize/__init__.py | 7 +++++++ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/pyopencl/__init__.py b/pyopencl/__init__.py index 07688d1d..0d912e41 100644 --- a/pyopencl/__init__.py +++ b/pyopencl/__init__.py @@ -324,10 +324,10 @@ class Program(object): knl._source = getattr(self, "_source", None) if self._build_duration_info is not None: - was_cached, what, duration = self._build_duration_info + build_descr, was_cached, duration = self._build_duration_info if duration > 0.2: logger.info("build program: kernel '%s' was part of a " - "lengthy %s (%.2f s)" % (attr, what, duration)) + "lengthy %s (%.2f s)" % (attr, build_descr, duration)) return knl except LogicError: @@ -431,7 +431,16 @@ class Program(object): cache_dir = getattr(self._context, 'cache_dir', None) import os + from pyopencl.characterize import has_platform_compiler_cache + plat_has_cache = has_platform_compiler_cache(self._context.devices[0]) + build_descr = None + if os.environ.get("PYOPENCL_NO_CACHE") and self._prg is None: + build_descr = "uncached source build (cache disabled by user)" + self._prg = _cl._Program(self._context, self._source) + + if plat_has_cache: + build_descr = "platform-cached source build" self._prg = _cl._Program(self._context, self._source) from time import time @@ -441,7 +450,9 @@ class Program(object): if self._prg is not None: # uncached - what = "uncached source build" + if build_descr is None: + build_descr = "uncached source build" + self._build_and_catch_errors( lambda: self._prg.build(options_bytes, devices), options_bytes=options_bytes) @@ -457,15 +468,15 @@ class Program(object): options_bytes=options_bytes, source=self._source) if was_cached: - what = "cache retrieval" + build_descr = "cache retrieval" else: - what = "source build resulting from a binary cache miss" + build_descr = "source build resulting from a binary cache miss" del self._context end_time = time() - self._build_duration_info = (was_cached, what, end_time-start_time) + self._build_duration_info = (build_descr, was_cached, end_time-start_time) return self diff --git a/pyopencl/characterize/__init__.py b/pyopencl/characterize/__init__.py index d0305189..8e5ab73d 100644 --- a/pyopencl/characterize/__init__.py +++ b/pyopencl/characterize/__init__.py @@ -387,3 +387,10 @@ def has_struct_arg_count_bug(dev, ctx=None): return "pocl" return False + + +def has_platform_compiler_cache(dev): + if dev.platform.name == "Portable Computing Language": + return True + + return False -- GitLab