From fcf0e965f2111574b28a78f09a9b05fd70b29506 Mon Sep 17 00:00:00 2001 From: Paul Kienzle Date: Tue, 5 Nov 2019 17:04:42 -0500 Subject: [PATCH] Rebuild from source if cached version causes BUILD_PROGRAM_FAILURE. Refs #276. --- pyopencl/cache.py | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/pyopencl/cache.py b/pyopencl/cache.py index b6d21f28..f24311f9 100644 --- a/pyopencl/cache.py +++ b/pyopencl/cache.py @@ -474,28 +474,36 @@ def _create_built_program_from_source_cached(ctx, src, options_bytes, def create_built_program_from_source_cached(ctx, src, options_bytes, devices=None, cache_dir=None, include_path=None): try: + was_cached = False + already_built = False if cache_dir is not False: prg, already_built, was_cached = \ _create_built_program_from_source_cached( ctx, src, options_bytes, devices, cache_dir, include_path=include_path) + if was_cached and not already_built: + prg.build(options_bytes, devices) + already_built = True else: prg = _cl._Program(ctx, src) - was_cached = False - already_built = False except Exception as e: from pyopencl import Error - if (isinstance(e, Error) - and e.code == _cl.status_code.BUILD_PROGRAM_FAILURE): # noqa pylint:disable=no-member - # no need to try again + build_program_failure = (isinstance(e, Error) + and e.code == _cl.status_code.BUILD_PROGRAM_FAILURE) # noqa pylint:disable=no-member + + # Mac error on intel CPU driver: can't build from cached version. + # If we get a build_program_failure from the cached version then + # build from source instead, otherwise report the failure. + if build_program_failure and not was_cached: raise - from warnings import warn - from traceback import format_exc - warn("PyOpenCL compiler caching failed with an exception:\n" - "[begin exception]\n%s[end exception]" - % format_exc()) + if not build_program_failure: + from warnings import warn + from traceback import format_exc + warn("PyOpenCL compiler caching failed with an exception:\n" + "[begin exception]\n%s[end exception]" + % format_exc()) prg = _cl._Program(ctx, src) was_cached = False -- GitLab