We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Add Windows support in cuTENSOR download tool
https://github.com/cupy/cupy/pull/4560#issuecomment-764422155

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `cupyx/tools/install_library.py`
Content:
```
1 #!/usr/bin/env python
2 
3 """
4 CUDA Library Installer
5 
6 Installs the latest CUDA library supported by CuPy.
7 """
8 
9 # This script will also be used as a standalone script when building wheels.
10 # Keep the script runnable without CuPy dependency.
11 
12 import argparse
13 import json
14 import os
15 import platform
16 import shutil
17 import sys
18 import tempfile
19 import urllib.request
20 
21 
22 _cudnn_records = []
23 _cutensor_records = []
24 library_records = {}
25 
26 
27 def _make_cudnn_url(public_version, filename):
28     # https://developer.download.nvidia.com/compute/redist/cudnn/v8.0.2/cudnn-11.0-linux-x64-v8.0.2.39.tgz
29     return (
30         'https://developer.download.nvidia.com/compute/redist/cudnn' +
31         '/v{}/{}'.format(public_version, filename))
32 
33 
34 def _make_cudnn_record(
35         cuda_version, public_version, filename_linux, filename_windows):
36     major_version = public_version.split('.')[0]
37     return {
38         'cuda': cuda_version,
39         'cudnn': public_version,
40         'assets': {
41             'Linux': {
42                 'url': _make_cudnn_url(public_version, filename_linux),
43                 'filename': 'libcudnn.so.{}'.format(public_version),
44             },
45             'Windows': {
46                 'url': _make_cudnn_url(public_version, filename_windows),
47                 'filename': 'cudnn64_{}.dll'.format(major_version),
48             },
49         }
50     }
51 
52 
53 # Latest cuDNN versions: https://developer.nvidia.com/rdp/cudnn-download
54 _cudnn_records.append(_make_cudnn_record(
55     '11.1', '8.1.0',
56     'cudnn-11.2-linux-x64-v8.1.0.77.tgz',
57     'cudnn-11.2-windows-x64-v8.1.0.77.zip'))
58 _cudnn_records.append(_make_cudnn_record(
59     '11.0', '8.1.0',
60     'cudnn-11.2-linux-x64-v8.1.0.77.tgz',
61     'cudnn-11.2-windows-x64-v8.1.0.77.zip'))
62 _cudnn_records.append(_make_cudnn_record(
63     '10.2', '8.1.0',
64     'cudnn-10.2-linux-x64-v8.1.0.77.tgz',
65     'cudnn-10.2-windows10-x64-v8.1.0.77.zip'))
66 _cudnn_records.append(_make_cudnn_record(
67     '10.1', '8.0.5',
68     'cudnn-10.1-linux-x64-v8.0.5.39.tgz',
69     'cudnn-10.1-windows10-x64-v8.0.5.39.zip'))
70 _cudnn_records.append(_make_cudnn_record(
71     '10.0', '7.6.5',
72     'cudnn-10.0-linux-x64-v7.6.5.32.tgz',
73     'cudnn-10.0-windows10-x64-v7.6.5.32.zip'))
74 _cudnn_records.append(_make_cudnn_record(
75     '9.2', '7.6.5',
76     'cudnn-9.2-linux-x64-v7.6.5.32.tgz',
77     'cudnn-9.2-windows10-x64-v7.6.5.32.zip'))
78 library_records['cudnn'] = _cudnn_records
79 
80 
81 def _make_cutensor_url(public_version, filename):
82     # https://developer.download.nvidia.com/compute/cutensor/1.2.2/local_installers/libcutensor-linux-x86_64-1.2.2.5.tar.gz
83     return (
84         'https://developer.download.nvidia.com/compute/cutensor/' +
85         '{}/local_installers/{}'.format(public_version, filename))
86 
87 
88 def _make_cutensor_record(
89         cuda_version, public_version, filename_linux, filename_windows=''):
90     # TODO(leofang): Support Windows when a public link becomes available
91     return {
92         'cuda': cuda_version,
93         'cutensor': public_version,
94         'assets': {
95             'Linux': {
96                 'url': _make_cutensor_url(public_version, filename_linux),
97                 'filename': 'libcutensor.so.{}'.format(public_version),
98             },
99         }
100     }
101 
102 
103 _cutensor_records.append(_make_cutensor_record(
104     '11.1', '1.2.2',
105     'libcutensor-linux-x86_64-1.2.2.5.tar.gz', ''))
106 _cutensor_records.append(_make_cutensor_record(
107     '11.0', '1.2.2',
108     'libcutensor-linux-x86_64-1.2.2.5.tar.gz', ''))
109 _cutensor_records.append(_make_cutensor_record(
110     '10.2', '1.2.2',
111     'libcutensor-linux-x86_64-1.2.2.5.tar.gz', ''))
112 _cutensor_records.append(_make_cutensor_record(
113     '10.1', '1.2.2',
114     'libcutensor-linux-x86_64-1.2.2.5.tar.gz', ''))
115 library_records['cutensor'] = _cutensor_records
116 
117 
118 def install_lib(cuda, prefix, library):
119     record = None
120     lib_records = library_records
121     for record in lib_records[library]:
122         if record['cuda'] == cuda:
123             break
124     else:
125         raise RuntimeError('''
126 The CUDA version specified is not supported.
127 Should be one of {}.'''.format(str([x['cuda'] for x in lib_records[library]])))
128     if prefix is None:
129         prefix = os.path.expanduser('~/.cupy/cuda_lib')
130     destination = calculate_destination(prefix, cuda, library, record[library])
131 
132     if os.path.exists(destination):
133         raise RuntimeError('''
134 The destination directory {} already exists.
135 Remove the directory first if you want to reinstall.'''.format(destination))
136     asset = record['assets'][platform.system()]
137 
138     print('Installing {} {} for CUDA {} to: {}'.format(
139         library, record[library], record['cuda'], destination))
140 
141     url = asset['url']
142     print('Downloading {}...'.format(url))
143     with tempfile.TemporaryDirectory() as tmpdir:
144         with open(os.path.join(tmpdir, os.path.basename(url)), 'wb') as f:
145             with urllib.request.urlopen(url) as response:
146                 f.write(response.read())
147         print('Extracting...')
148         shutil.unpack_archive(f.name, tmpdir)
149         print('Installing...')
150         if library == 'cudnn':
151             shutil.move(os.path.join(tmpdir, 'cuda'), destination)
152         elif library == 'cutensor':
153             include = os.path.join(destination, 'include')
154             lib = os.path.join(destination, 'lib64')
155             shutil.move(os.path.join(tmpdir, 'libcutensor/include'), include)
156             if cuda.startswith('11'):
157                 cuda = '11'
158             shutil.move(os.path.join(tmpdir, 'libcutensor/lib', cuda), lib)
159         print('Cleaning up...')
160     print('Done!')
161 
162 
163 def calculate_destination(prefix, cuda, lib, lib_ver):
164     """Calculates the installation directory.
165 
166     ~/.cupy/cuda_lib/{cuda_version}/{library_name}/{library_version}
167     """
168     return os.path.join(prefix, cuda, lib, lib_ver)
169 
170 
171 def main(args):
172     parser = argparse.ArgumentParser()
173 
174     # TODO(kmaehashi): support NCCL
175     parser.add_argument('--library',
176                         choices=['cudnn', 'cutensor'],
177                         required=True,
178                         help='Library to install')
179     parser.add_argument('--cuda', type=str, required=True,
180                         help='CUDA version')
181     parser.add_argument('--prefix', type=str, default=None,
182                         help='Install destination')
183     parser.add_argument('--action', choices=['install', 'dump'],
184                         default='install',
185                         help='Action to perform')
186     params = parser.parse_args(args)
187 
188     if params.prefix is not None:
189         params.prefix = os.path.abspath(params.prefix)
190 
191     if params.library == 'cudnn':
192         if params.action == 'install':
193             install_lib(params.cuda, params.prefix, 'cudnn')
194         elif params.action == 'dump':
195             print(json.dumps(_cudnn_records, indent=4))
196         else:
197             assert False
198     elif params.library == 'cutensor':
199         if params.action == 'install':
200             install_lib(params.cuda, params.prefix, 'cutensor')
201         elif params.action == 'dump':
202             print(json.dumps(_cutensor_records, indent=4))
203         else:
204             assert False
205     else:
206         assert False
207 
208 
209 if __name__ == '__main__':
210     main(sys.argv[1:])
211
```
--- 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/cupyx/tools/install_library.py b/cupyx/tools/install_library.py
--- a/cupyx/tools/install_library.py
+++ b/cupyx/tools/install_library.py
@@ -86,8 +86,7 @@
 
 
 def _make_cutensor_record(
-        cuda_version, public_version, filename_linux, filename_windows=''):
-    # TODO(leofang): Support Windows when a public link becomes available
+        cuda_version, public_version, filename_linux, filename_windows):
     return {
         'cuda': cuda_version,
         'cutensor': public_version,
@@ -96,22 +95,30 @@
                 'url': _make_cutensor_url(public_version, filename_linux),
                 'filename': 'libcutensor.so.{}'.format(public_version),
             },
+            'Windows': {
+                'url': _make_cutensor_url(public_version, filename_windows),
+                'filename': 'cutensor.dll',
+            },
         }
     }
 
 
 _cutensor_records.append(_make_cutensor_record(
     '11.1', '1.2.2',
-    'libcutensor-linux-x86_64-1.2.2.5.tar.gz', ''))
+    'libcutensor-linux-x86_64-1.2.2.5.tar.gz',
+    'libcutensor-windows-x86_64-1.2.2.5.zip'))
 _cutensor_records.append(_make_cutensor_record(
     '11.0', '1.2.2',
-    'libcutensor-linux-x86_64-1.2.2.5.tar.gz', ''))
+    'libcutensor-linux-x86_64-1.2.2.5.tar.gz',
+    'libcutensor-windows-x86_64-1.2.2.5.zip'))
 _cutensor_records.append(_make_cutensor_record(
     '10.2', '1.2.2',
-    'libcutensor-linux-x86_64-1.2.2.5.tar.gz', ''))
+    'libcutensor-linux-x86_64-1.2.2.5.tar.gz',
+    'libcutensor-windows-x86_64-1.2.2.5.zip'))
 _cutensor_records.append(_make_cutensor_record(
     '10.1', '1.2.2',
-    'libcutensor-linux-x86_64-1.2.2.5.tar.gz', ''))
+    'libcutensor-linux-x86_64-1.2.2.5.tar.gz',
+    'libcutensor-windows-x86_64-1.2.2.5.zip'))
 library_records['cutensor'] = _cutensor_records

{"golden_diff": "diff --git a/cupyx/tools/install_library.py b/cupyx/tools/install_library.py\n--- a/cupyx/tools/install_library.py\n+++ b/cupyx/tools/install_library.py\n@@ -86,8 +86,7 @@\n \n \n def _make_cutensor_record(\n-        cuda_version, public_version, filename_linux, filename_windows=''):\n-    # TODO(leofang): Support Windows when a public link becomes available\n+        cuda_version, public_version, filename_linux, filename_windows):\n     return {\n         'cuda': cuda_version,\n         'cutensor': public_version,\n@@ -96,22 +95,30 @@\n                 'url': _make_cutensor_url(public_version, filename_linux),\n                 'filename': 'libcutensor.so.{}'.format(public_version),\n             },\n+            'Windows': {\n+                'url': _make_cutensor_url(public_version, filename_windows),\n+                'filename': 'cutensor.dll',\n+            },\n         }\n     }\n \n \n _cutensor_records.append(_make_cutensor_record(\n     '11.1', '1.2.2',\n-    'libcutensor-linux-x86_64-1.2.2.5.tar.gz', ''))\n+    'libcutensor-linux-x86_64-1.2.2.5.tar.gz',\n+    'libcutensor-windows-x86_64-1.2.2.5.zip'))\n _cutensor_records.append(_make_cutensor_record(\n     '11.0', '1.2.2',\n-    'libcutensor-linux-x86_64-1.2.2.5.tar.gz', ''))\n+    'libcutensor-linux-x86_64-1.2.2.5.tar.gz',\n+    'libcutensor-windows-x86_64-1.2.2.5.zip'))\n _cutensor_records.append(_make_cutensor_record(\n     '10.2', '1.2.2',\n-    'libcutensor-linux-x86_64-1.2.2.5.tar.gz', ''))\n+    'libcutensor-linux-x86_64-1.2.2.5.tar.gz',\n+    'libcutensor-windows-x86_64-1.2.2.5.zip'))\n _cutensor_records.append(_make_cutensor_record(\n     '10.1', '1.2.2',\n-    'libcutensor-linux-x86_64-1.2.2.5.tar.gz', ''))\n+    'libcutensor-linux-x86_64-1.2.2.5.tar.gz',\n+    'libcutensor-windows-x86_64-1.2.2.5.zip'))\n library_records['cutensor'] = _cutensor_records\n", "issue": "Add Windows support in cuTENSOR download tool\nhttps://github.com/cupy/cupy/pull/4560#issuecomment-764422155\n", "before_files": [{"content": "#!/usr/bin/env python\n\n\"\"\"\nCUDA Library Installer\n\nInstalls the latest CUDA library supported by CuPy.\n\"\"\"\n\n# This script will also be used as a standalone script when building wheels.\n# Keep the script runnable without CuPy dependency.\n\nimport argparse\nimport json\nimport os\nimport platform\nimport shutil\nimport sys\nimport tempfile\nimport urllib.request\n\n\n_cudnn_records = []\n_cutensor_records = []\nlibrary_records = {}\n\n\ndef _make_cudnn_url(public_version, filename):\n    # https://developer.download.nvidia.com/compute/redist/cudnn/v8.0.2/cudnn-11.0-linux-x64-v8.0.2.39.tgz\n    return (\n        'https://developer.download.nvidia.com/compute/redist/cudnn' +\n        '/v{}/{}'.format(public_version, filename))\n\n\ndef _make_cudnn_record(\n        cuda_version, public_version, filename_linux, filename_windows):\n    major_version = public_version.split('.')[0]\n    return {\n        'cuda': cuda_version,\n        'cudnn': public_version,\n        'assets': {\n            'Linux': {\n                'url': _make_cudnn_url(public_version, filename_linux),\n                'filename': 'libcudnn.so.{}'.format(public_version),\n            },\n            'Windows': {\n                'url': _make_cudnn_url(public_version, filename_windows),\n                'filename': 'cudnn64_{}.dll'.format(major_version),\n            },\n        }\n    }\n\n\n# Latest cuDNN versions: https://developer.nvidia.com/rdp/cudnn-download\n_cudnn_records.append(_make_cudnn_record(\n    '11.1', '8.1.0',\n    'cudnn-11.2-linux-x64-v8.1.0.77.tgz',\n    'cudnn-11.2-windows-x64-v8.1.0.77.zip'))\n_cudnn_records.append(_make_cudnn_record(\n    '11.0', '8.1.0',\n    'cudnn-11.2-linux-x64-v8.1.0.77.tgz',\n    'cudnn-11.2-windows-x64-v8.1.0.77.zip'))\n_cudnn_records.append(_make_cudnn_record(\n    '10.2', '8.1.0',\n    'cudnn-10.2-linux-x64-v8.1.0.77.tgz',\n    'cudnn-10.2-windows10-x64-v8.1.0.77.zip'))\n_cudnn_records.append(_make_cudnn_record(\n    '10.1', '8.0.5',\n    'cudnn-10.1-linux-x64-v8.0.5.39.tgz',\n    'cudnn-10.1-windows10-x64-v8.0.5.39.zip'))\n_cudnn_records.append(_make_cudnn_record(\n    '10.0', '7.6.5',\n    'cudnn-10.0-linux-x64-v7.6.5.32.tgz',\n    'cudnn-10.0-windows10-x64-v7.6.5.32.zip'))\n_cudnn_records.append(_make_cudnn_record(\n    '9.2', '7.6.5',\n    'cudnn-9.2-linux-x64-v7.6.5.32.tgz',\n    'cudnn-9.2-windows10-x64-v7.6.5.32.zip'))\nlibrary_records['cudnn'] = _cudnn_records\n\n\ndef _make_cutensor_url(public_version, filename):\n    # https://developer.download.nvidia.com/compute/cutensor/1.2.2/local_installers/libcutensor-linux-x86_64-1.2.2.5.tar.gz\n    return (\n        'https://developer.download.nvidia.com/compute/cutensor/' +\n        '{}/local_installers/{}'.format(public_version, filename))\n\n\ndef _make_cutensor_record(\n        cuda_version, public_version, filename_linux, filename_windows=''):\n    # TODO(leofang): Support Windows when a public link becomes available\n    return {\n        'cuda': cuda_version,\n        'cutensor': public_version,\n        'assets': {\n            'Linux': {\n                'url': _make_cutensor_url(public_version, filename_linux),\n                'filename': 'libcutensor.so.{}'.format(public_version),\n            },\n        }\n    }\n\n\n_cutensor_records.append(_make_cutensor_record(\n    '11.1', '1.2.2',\n    'libcutensor-linux-x86_64-1.2.2.5.tar.gz', ''))\n_cutensor_records.append(_make_cutensor_record(\n    '11.0', '1.2.2',\n    'libcutensor-linux-x86_64-1.2.2.5.tar.gz', ''))\n_cutensor_records.append(_make_cutensor_record(\n    '10.2', '1.2.2',\n    'libcutensor-linux-x86_64-1.2.2.5.tar.gz', ''))\n_cutensor_records.append(_make_cutensor_record(\n    '10.1', '1.2.2',\n    'libcutensor-linux-x86_64-1.2.2.5.tar.gz', ''))\nlibrary_records['cutensor'] = _cutensor_records\n\n\ndef install_lib(cuda, prefix, library):\n    record = None\n    lib_records = library_records\n    for record in lib_records[library]:\n        if record['cuda'] == cuda:\n            break\n    else:\n        raise RuntimeError('''\nThe CUDA version specified is not supported.\nShould be one of {}.'''.format(str([x['cuda'] for x in lib_records[library]])))\n    if prefix is None:\n        prefix = os.path.expanduser('~/.cupy/cuda_lib')\n    destination = calculate_destination(prefix, cuda, library, record[library])\n\n    if os.path.exists(destination):\n        raise RuntimeError('''\nThe destination directory {} already exists.\nRemove the directory first if you want to reinstall.'''.format(destination))\n    asset = record['assets'][platform.system()]\n\n    print('Installing {} {} for CUDA {} to: {}'.format(\n        library, record[library], record['cuda'], destination))\n\n    url = asset['url']\n    print('Downloading {}...'.format(url))\n    with tempfile.TemporaryDirectory() as tmpdir:\n        with open(os.path.join(tmpdir, os.path.basename(url)), 'wb') as f:\n            with urllib.request.urlopen(url) as response:\n                f.write(response.read())\n        print('Extracting...')\n        shutil.unpack_archive(f.name, tmpdir)\n        print('Installing...')\n        if library == 'cudnn':\n            shutil.move(os.path.join(tmpdir, 'cuda'), destination)\n        elif library == 'cutensor':\n            include = os.path.join(destination, 'include')\n            lib = os.path.join(destination, 'lib64')\n            shutil.move(os.path.join(tmpdir, 'libcutensor/include'), include)\n            if cuda.startswith('11'):\n                cuda = '11'\n            shutil.move(os.path.join(tmpdir, 'libcutensor/lib', cuda), lib)\n        print('Cleaning up...')\n    print('Done!')\n\n\ndef calculate_destination(prefix, cuda, lib, lib_ver):\n    \"\"\"Calculates the installation directory.\n\n    ~/.cupy/cuda_lib/{cuda_version}/{library_name}/{library_version}\n    \"\"\"\n    return os.path.join(prefix, cuda, lib, lib_ver)\n\n\ndef main(args):\n    parser = argparse.ArgumentParser()\n\n    # TODO(kmaehashi): support NCCL\n    parser.add_argument('--library',\n                        choices=['cudnn', 'cutensor'],\n                        required=True,\n                        help='Library to install')\n    parser.add_argument('--cuda', type=str, required=True,\n                        help='CUDA version')\n    parser.add_argument('--prefix', type=str, default=None,\n                        help='Install destination')\n    parser.add_argument('--action', choices=['install', 'dump'],\n                        default='install',\n                        help='Action to perform')\n    params = parser.parse_args(args)\n\n    if params.prefix is not None:\n        params.prefix = os.path.abspath(params.prefix)\n\n    if params.library == 'cudnn':\n        if params.action == 'install':\n            install_lib(params.cuda, params.prefix, 'cudnn')\n        elif params.action == 'dump':\n            print(json.dumps(_cudnn_records, indent=4))\n        else:\n            assert False\n    elif params.library == 'cutensor':\n        if params.action == 'install':\n            install_lib(params.cuda, params.prefix, 'cutensor')\n        elif params.action == 'dump':\n            print(json.dumps(_cutensor_records, indent=4))\n        else:\n            assert False\n    else:\n        assert False\n\n\nif __name__ == '__main__':\n    main(sys.argv[1:])\n", "path": "cupyx/tools/install_library.py"}], "after_files": [{"content": "#!/usr/bin/env python\n\n\"\"\"\nCUDA Library Installer\n\nInstalls the latest CUDA library supported by CuPy.\n\"\"\"\n\n# This script will also be used as a standalone script when building wheels.\n# Keep the script runnable without CuPy dependency.\n\nimport argparse\nimport json\nimport os\nimport platform\nimport shutil\nimport sys\nimport tempfile\nimport urllib.request\n\n\n_cudnn_records = []\n_cutensor_records = []\nlibrary_records = {}\n\n\ndef _make_cudnn_url(public_version, filename):\n    # https://developer.download.nvidia.com/compute/redist/cudnn/v8.0.2/cudnn-11.0-linux-x64-v8.0.2.39.tgz\n    return (\n        'https://developer.download.nvidia.com/compute/redist/cudnn' +\n        '/v{}/{}'.format(public_version, filename))\n\n\ndef _make_cudnn_record(\n        cuda_version, public_version, filename_linux, filename_windows):\n    major_version = public_version.split('.')[0]\n    return {\n        'cuda': cuda_version,\n        'cudnn': public_version,\n        'assets': {\n            'Linux': {\n                'url': _make_cudnn_url(public_version, filename_linux),\n                'filename': 'libcudnn.so.{}'.format(public_version),\n            },\n            'Windows': {\n                'url': _make_cudnn_url(public_version, filename_windows),\n                'filename': 'cudnn64_{}.dll'.format(major_version),\n            },\n        }\n    }\n\n\n# Latest cuDNN versions: https://developer.nvidia.com/rdp/cudnn-download\n_cudnn_records.append(_make_cudnn_record(\n    '11.1', '8.1.0',\n    'cudnn-11.2-linux-x64-v8.1.0.77.tgz',\n    'cudnn-11.2-windows-x64-v8.1.0.77.zip'))\n_cudnn_records.append(_make_cudnn_record(\n    '11.0', '8.1.0',\n    'cudnn-11.2-linux-x64-v8.1.0.77.tgz',\n    'cudnn-11.2-windows-x64-v8.1.0.77.zip'))\n_cudnn_records.append(_make_cudnn_record(\n    '10.2', '8.1.0',\n    'cudnn-10.2-linux-x64-v8.1.0.77.tgz',\n    'cudnn-10.2-windows10-x64-v8.1.0.77.zip'))\n_cudnn_records.append(_make_cudnn_record(\n    '10.1', '8.0.5',\n    'cudnn-10.1-linux-x64-v8.0.5.39.tgz',\n    'cudnn-10.1-windows10-x64-v8.0.5.39.zip'))\n_cudnn_records.append(_make_cudnn_record(\n    '10.0', '7.6.5',\n    'cudnn-10.0-linux-x64-v7.6.5.32.tgz',\n    'cudnn-10.0-windows10-x64-v7.6.5.32.zip'))\n_cudnn_records.append(_make_cudnn_record(\n    '9.2', '7.6.5',\n    'cudnn-9.2-linux-x64-v7.6.5.32.tgz',\n    'cudnn-9.2-windows10-x64-v7.6.5.32.zip'))\nlibrary_records['cudnn'] = _cudnn_records\n\n\ndef _make_cutensor_url(public_version, filename):\n    # https://developer.download.nvidia.com/compute/cutensor/1.2.2/local_installers/libcutensor-linux-x86_64-1.2.2.5.tar.gz\n    return (\n        'https://developer.download.nvidia.com/compute/cutensor/' +\n        '{}/local_installers/{}'.format(public_version, filename))\n\n\ndef _make_cutensor_record(\n        cuda_version, public_version, filename_linux, filename_windows):\n    return {\n        'cuda': cuda_version,\n        'cutensor': public_version,\n        'assets': {\n            'Linux': {\n                'url': _make_cutensor_url(public_version, filename_linux),\n                'filename': 'libcutensor.so.{}'.format(public_version),\n            },\n            'Windows': {\n                'url': _make_cutensor_url(public_version, filename_windows),\n                'filename': 'cutensor.dll',\n            },\n        }\n    }\n\n\n_cutensor_records.append(_make_cutensor_record(\n    '11.1', '1.2.2',\n    'libcutensor-linux-x86_64-1.2.2.5.tar.gz',\n    'libcutensor-windows-x86_64-1.2.2.5.zip'))\n_cutensor_records.append(_make_cutensor_record(\n    '11.0', '1.2.2',\n    'libcutensor-linux-x86_64-1.2.2.5.tar.gz',\n    'libcutensor-windows-x86_64-1.2.2.5.zip'))\n_cutensor_records.append(_make_cutensor_record(\n    '10.2', '1.2.2',\n    'libcutensor-linux-x86_64-1.2.2.5.tar.gz',\n    'libcutensor-windows-x86_64-1.2.2.5.zip'))\n_cutensor_records.append(_make_cutensor_record(\n    '10.1', '1.2.2',\n    'libcutensor-linux-x86_64-1.2.2.5.tar.gz',\n    'libcutensor-windows-x86_64-1.2.2.5.zip'))\nlibrary_records['cutensor'] = _cutensor_records\n\n\ndef install_lib(cuda, prefix, library):\n    record = None\n    lib_records = library_records\n    for record in lib_records[library]:\n        if record['cuda'] == cuda:\n            break\n    else:\n        raise RuntimeError('''\nThe CUDA version specified is not supported.\nShould be one of {}.'''.format(str([x['cuda'] for x in lib_records[library]])))\n    if prefix is None:\n        prefix = os.path.expanduser('~/.cupy/cuda_lib')\n    destination = calculate_destination(prefix, cuda, library, record[library])\n\n    if os.path.exists(destination):\n        raise RuntimeError('''\nThe destination directory {} already exists.\nRemove the directory first if you want to reinstall.'''.format(destination))\n    asset = record['assets'][platform.system()]\n\n    print('Installing {} {} for CUDA {} to: {}'.format(\n        library, record[library], record['cuda'], destination))\n\n    url = asset['url']\n    print('Downloading {}...'.format(url))\n    with tempfile.TemporaryDirectory() as tmpdir:\n        with open(os.path.join(tmpdir, os.path.basename(url)), 'wb') as f:\n            with urllib.request.urlopen(url) as response:\n                f.write(response.read())\n        print('Extracting...')\n        shutil.unpack_archive(f.name, tmpdir)\n        print('Installing...')\n        if library == 'cudnn':\n            shutil.move(os.path.join(tmpdir, 'cuda'), destination)\n        elif library == 'cutensor':\n            include = os.path.join(destination, 'include')\n            lib = os.path.join(destination, 'lib64')\n            shutil.move(os.path.join(tmpdir, 'libcutensor/include'), include)\n            if cuda.startswith('11'):\n                cuda = '11'\n            shutil.move(os.path.join(tmpdir, 'libcutensor/lib', cuda), lib)\n        print('Cleaning up...')\n    print('Done!')\n\n\ndef calculate_destination(prefix, cuda, lib, lib_ver):\n    \"\"\"Calculates the installation directory.\n\n    ~/.cupy/cuda_lib/{cuda_version}/{library_name}/{library_version}\n    \"\"\"\n    return os.path.join(prefix, cuda, lib, lib_ver)\n\n\ndef main(args):\n    parser = argparse.ArgumentParser()\n\n    # TODO(kmaehashi): support NCCL\n    parser.add_argument('--library',\n                        choices=['cudnn', 'cutensor'],\n                        required=True,\n                        help='Library to install')\n    parser.add_argument('--cuda', type=str, required=True,\n                        help='CUDA version')\n    parser.add_argument('--prefix', type=str, default=None,\n                        help='Install destination')\n    parser.add_argument('--action', choices=['install', 'dump'],\n                        default='install',\n                        help='Action to perform')\n    params = parser.parse_args(args)\n\n    if params.prefix is not None:\n        params.prefix = os.path.abspath(params.prefix)\n\n    if params.library == 'cudnn':\n        if params.action == 'install':\n            install_lib(params.cuda, params.prefix, 'cudnn')\n        elif params.action == 'dump':\n            print(json.dumps(_cudnn_records, indent=4))\n        else:\n            assert False\n    elif params.library == 'cutensor':\n        if params.action == 'install':\n            install_lib(params.cuda, params.prefix, 'cutensor')\n        elif params.action == 'dump':\n            print(json.dumps(_cutensor_records, indent=4))\n        else:\n            assert False\n    else:\n        assert False\n\n\nif __name__ == '__main__':\n    main(sys.argv[1:])\n", "path": "cupyx/tools/install_library.py"}]}