From 06b2088dcbeac8d1d77dbb0a6d124260944f6849 Mon Sep 17 00:00:00 2001 From: Nikolay Polyarniy <PolarNick239@gmail.com> Date: Tue, 17 Nov 2015 01:37:03 +0300 Subject: [PATCH] Context: optional cache_dir param: If not None it will be default one for all context's programs --- pyopencl/__init__.py | 9 ++++++--- pyopencl/cffi_cl.py | 3 ++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/pyopencl/__init__.py b/pyopencl/__init__.py index 0c3df5f9..5b84393d 100644 --- a/pyopencl/__init__.py +++ b/pyopencl/__init__.py @@ -347,6 +347,9 @@ class Program(object): elif isinstance(options, six.text_type): options = [options.encode("utf8")] + if cache_dir is None: + cache_dir = self._context.cache_dir + options = (options + _DEFAULT_BUILD_OPTIONS + _DEFAULT_INCLUDE_OPTIONS @@ -1208,7 +1211,7 @@ _add_functionality() # {{{ convenience -def create_some_context(interactive=None, answers=None): +def create_some_context(interactive=None, answers=None, cache_dir=None): import os if answers is None: if "PYOPENCL_CTX" in os.environ: @@ -1219,7 +1222,7 @@ def create_some_context(interactive=None, answers=None): from pyopencl.tools import get_test_platforms_and_devices for plat, devs in get_test_platforms_and_devices(): for dev in devs: - return Context([dev]) + return Context([dev], cache_dir=cache_dir) if answers is not None: pre_provided_answers = answers @@ -1334,7 +1337,7 @@ def create_some_context(interactive=None, answers=None): raise RuntimeError("not all provided choices were used by " "create_some_context. (left over: '%s')" % ":".join(answers)) - return Context(devices) + return Context(devices, cache_dir=cache_dir) _csc = create_some_context diff --git a/pyopencl/cffi_cl.py b/pyopencl/cffi_cl.py index ecb42397..2e6caa61 100644 --- a/pyopencl/cffi_cl.py +++ b/pyopencl/cffi_cl.py @@ -641,7 +641,7 @@ def _parse_context_properties(properties): class Context(_Common): _id = 'context' - def __init__(self, devices=None, properties=None, dev_type=None): + def __init__(self, devices=None, properties=None, dev_type=None, cache_dir=None): c_props = _parse_context_properties(properties) status_code = _ffi.new('cl_int*') @@ -665,6 +665,7 @@ class Context(_Common): dev_type)) self.ptr = _ctx[0] + self.cache_dir = cache_dir # }}} -- GitLab