Skip to content

Commit

Permalink
Allow the caching behaviour to be controlled globally.
Browse files Browse the repository at this point in the history
The kernel compilation cache can be disabled by exporting
$PYCUDA_DISABLE_CACHE and the default cache directory can be
overridden by exporting $PYCUDA_CACHE_DIR.
  • Loading branch information
FreddieWitherden committed Feb 15, 2016
1 parent 08e2c16 commit af5bfec
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
10 changes: 7 additions & 3 deletions doc/source/driver.rst
Expand Up @@ -2029,9 +2029,13 @@ Just-in-time Compilation
`None`, it defaults to the current context's device's compute capability.
If `code` is `None`, it will not be specified.

`cache_dir` gives the directory used for compiler caching. It has a
sensible per-user default. If it is set to `False`, caching is
disabled.
`cache_dir` gives the directory used for compiler caching. If `None`
then `cache_dir` is taken to be :envvar:`PYCUDA_CACHE_DIR` if set or
a sensible per-user default. If passed as `False`, caching is disabled.

If the environment variable :envvar:`PYCUDA_DISABLE_CACHE` is set to
any value then caching is disabled. This preference overrides any
value of `cache_dir` and can be used to disable caching globally.

This class exhibits the same public interface as :class:`pycuda.driver.Module`, but
does not inherit from it.
Expand Down
6 changes: 6 additions & 0 deletions pycuda/compiler.py
Expand Up @@ -214,6 +214,12 @@ def compile(source, nvcc="nvcc", options=None, keep=False,
keep = True
options.extend(["-g", "-G"])

if "PYCUDA_CACHE_DIR" in os.environ and cache_dir is None:
cache_dir = os.environ["PYCUDA_CACHE_DIR"]

if "PYCUDA_DISABLE_CACHE" in os.environ:
cache_dir = False

if cache_dir is None:
from os.path import join
import appdirs
Expand Down

0 comments on commit af5bfec

Please sign in to comment.