We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Invalid CuPy cache problem with different version of CUDAs
When a user update CUDA, caches of CuPy for old CUDA is sometimes incompatible with new one. We need to check CUDA version and to store kernel cache with its information.

@cosmo__ reported this problem on Twitter. Thank you!


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `cupy/cuda/compiler.py`
Content:
```
1 import hashlib
2 import os
3 import re
4 import subprocess
5 import sys
6 import tempfile
7 
8 import filelock
9 import six
10 
11 from cupy.cuda import device
12 from cupy.cuda import function
13 
14 
15 def _get_arch():
16     cc = device.Device().compute_capability
17     return 'sm_%s' % cc
18 
19 
20 class TemporaryDirectory(object):
21 
22     def __enter__(self):
23         self.path = tempfile.mkdtemp()
24         return self.path
25 
26     def __exit__(self, exc_type, exc_value, traceback):
27         if exc_value is not None:
28             return
29 
30         for name in os.listdir(self.path):
31             os.unlink(os.path.join(self.path, name))
32         os.rmdir(self.path)
33 
34 
35 def _run_nvcc(cmd, cwd):
36     try:
37         return subprocess.check_output(cmd, cwd=cwd, stderr=subprocess.STDOUT)
38     except subprocess.CalledProcessError as e:
39         msg = ('`nvcc` command returns non-zero exit status. \n'
40                'command: {0}\n'
41                'return-code: {1}\n'
42                'stdout/stderr: \n'
43                '{2}'.format(e.cmd, e.returncode, e.output))
44         raise RuntimeError(msg)
45     except OSError as e:
46         msg = 'Failed to run `nvcc` command. ' \
47               'Check PATH environment variable: ' \
48               + str(e)
49         raise OSError(msg)
50 
51 
52 def nvcc(source, options=(), arch=None):
53     if not arch:
54         arch = _get_arch()
55     cmd = ['nvcc', '--cubin', '-arch', arch] + list(options)
56 
57     with TemporaryDirectory() as root_dir:
58         path = os.path.join(root_dir, 'kern')
59         cu_path = '%s.cu' % path
60         cubin_path = '%s.cubin' % path
61 
62         with open(cu_path, 'w') as cu_file:
63             cu_file.write(source)
64 
65         cmd.append(cu_path)
66         _run_nvcc(cmd, root_dir)
67 
68         with open(cubin_path, 'rb') as bin_file:
69             return bin_file.read()
70 
71 
72 def preprocess(source, options=()):
73     cmd = ['nvcc', '--preprocess'] + list(options)
74     with TemporaryDirectory() as root_dir:
75         path = os.path.join(root_dir, 'kern')
76         cu_path = '%s.cu' % path
77 
78         with open(cu_path, 'w') as cu_file:
79             cu_file.write(source)
80 
81         cmd.append(cu_path)
82         pp_src = _run_nvcc(cmd, root_dir)
83 
84         if isinstance(pp_src, six.binary_type):
85             pp_src = pp_src.decode('utf-8')
86         return re.sub('(?m)^#.*$', '', pp_src)
87 
88 
89 _default_cache_dir = os.path.expanduser('~/.cupy/kernel_cache')
90 
91 
92 def get_cache_dir():
93     return os.environ.get('CUPY_CACHE_DIR', _default_cache_dir)
94 
95 
96 _empty_file_preprocess_cache = {}
97 
98 
99 def compile_with_cache(source, options=(), arch=None, cache_dir=None):
100     global _empty_file_preprocess_cache
101     if cache_dir is None:
102         cache_dir = get_cache_dir()
103     if arch is None:
104         arch = _get_arch()
105 
106     if 'win32' == sys.platform:
107         options += ('-Xcompiler', '/wd 4819')
108         if sys.maxsize == 9223372036854775807:
109             options += '-m64',
110         elif sys.maxsize == 2147483647:
111             options += '-m32',
112 
113     env = (arch, options)
114     if '#include' in source:
115         pp_src = '%s %s' % (env, preprocess(source, options))
116     else:
117         base = _empty_file_preprocess_cache.get(env, None)
118         if base is None:
119             base = _empty_file_preprocess_cache[env] = preprocess('', options)
120         pp_src = '%s %s %s' % (env, base, source)
121 
122     if isinstance(pp_src, six.text_type):
123         pp_src = pp_src.encode('utf-8')
124     name = '%s.cubin' % hashlib.md5(pp_src).hexdigest()
125 
126     mod = function.Module()
127 
128     if not os.path.exists(cache_dir):
129         os.makedirs(cache_dir)
130 
131     lock_path = os.path.join(cache_dir, 'lock_file.lock')
132 
133     path = os.path.join(cache_dir, name)
134     with filelock.FileLock(lock_path) as lock:
135         if os.path.exists(path):
136             with open(path, 'rb') as file:
137                 cubin = file.read()
138             mod.load(cubin)
139         else:
140             lock.release()
141             cubin = nvcc(source, options, arch)
142             mod.load(cubin)
143             lock.acquire()
144             with open(path, 'wb') as cubin_file:
145                 cubin_file.write(cubin)
146 
147     return mod
148
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/cupy/cuda/compiler.py b/cupy/cuda/compiler.py
--- a/cupy/cuda/compiler.py
+++ b/cupy/cuda/compiler.py
@@ -12,6 +12,18 @@
 from cupy.cuda import function
 
 
+_nvcc_version = None
+
+
+def _get_nvcc_version():
+    global _nvcc_version
+    if _nvcc_version is None:
+        cmd = ['nvcc', '--version']
+        _nvcc_version = _run_nvcc(cmd, '.')
+
+    return _nvcc_version
+
+
 def _get_arch():
     cc = device.Device().compute_capability
     return 'sm_%s' % cc
@@ -110,7 +122,7 @@
         elif sys.maxsize == 2147483647:
             options += '-m32',
 
-    env = (arch, options)
+    env = (arch, options, _get_nvcc_version())
     if '#include' in source:
         pp_src = '%s %s' % (env, preprocess(source, options))
     else:

{"golden_diff": "diff --git a/cupy/cuda/compiler.py b/cupy/cuda/compiler.py\n--- a/cupy/cuda/compiler.py\n+++ b/cupy/cuda/compiler.py\n@@ -12,6 +12,18 @@\n from cupy.cuda import function\n \n \n+_nvcc_version = None\n+\n+\n+def _get_nvcc_version():\n+    global _nvcc_version\n+    if _nvcc_version is None:\n+        cmd = ['nvcc', '--version']\n+        _nvcc_version = _run_nvcc(cmd, '.')\n+\n+    return _nvcc_version\n+\n+\n def _get_arch():\n     cc = device.Device().compute_capability\n     return 'sm_%s' % cc\n@@ -110,7 +122,7 @@\n         elif sys.maxsize == 2147483647:\n             options += '-m32',\n \n-    env = (arch, options)\n+    env = (arch, options, _get_nvcc_version())\n     if '#include' in source:\n         pp_src = '%s %s' % (env, preprocess(source, options))\n     else:\n", "issue": "Invalid CuPy cache problem with different version of CUDAs\nWhen a user update CUDA, caches of CuPy for old CUDA is sometimes incompatible with new one. We need to check CUDA version and to store kernel cache with its information.\n\n@cosmo__ reported this problem on Twitter. Thank you!\n\n", "before_files": [{"content": "import hashlib\nimport os\nimport re\nimport subprocess\nimport sys\nimport tempfile\n\nimport filelock\nimport six\n\nfrom cupy.cuda import device\nfrom cupy.cuda import function\n\n\ndef _get_arch():\n    cc = device.Device().compute_capability\n    return 'sm_%s' % cc\n\n\nclass TemporaryDirectory(object):\n\n    def __enter__(self):\n        self.path = tempfile.mkdtemp()\n        return self.path\n\n    def __exit__(self, exc_type, exc_value, traceback):\n        if exc_value is not None:\n            return\n\n        for name in os.listdir(self.path):\n            os.unlink(os.path.join(self.path, name))\n        os.rmdir(self.path)\n\n\ndef _run_nvcc(cmd, cwd):\n    try:\n        return subprocess.check_output(cmd, cwd=cwd, stderr=subprocess.STDOUT)\n    except subprocess.CalledProcessError as e:\n        msg = ('`nvcc` command returns non-zero exit status. \\n'\n               'command: {0}\\n'\n               'return-code: {1}\\n'\n               'stdout/stderr: \\n'\n               '{2}'.format(e.cmd, e.returncode, e.output))\n        raise RuntimeError(msg)\n    except OSError as e:\n        msg = 'Failed to run `nvcc` command. ' \\\n              'Check PATH environment variable: ' \\\n              + str(e)\n        raise OSError(msg)\n\n\ndef nvcc(source, options=(), arch=None):\n    if not arch:\n        arch = _get_arch()\n    cmd = ['nvcc', '--cubin', '-arch', arch] + list(options)\n\n    with TemporaryDirectory() as root_dir:\n        path = os.path.join(root_dir, 'kern')\n        cu_path = '%s.cu' % path\n        cubin_path = '%s.cubin' % path\n\n        with open(cu_path, 'w') as cu_file:\n            cu_file.write(source)\n\n        cmd.append(cu_path)\n        _run_nvcc(cmd, root_dir)\n\n        with open(cubin_path, 'rb') as bin_file:\n            return bin_file.read()\n\n\ndef preprocess(source, options=()):\n    cmd = ['nvcc', '--preprocess'] + list(options)\n    with TemporaryDirectory() as root_dir:\n        path = os.path.join(root_dir, 'kern')\n        cu_path = '%s.cu' % path\n\n        with open(cu_path, 'w') as cu_file:\n            cu_file.write(source)\n\n        cmd.append(cu_path)\n        pp_src = _run_nvcc(cmd, root_dir)\n\n        if isinstance(pp_src, six.binary_type):\n            pp_src = pp_src.decode('utf-8')\n        return re.sub('(?m)^#.*$', '', pp_src)\n\n\n_default_cache_dir = os.path.expanduser('~/.cupy/kernel_cache')\n\n\ndef get_cache_dir():\n    return os.environ.get('CUPY_CACHE_DIR', _default_cache_dir)\n\n\n_empty_file_preprocess_cache = {}\n\n\ndef compile_with_cache(source, options=(), arch=None, cache_dir=None):\n    global _empty_file_preprocess_cache\n    if cache_dir is None:\n        cache_dir = get_cache_dir()\n    if arch is None:\n        arch = _get_arch()\n\n    if 'win32' == sys.platform:\n        options += ('-Xcompiler', '/wd 4819')\n        if sys.maxsize == 9223372036854775807:\n            options += '-m64',\n        elif sys.maxsize == 2147483647:\n            options += '-m32',\n\n    env = (arch, options)\n    if '#include' in source:\n        pp_src = '%s %s' % (env, preprocess(source, options))\n    else:\n        base = _empty_file_preprocess_cache.get(env, None)\n        if base is None:\n            base = _empty_file_preprocess_cache[env] = preprocess('', options)\n        pp_src = '%s %s %s' % (env, base, source)\n\n    if isinstance(pp_src, six.text_type):\n        pp_src = pp_src.encode('utf-8')\n    name = '%s.cubin' % hashlib.md5(pp_src).hexdigest()\n\n    mod = function.Module()\n\n    if not os.path.exists(cache_dir):\n        os.makedirs(cache_dir)\n\n    lock_path = os.path.join(cache_dir, 'lock_file.lock')\n\n    path = os.path.join(cache_dir, name)\n    with filelock.FileLock(lock_path) as lock:\n        if os.path.exists(path):\n            with open(path, 'rb') as file:\n                cubin = file.read()\n            mod.load(cubin)\n        else:\n            lock.release()\n            cubin = nvcc(source, options, arch)\n            mod.load(cubin)\n            lock.acquire()\n            with open(path, 'wb') as cubin_file:\n                cubin_file.write(cubin)\n\n    return mod\n", "path": "cupy/cuda/compiler.py"}], "after_files": [{"content": "import hashlib\nimport os\nimport re\nimport subprocess\nimport sys\nimport tempfile\n\nimport filelock\nimport six\n\nfrom cupy.cuda import device\nfrom cupy.cuda import function\n\n\n_nvcc_version = None\n\n\ndef _get_nvcc_version():\n    global _nvcc_version\n    if _nvcc_version is None:\n        cmd = ['nvcc', '--version']\n        _nvcc_version = _run_nvcc(cmd, '.')\n\n    return _nvcc_version\n\n\ndef _get_arch():\n    cc = device.Device().compute_capability\n    return 'sm_%s' % cc\n\n\nclass TemporaryDirectory(object):\n\n    def __enter__(self):\n        self.path = tempfile.mkdtemp()\n        return self.path\n\n    def __exit__(self, exc_type, exc_value, traceback):\n        if exc_value is not None:\n            return\n\n        for name in os.listdir(self.path):\n            os.unlink(os.path.join(self.path, name))\n        os.rmdir(self.path)\n\n\ndef _run_nvcc(cmd, cwd):\n    try:\n        return subprocess.check_output(cmd, cwd=cwd, stderr=subprocess.STDOUT)\n    except subprocess.CalledProcessError as e:\n        msg = ('`nvcc` command returns non-zero exit status. \\n'\n               'command: {0}\\n'\n               'return-code: {1}\\n'\n               'stdout/stderr: \\n'\n               '{2}'.format(e.cmd, e.returncode, e.output))\n        raise RuntimeError(msg)\n    except OSError as e:\n        msg = 'Failed to run `nvcc` command. ' \\\n              'Check PATH environment variable: ' \\\n              + str(e)\n        raise OSError(msg)\n\n\ndef nvcc(source, options=(), arch=None):\n    if not arch:\n        arch = _get_arch()\n    cmd = ['nvcc', '--cubin', '-arch', arch] + list(options)\n\n    with TemporaryDirectory() as root_dir:\n        path = os.path.join(root_dir, 'kern')\n        cu_path = '%s.cu' % path\n        cubin_path = '%s.cubin' % path\n\n        with open(cu_path, 'w') as cu_file:\n            cu_file.write(source)\n\n        cmd.append(cu_path)\n        _run_nvcc(cmd, root_dir)\n\n        with open(cubin_path, 'rb') as bin_file:\n            return bin_file.read()\n\n\ndef preprocess(source, options=()):\n    cmd = ['nvcc', '--preprocess'] + list(options)\n    with TemporaryDirectory() as root_dir:\n        path = os.path.join(root_dir, 'kern')\n        cu_path = '%s.cu' % path\n\n        with open(cu_path, 'w') as cu_file:\n            cu_file.write(source)\n\n        cmd.append(cu_path)\n        pp_src = _run_nvcc(cmd, root_dir)\n\n        if isinstance(pp_src, six.binary_type):\n            pp_src = pp_src.decode('utf-8')\n        return re.sub('(?m)^#.*$', '', pp_src)\n\n\n_default_cache_dir = os.path.expanduser('~/.cupy/kernel_cache')\n\n\ndef get_cache_dir():\n    return os.environ.get('CUPY_CACHE_DIR', _default_cache_dir)\n\n\n_empty_file_preprocess_cache = {}\n\n\ndef compile_with_cache(source, options=(), arch=None, cache_dir=None):\n    global _empty_file_preprocess_cache\n    if cache_dir is None:\n        cache_dir = get_cache_dir()\n    if arch is None:\n        arch = _get_arch()\n\n    if 'win32' == sys.platform:\n        options += ('-Xcompiler', '/wd 4819')\n        if sys.maxsize == 9223372036854775807:\n            options += '-m64',\n        elif sys.maxsize == 2147483647:\n            options += '-m32',\n\n    env = (arch, options, _get_nvcc_version())\n    if '#include' in source:\n        pp_src = '%s %s' % (env, preprocess(source, options))\n    else:\n        base = _empty_file_preprocess_cache.get(env, None)\n        if base is None:\n            base = _empty_file_preprocess_cache[env] = preprocess('', options)\n        pp_src = '%s %s %s' % (env, base, source)\n\n    if isinstance(pp_src, six.text_type):\n        pp_src = pp_src.encode('utf-8')\n    name = '%s.cubin' % hashlib.md5(pp_src).hexdigest()\n\n    mod = function.Module()\n\n    if not os.path.exists(cache_dir):\n        os.makedirs(cache_dir)\n\n    lock_path = os.path.join(cache_dir, 'lock_file.lock')\n\n    path = os.path.join(cache_dir, name)\n    with filelock.FileLock(lock_path) as lock:\n        if os.path.exists(path):\n            with open(path, 'rb') as file:\n                cubin = file.read()\n            mod.load(cubin)\n        else:\n            lock.release()\n            cubin = nvcc(source, options, arch)\n            mod.load(cubin)\n            lock.acquire()\n            with open(path, 'wb') as cubin_file:\n                cubin_file.write(cubin)\n\n    return mod\n", "path": "cupy/cuda/compiler.py"}]}