Skip to content

Commit

Permalink
Context: optional cache_dir param:
Browse files Browse the repository at this point in the history
 If not None it will be default one for all context's programs
  • Loading branch information
PolarNick239 committed Nov 16, 2015
1 parent e58fd6c commit 06b2088
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
9 changes: 6 additions & 3 deletions pyopencl/__init__.py
Expand Up @@ -347,6 +347,9 @@ def build(self, options=[], devices=None, cache_dir=None):
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
Expand Down Expand Up @@ -1208,7 +1211,7 @@ def gl_object_get_gl_object(self):

# {{{ 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:
Expand All @@ -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
Expand Down Expand Up @@ -1334,7 +1337,7 @@ def parse_device(choice):
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

Expand Down
3 changes: 2 additions & 1 deletion pyopencl/cffi_cl.py
Expand Up @@ -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*')

Expand All @@ -665,6 +665,7 @@ def __init__(self, devices=None, properties=None, dev_type=None):
dev_type))

self.ptr = _ctx[0]
self.cache_dir = cache_dir

# }}}

Expand Down

0 comments on commit 06b2088

Please sign in to comment.