We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Has anyone successfully compiled the C++ API on Windows, including the cuda code?
I have tried many versions of torchvision, none seems to work for me. (on Windows)
1, The old version 0.5.0 simply does not include cuda code into the build. 
2, Then I tried 0.6.0, it has the "-openmp" not support error. After a lot of searching and trying, I solved it by deleting one line in the torchvision.vcxproj.
3, 0.6.0 finally gets to compile, but it gives "unresolved external symbol" error if i want to use nms_cuda, according to this issue #2139, the cuda impl of operators are not included in torchvision.lib.
4, Then I tried the recent 0.7.0 tag and it gives "A single input file is required for a non-link phase when an outputfile is specified" error, this one (#2677) simply no one here knows how to solve it. Other resources suggests it might due to misplaced white space...

Could you point me to a version that works on Windows? Or simply no support for Windows?


cc @peterjc123 @nbcsm @guyang3532 @maxluk @gunandrose4u @smartcat2010 @mszhanyi

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `.circleci/regenerate.py`
Content:
```
1 #!/usr/bin/env python3
2 
3 """
4 This script should use a very simple, functional programming style.
5 Avoid Jinja macros in favor of native Python functions.
6 
7 Don't go overboard on code generation; use Python only to generate
8 content that can't be easily declared statically using CircleCI's YAML API.
9 
10 Data declarations (e.g. the nested loops for defining the configuration matrix)
11 should be at the top of the file for easy updating.
12 
13 See this comment for design rationale:
14 https://github.com/pytorch/vision/pull/1321#issuecomment-531033978
15 """
16 
17 import jinja2
18 import yaml
19 import os.path
20 
21 
22 PYTHON_VERSIONS = ["3.6", "3.7", "3.8"]
23 
24 
25 def build_workflows(prefix='', filter_branch=None, upload=False, indentation=6, windows_latest_only=False):
26     w = []
27     for btype in ["wheel", "conda"]:
28         for os_type in ["linux", "macos", "win"]:
29             python_versions = PYTHON_VERSIONS
30             cu_versions_dict = {"linux": ["cpu", "cu92", "cu101", "cu102", "cu110"],
31                                 "win": ["cpu", "cu101", "cu102", "cu110"],
32                                 "macos": ["cpu"]}
33             cu_versions = cu_versions_dict[os_type]
34             for python_version in python_versions:
35                 for cu_version in cu_versions:
36                     for unicode in ([False, True] if btype == "wheel" and python_version == "2.7" else [False]):
37                         fb = filter_branch
38                         if windows_latest_only and os_type == "win" and filter_branch is None and \
39                             (python_version != python_versions[-1] or
40                              (cu_version not in [cu_versions[0], cu_versions[-1]])):
41                             fb = "master"
42                         w += workflow_pair(
43                             btype, os_type, python_version, cu_version,
44                             unicode, prefix, upload, filter_branch=fb)
45 
46     return indent(indentation, w)
47 
48 
49 def workflow_pair(btype, os_type, python_version, cu_version, unicode, prefix='', upload=False, *, filter_branch=None):
50 
51     w = []
52     unicode_suffix = "u" if unicode else ""
53     base_workflow_name = f"{prefix}binary_{os_type}_{btype}_py{python_version}{unicode_suffix}_{cu_version}"
54 
55     w.append(generate_base_workflow(
56         base_workflow_name, python_version, cu_version,
57         unicode, os_type, btype, filter_branch=filter_branch))
58 
59     if upload:
60         w.append(generate_upload_workflow(base_workflow_name, os_type, btype, cu_version, filter_branch=filter_branch))
61         if filter_branch == 'nightly' and os_type in ['linux', 'win']:
62             pydistro = 'pip' if btype == 'wheel' else 'conda'
63             w.append(generate_smoketest_workflow(pydistro, base_workflow_name, filter_branch, python_version, os_type))
64 
65     return w
66 
67 
68 manylinux_images = {
69     "cu92": "pytorch/manylinux-cuda92",
70     "cu101": "pytorch/manylinux-cuda101",
71     "cu102": "pytorch/manylinux-cuda102",
72     "cu110": "pytorch/manylinux-cuda110",
73 }
74 
75 
76 def get_manylinux_image(cu_version):
77     cu_suffix = "102"
78     if cu_version.startswith('cu'):
79         cu_suffix = cu_version[len('cu'):]
80     return f"pytorch/manylinux-cuda{cu_suffix}"
81 
82 
83 def generate_base_workflow(base_workflow_name, python_version, cu_version,
84                            unicode, os_type, btype, *, filter_branch=None):
85 
86     d = {
87         "name": base_workflow_name,
88         "python_version": python_version,
89         "cu_version": cu_version,
90     }
91 
92     if os_type != "win" and unicode:
93         d["unicode_abi"] = '1'
94 
95     if os_type != "win":
96         d["wheel_docker_image"] = get_manylinux_image(cu_version)
97 
98     if filter_branch is not None:
99         d["filters"] = {
100             "branches": {
101                 "only": filter_branch
102             },
103             "tags": {
104                 # Using a raw string here to avoid having to escape
105                 # anything
106                 "only": r"/v[0-9]+(\.[0-9]+)*-rc[0-9]+/"
107             }
108         }
109 
110     w = f"binary_{os_type}_{btype}"
111     return {w: d}
112 
113 
114 def gen_filter_branch_tree(*branches):
115     return {"branches": {"only": [b for b in branches]}}
116 
117 
118 def generate_upload_workflow(base_workflow_name, os_type, btype, cu_version, *, filter_branch=None):
119     d = {
120         "name": f"{base_workflow_name}_upload",
121         "context": "org-member",
122         "requires": [base_workflow_name],
123     }
124 
125     if btype == 'wheel':
126         d["subfolder"] = "" if os_type == 'macos' else cu_version + "/"
127 
128     if filter_branch is not None:
129         d["filters"] = {
130             "branches": {
131                 "only": filter_branch
132             },
133             "tags": {
134                 # Using a raw string here to avoid having to escape
135                 # anything
136                 "only": r"/v[0-9]+(\.[0-9]+)*-rc[0-9]+/"
137             }
138         }
139 
140     return {f"binary_{btype}_upload": d}
141 
142 
143 def generate_smoketest_workflow(pydistro, base_workflow_name, filter_branch, python_version, os_type):
144 
145     required_build_suffix = "_upload"
146     required_build_name = base_workflow_name + required_build_suffix
147 
148     smoke_suffix = f"smoke_test_{pydistro}"
149     d = {
150         "name": f"{base_workflow_name}_{smoke_suffix}",
151         "requires": [required_build_name],
152         "python_version": python_version,
153     }
154 
155     if filter_branch:
156         d["filters"] = gen_filter_branch_tree(filter_branch)
157 
158     return {"smoke_test_{os_type}_{pydistro}".format(os_type=os_type, pydistro=pydistro): d}
159 
160 
161 def indent(indentation, data_list):
162     return ("\n" + " " * indentation).join(
163         yaml.dump(data_list, default_flow_style=False).splitlines())
164 
165 
166 def unittest_workflows(indentation=6):
167     jobs = []
168     for os_type in ["linux", "windows", "macos"]:
169         for device_type in ["cpu", "gpu"]:
170             if os_type == "macos" and device_type == "gpu":
171                 continue
172             for i, python_version in enumerate(PYTHON_VERSIONS):
173                 job = {
174                     "name": f"unittest_{os_type}_{device_type}_py{python_version}",
175                     "python_version": python_version,
176                 }
177 
178                 if device_type == 'gpu':
179                     if python_version != "3.8":
180                         job['filters'] = gen_filter_branch_tree('master', 'nightly')
181                     job['cu_version'] = 'cu101'
182                 else:
183                     job['cu_version'] = 'cpu'
184 
185                 jobs.append({f"unittest_{os_type}_{device_type}": job})
186 
187     return indent(indentation, jobs)
188 
189 
190 def cmake_workflows(indentation=6):
191     jobs = []
192     python_version = '3.8'
193     for os_type in ['linux', 'windows', 'macos']:
194         # Right now CMake builds are failling on Windows (GPU)
195         device_types = ['cpu', 'gpu'] if os_type == 'linux' else ['cpu']
196         for device in device_types:
197             job = {
198                 'name': f'cmake_{os_type}_{device}',
199                 'python_version': python_version
200             }
201 
202             job['cu_version'] = 'cu101' if device == 'gpu' else 'cpu'
203             if device == 'gpu':
204                 job['wheel_docker_image'] = 'pytorch/manylinux-cuda101'
205             jobs.append({f'cmake_{os_type}_{device}': job})
206     return indent(indentation, jobs)
207 
208 
209 if __name__ == "__main__":
210     d = os.path.dirname(__file__)
211     env = jinja2.Environment(
212         loader=jinja2.FileSystemLoader(d),
213         lstrip_blocks=True,
214         autoescape=False,
215     )
216 
217     with open(os.path.join(d, 'config.yml'), 'w') as f:
218         f.write(env.get_template('config.yml.in').render(
219             build_workflows=build_workflows,
220             unittest_workflows=unittest_workflows,
221             cmake_workflows=cmake_workflows,
222         ))
223
```
--- 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/.circleci/regenerate.py b/.circleci/regenerate.py
--- a/.circleci/regenerate.py
+++ b/.circleci/regenerate.py
@@ -191,8 +191,8 @@
     jobs = []
     python_version = '3.8'
     for os_type in ['linux', 'windows', 'macos']:
-        # Right now CMake builds are failling on Windows (GPU)
-        device_types = ['cpu', 'gpu'] if os_type == 'linux' else ['cpu']
+        # Skip OSX CUDA
+        device_types = ['cpu', 'gpu'] if os_type != 'macos' else ['cpu']
         for device in device_types:
             job = {
                 'name': f'cmake_{os_type}_{device}',
@@ -200,7 +200,7 @@
             }
 
             job['cu_version'] = 'cu101' if device == 'gpu' else 'cpu'
-            if device == 'gpu':
+            if device == 'gpu' and os_type == 'linux':
                 job['wheel_docker_image'] = 'pytorch/manylinux-cuda101'
             jobs.append({f'cmake_{os_type}_{device}': job})
     return indent(indentation, jobs)

{"golden_diff": "diff --git a/.circleci/regenerate.py b/.circleci/regenerate.py\n--- a/.circleci/regenerate.py\n+++ b/.circleci/regenerate.py\n@@ -191,8 +191,8 @@\n     jobs = []\n     python_version = '3.8'\n     for os_type in ['linux', 'windows', 'macos']:\n-        # Right now CMake builds are failling on Windows (GPU)\n-        device_types = ['cpu', 'gpu'] if os_type == 'linux' else ['cpu']\n+        # Skip OSX CUDA\n+        device_types = ['cpu', 'gpu'] if os_type != 'macos' else ['cpu']\n         for device in device_types:\n             job = {\n                 'name': f'cmake_{os_type}_{device}',\n@@ -200,7 +200,7 @@\n             }\n \n             job['cu_version'] = 'cu101' if device == 'gpu' else 'cpu'\n-            if device == 'gpu':\n+            if device == 'gpu' and os_type == 'linux':\n                 job['wheel_docker_image'] = 'pytorch/manylinux-cuda101'\n             jobs.append({f'cmake_{os_type}_{device}': job})\n     return indent(indentation, jobs)\n", "issue": "Has anyone successfully compiled the C++ API on Windows, including the cuda code?\nI have tried many versions of torchvision, none seems to work for me. (on Windows)\r\n1, The old version 0.5.0 simply does not include cuda code into the build. \r\n2, Then I tried 0.6.0, it has the \"-openmp\" not support error. After a lot of searching and trying, I solved it by deleting one line in the torchvision.vcxproj.\r\n3, 0.6.0 finally gets to compile, but it gives \"unresolved external symbol\" error if i want to use nms_cuda, according to this issue #2139, the cuda impl of operators are not included in torchvision.lib.\r\n4, Then I tried the recent 0.7.0 tag and it gives \"A single input file is required for a non-link phase when an outputfile is specified\" error, this one (#2677) simply no one here knows how to solve it. Other resources suggests it might due to misplaced white space...\r\n\r\nCould you point me to a version that works on Windows? Or simply no support for Windows?\r\n\n\ncc @peterjc123 @nbcsm @guyang3532 @maxluk @gunandrose4u @smartcat2010 @mszhanyi\n", "before_files": [{"content": "#!/usr/bin/env python3\n\n\"\"\"\nThis script should use a very simple, functional programming style.\nAvoid Jinja macros in favor of native Python functions.\n\nDon't go overboard on code generation; use Python only to generate\ncontent that can't be easily declared statically using CircleCI's YAML API.\n\nData declarations (e.g. the nested loops for defining the configuration matrix)\nshould be at the top of the file for easy updating.\n\nSee this comment for design rationale:\nhttps://github.com/pytorch/vision/pull/1321#issuecomment-531033978\n\"\"\"\n\nimport jinja2\nimport yaml\nimport os.path\n\n\nPYTHON_VERSIONS = [\"3.6\", \"3.7\", \"3.8\"]\n\n\ndef build_workflows(prefix='', filter_branch=None, upload=False, indentation=6, windows_latest_only=False):\n    w = []\n    for btype in [\"wheel\", \"conda\"]:\n        for os_type in [\"linux\", \"macos\", \"win\"]:\n            python_versions = PYTHON_VERSIONS\n            cu_versions_dict = {\"linux\": [\"cpu\", \"cu92\", \"cu101\", \"cu102\", \"cu110\"],\n                                \"win\": [\"cpu\", \"cu101\", \"cu102\", \"cu110\"],\n                                \"macos\": [\"cpu\"]}\n            cu_versions = cu_versions_dict[os_type]\n            for python_version in python_versions:\n                for cu_version in cu_versions:\n                    for unicode in ([False, True] if btype == \"wheel\" and python_version == \"2.7\" else [False]):\n                        fb = filter_branch\n                        if windows_latest_only and os_type == \"win\" and filter_branch is None and \\\n                            (python_version != python_versions[-1] or\n                             (cu_version not in [cu_versions[0], cu_versions[-1]])):\n                            fb = \"master\"\n                        w += workflow_pair(\n                            btype, os_type, python_version, cu_version,\n                            unicode, prefix, upload, filter_branch=fb)\n\n    return indent(indentation, w)\n\n\ndef workflow_pair(btype, os_type, python_version, cu_version, unicode, prefix='', upload=False, *, filter_branch=None):\n\n    w = []\n    unicode_suffix = \"u\" if unicode else \"\"\n    base_workflow_name = f\"{prefix}binary_{os_type}_{btype}_py{python_version}{unicode_suffix}_{cu_version}\"\n\n    w.append(generate_base_workflow(\n        base_workflow_name, python_version, cu_version,\n        unicode, os_type, btype, filter_branch=filter_branch))\n\n    if upload:\n        w.append(generate_upload_workflow(base_workflow_name, os_type, btype, cu_version, filter_branch=filter_branch))\n        if filter_branch == 'nightly' and os_type in ['linux', 'win']:\n            pydistro = 'pip' if btype == 'wheel' else 'conda'\n            w.append(generate_smoketest_workflow(pydistro, base_workflow_name, filter_branch, python_version, os_type))\n\n    return w\n\n\nmanylinux_images = {\n    \"cu92\": \"pytorch/manylinux-cuda92\",\n    \"cu101\": \"pytorch/manylinux-cuda101\",\n    \"cu102\": \"pytorch/manylinux-cuda102\",\n    \"cu110\": \"pytorch/manylinux-cuda110\",\n}\n\n\ndef get_manylinux_image(cu_version):\n    cu_suffix = \"102\"\n    if cu_version.startswith('cu'):\n        cu_suffix = cu_version[len('cu'):]\n    return f\"pytorch/manylinux-cuda{cu_suffix}\"\n\n\ndef generate_base_workflow(base_workflow_name, python_version, cu_version,\n                           unicode, os_type, btype, *, filter_branch=None):\n\n    d = {\n        \"name\": base_workflow_name,\n        \"python_version\": python_version,\n        \"cu_version\": cu_version,\n    }\n\n    if os_type != \"win\" and unicode:\n        d[\"unicode_abi\"] = '1'\n\n    if os_type != \"win\":\n        d[\"wheel_docker_image\"] = get_manylinux_image(cu_version)\n\n    if filter_branch is not None:\n        d[\"filters\"] = {\n            \"branches\": {\n                \"only\": filter_branch\n            },\n            \"tags\": {\n                # Using a raw string here to avoid having to escape\n                # anything\n                \"only\": r\"/v[0-9]+(\\.[0-9]+)*-rc[0-9]+/\"\n            }\n        }\n\n    w = f\"binary_{os_type}_{btype}\"\n    return {w: d}\n\n\ndef gen_filter_branch_tree(*branches):\n    return {\"branches\": {\"only\": [b for b in branches]}}\n\n\ndef generate_upload_workflow(base_workflow_name, os_type, btype, cu_version, *, filter_branch=None):\n    d = {\n        \"name\": f\"{base_workflow_name}_upload\",\n        \"context\": \"org-member\",\n        \"requires\": [base_workflow_name],\n    }\n\n    if btype == 'wheel':\n        d[\"subfolder\"] = \"\" if os_type == 'macos' else cu_version + \"/\"\n\n    if filter_branch is not None:\n        d[\"filters\"] = {\n            \"branches\": {\n                \"only\": filter_branch\n            },\n            \"tags\": {\n                # Using a raw string here to avoid having to escape\n                # anything\n                \"only\": r\"/v[0-9]+(\\.[0-9]+)*-rc[0-9]+/\"\n            }\n        }\n\n    return {f\"binary_{btype}_upload\": d}\n\n\ndef generate_smoketest_workflow(pydistro, base_workflow_name, filter_branch, python_version, os_type):\n\n    required_build_suffix = \"_upload\"\n    required_build_name = base_workflow_name + required_build_suffix\n\n    smoke_suffix = f\"smoke_test_{pydistro}\"\n    d = {\n        \"name\": f\"{base_workflow_name}_{smoke_suffix}\",\n        \"requires\": [required_build_name],\n        \"python_version\": python_version,\n    }\n\n    if filter_branch:\n        d[\"filters\"] = gen_filter_branch_tree(filter_branch)\n\n    return {\"smoke_test_{os_type}_{pydistro}\".format(os_type=os_type, pydistro=pydistro): d}\n\n\ndef indent(indentation, data_list):\n    return (\"\\n\" + \" \" * indentation).join(\n        yaml.dump(data_list, default_flow_style=False).splitlines())\n\n\ndef unittest_workflows(indentation=6):\n    jobs = []\n    for os_type in [\"linux\", \"windows\", \"macos\"]:\n        for device_type in [\"cpu\", \"gpu\"]:\n            if os_type == \"macos\" and device_type == \"gpu\":\n                continue\n            for i, python_version in enumerate(PYTHON_VERSIONS):\n                job = {\n                    \"name\": f\"unittest_{os_type}_{device_type}_py{python_version}\",\n                    \"python_version\": python_version,\n                }\n\n                if device_type == 'gpu':\n                    if python_version != \"3.8\":\n                        job['filters'] = gen_filter_branch_tree('master', 'nightly')\n                    job['cu_version'] = 'cu101'\n                else:\n                    job['cu_version'] = 'cpu'\n\n                jobs.append({f\"unittest_{os_type}_{device_type}\": job})\n\n    return indent(indentation, jobs)\n\n\ndef cmake_workflows(indentation=6):\n    jobs = []\n    python_version = '3.8'\n    for os_type in ['linux', 'windows', 'macos']:\n        # Right now CMake builds are failling on Windows (GPU)\n        device_types = ['cpu', 'gpu'] if os_type == 'linux' else ['cpu']\n        for device in device_types:\n            job = {\n                'name': f'cmake_{os_type}_{device}',\n                'python_version': python_version\n            }\n\n            job['cu_version'] = 'cu101' if device == 'gpu' else 'cpu'\n            if device == 'gpu':\n                job['wheel_docker_image'] = 'pytorch/manylinux-cuda101'\n            jobs.append({f'cmake_{os_type}_{device}': job})\n    return indent(indentation, jobs)\n\n\nif __name__ == \"__main__\":\n    d = os.path.dirname(__file__)\n    env = jinja2.Environment(\n        loader=jinja2.FileSystemLoader(d),\n        lstrip_blocks=True,\n        autoescape=False,\n    )\n\n    with open(os.path.join(d, 'config.yml'), 'w') as f:\n        f.write(env.get_template('config.yml.in').render(\n            build_workflows=build_workflows,\n            unittest_workflows=unittest_workflows,\n            cmake_workflows=cmake_workflows,\n        ))\n", "path": ".circleci/regenerate.py"}], "after_files": [{"content": "#!/usr/bin/env python3\n\n\"\"\"\nThis script should use a very simple, functional programming style.\nAvoid Jinja macros in favor of native Python functions.\n\nDon't go overboard on code generation; use Python only to generate\ncontent that can't be easily declared statically using CircleCI's YAML API.\n\nData declarations (e.g. the nested loops for defining the configuration matrix)\nshould be at the top of the file for easy updating.\n\nSee this comment for design rationale:\nhttps://github.com/pytorch/vision/pull/1321#issuecomment-531033978\n\"\"\"\n\nimport jinja2\nimport yaml\nimport os.path\n\n\nPYTHON_VERSIONS = [\"3.6\", \"3.7\", \"3.8\"]\n\n\ndef build_workflows(prefix='', filter_branch=None, upload=False, indentation=6, windows_latest_only=False):\n    w = []\n    for btype in [\"wheel\", \"conda\"]:\n        for os_type in [\"linux\", \"macos\", \"win\"]:\n            python_versions = PYTHON_VERSIONS\n            cu_versions_dict = {\"linux\": [\"cpu\", \"cu92\", \"cu101\", \"cu102\", \"cu110\"],\n                                \"win\": [\"cpu\", \"cu101\", \"cu102\", \"cu110\"],\n                                \"macos\": [\"cpu\"]}\n            cu_versions = cu_versions_dict[os_type]\n            for python_version in python_versions:\n                for cu_version in cu_versions:\n                    for unicode in ([False, True] if btype == \"wheel\" and python_version == \"2.7\" else [False]):\n                        fb = filter_branch\n                        if windows_latest_only and os_type == \"win\" and filter_branch is None and \\\n                            (python_version != python_versions[-1] or\n                             (cu_version not in [cu_versions[0], cu_versions[-1]])):\n                            fb = \"master\"\n                        w += workflow_pair(\n                            btype, os_type, python_version, cu_version,\n                            unicode, prefix, upload, filter_branch=fb)\n\n    return indent(indentation, w)\n\n\ndef workflow_pair(btype, os_type, python_version, cu_version, unicode, prefix='', upload=False, *, filter_branch=None):\n\n    w = []\n    unicode_suffix = \"u\" if unicode else \"\"\n    base_workflow_name = f\"{prefix}binary_{os_type}_{btype}_py{python_version}{unicode_suffix}_{cu_version}\"\n\n    w.append(generate_base_workflow(\n        base_workflow_name, python_version, cu_version,\n        unicode, os_type, btype, filter_branch=filter_branch))\n\n    if upload:\n        w.append(generate_upload_workflow(base_workflow_name, os_type, btype, cu_version, filter_branch=filter_branch))\n        if filter_branch == 'nightly' and os_type in ['linux', 'win']:\n            pydistro = 'pip' if btype == 'wheel' else 'conda'\n            w.append(generate_smoketest_workflow(pydistro, base_workflow_name, filter_branch, python_version, os_type))\n\n    return w\n\n\nmanylinux_images = {\n    \"cu92\": \"pytorch/manylinux-cuda92\",\n    \"cu101\": \"pytorch/manylinux-cuda101\",\n    \"cu102\": \"pytorch/manylinux-cuda102\",\n    \"cu110\": \"pytorch/manylinux-cuda110\",\n}\n\n\ndef get_manylinux_image(cu_version):\n    cu_suffix = \"102\"\n    if cu_version.startswith('cu'):\n        cu_suffix = cu_version[len('cu'):]\n    return f\"pytorch/manylinux-cuda{cu_suffix}\"\n\n\ndef generate_base_workflow(base_workflow_name, python_version, cu_version,\n                           unicode, os_type, btype, *, filter_branch=None):\n\n    d = {\n        \"name\": base_workflow_name,\n        \"python_version\": python_version,\n        \"cu_version\": cu_version,\n    }\n\n    if os_type != \"win\" and unicode:\n        d[\"unicode_abi\"] = '1'\n\n    if os_type != \"win\":\n        d[\"wheel_docker_image\"] = get_manylinux_image(cu_version)\n\n    if filter_branch is not None:\n        d[\"filters\"] = {\n            \"branches\": {\n                \"only\": filter_branch\n            },\n            \"tags\": {\n                # Using a raw string here to avoid having to escape\n                # anything\n                \"only\": r\"/v[0-9]+(\\.[0-9]+)*-rc[0-9]+/\"\n            }\n        }\n\n    w = f\"binary_{os_type}_{btype}\"\n    return {w: d}\n\n\ndef gen_filter_branch_tree(*branches):\n    return {\"branches\": {\"only\": [b for b in branches]}}\n\n\ndef generate_upload_workflow(base_workflow_name, os_type, btype, cu_version, *, filter_branch=None):\n    d = {\n        \"name\": f\"{base_workflow_name}_upload\",\n        \"context\": \"org-member\",\n        \"requires\": [base_workflow_name],\n    }\n\n    if btype == 'wheel':\n        d[\"subfolder\"] = \"\" if os_type == 'macos' else cu_version + \"/\"\n\n    if filter_branch is not None:\n        d[\"filters\"] = {\n            \"branches\": {\n                \"only\": filter_branch\n            },\n            \"tags\": {\n                # Using a raw string here to avoid having to escape\n                # anything\n                \"only\": r\"/v[0-9]+(\\.[0-9]+)*-rc[0-9]+/\"\n            }\n        }\n\n    return {f\"binary_{btype}_upload\": d}\n\n\ndef generate_smoketest_workflow(pydistro, base_workflow_name, filter_branch, python_version, os_type):\n\n    required_build_suffix = \"_upload\"\n    required_build_name = base_workflow_name + required_build_suffix\n\n    smoke_suffix = f\"smoke_test_{pydistro}\"\n    d = {\n        \"name\": f\"{base_workflow_name}_{smoke_suffix}\",\n        \"requires\": [required_build_name],\n        \"python_version\": python_version,\n    }\n\n    if filter_branch:\n        d[\"filters\"] = gen_filter_branch_tree(filter_branch)\n\n    return {\"smoke_test_{os_type}_{pydistro}\".format(os_type=os_type, pydistro=pydistro): d}\n\n\ndef indent(indentation, data_list):\n    return (\"\\n\" + \" \" * indentation).join(\n        yaml.dump(data_list, default_flow_style=False).splitlines())\n\n\ndef unittest_workflows(indentation=6):\n    jobs = []\n    for os_type in [\"linux\", \"windows\", \"macos\"]:\n        for device_type in [\"cpu\", \"gpu\"]:\n            if os_type == \"macos\" and device_type == \"gpu\":\n                continue\n            for i, python_version in enumerate(PYTHON_VERSIONS):\n                job = {\n                    \"name\": f\"unittest_{os_type}_{device_type}_py{python_version}\",\n                    \"python_version\": python_version,\n                }\n\n                if device_type == 'gpu':\n                    if python_version != \"3.8\":\n                        job['filters'] = gen_filter_branch_tree('master', 'nightly')\n                    job['cu_version'] = 'cu101'\n                else:\n                    job['cu_version'] = 'cpu'\n\n                jobs.append({f\"unittest_{os_type}_{device_type}\": job})\n\n    return indent(indentation, jobs)\n\n\ndef cmake_workflows(indentation=6):\n    jobs = []\n    python_version = '3.8'\n    for os_type in ['linux', 'windows', 'macos']:\n        # Skip OSX CUDA\n        device_types = ['cpu', 'gpu'] if os_type != 'macos' else ['cpu']\n        for device in device_types:\n            job = {\n                'name': f'cmake_{os_type}_{device}',\n                'python_version': python_version\n            }\n\n            job['cu_version'] = 'cu101' if device == 'gpu' else 'cpu'\n            if device == 'gpu' and os_type == 'linux':\n                job['wheel_docker_image'] = 'pytorch/manylinux-cuda101'\n            jobs.append({f'cmake_{os_type}_{device}': job})\n    return indent(indentation, jobs)\n\n\nif __name__ == \"__main__\":\n    d = os.path.dirname(__file__)\n    env = jinja2.Environment(\n        loader=jinja2.FileSystemLoader(d),\n        lstrip_blocks=True,\n        autoescape=False,\n    )\n\n    with open(os.path.join(d, 'config.yml'), 'w') as f:\n        f.write(env.get_template('config.yml.in').render(\n            build_workflows=build_workflows,\n            unittest_workflows=unittest_workflows,\n            cmake_workflows=cmake_workflows,\n        ))\n", "path": ".circleci/regenerate.py"}]}