Skip to content

Commit b2cee0e

Browse files
committed
Update on "Introduce tools.codegen.api.translate"
cpparguments_exprs has induced a lot of head scratching in many recent PRs for how to structure the code in a good way. This PR eliminates the old algorithm for an entirely new algorithm inspired by logic programming. The net result is shorter, cleaner and should be more robust to future changes. This PR is a bit of a whopper. Here is the order to review it. - tools/codegen/api/types.py - Deleted CppArgument, CppArgumentPackIface (and subclasses), CppExpr, DispatcherExpr, DispatcherArgument, NativeExpr, NativeArgument, MetaArgument. All things previously called XArgument are now Binding. All things previously called XExpr are now Expr. I deleted the `__str__` implementation on Binding and fixed all call sites not to use it. On Binding, I renamed `str_no_default` and `str_default` to `defn` and `decl` for better symmetry with the corresponding signature concepts, although I'm open to naming them back to their original versions. - Obviously, things are less type safe without the class distinctions. So I introduce a new ADT called CType. CType represents the *semantic C++ type* of a binding: it is both the C++ type (e.g., `const Tensor&`) as well as the argument name that specifies what the binding denotes (e.g., `other`). Every binding now records its CType. The key observation here is that you don't actually care if a given expression is from the cpp or dispatcher or native API; what you care is having enough information to know what the expression means, so you can use it appropriately. CType has this information. For the most part, ArgNames are just the string names of the arguments as you see them in JIT schema, but there is one case (`possibly_redundant_memory_format`) where we encode a little extra information. Unlike the plain strings we previously used to represent C++ types, CType have a little bit of structure around optional and references, because the translation code needs to work around these concepts. - I took the opportunity to kill all of the private fields like `_arguments` and `_returns_type` (since the argument types don't make sense anymore). Everything is computed for you on the fly. If this is a perf problem in codegen we can start using `cached_property` decorator. - All of the heavy lifting in CppSignature.argument_packs has been moved to the cpp module. We'll head over there next. Similarly, all of the exprs methods are now calling translate, the new functionality which we haven't gotten to yet - tools/codegen/api/cpp.py - We refactor all of the type computation functions to return CType instead of str. Because CTypes need to know the denotation, there is a new `binds: ArgName` argument to most functions that provides the denotation, so we can slot it in. (An alternative would have been to construct CTypes without denotations and then fill them in post-facto, but I didn't do it this way. One downside is there are some places where I need a CType without denotation, so I fill these in with `__placeholder__` whenever this happens). - `argument` and `arguments` are now extremely simple. There is no more Pack business, just produce one or more Bindings. The one thing of note is that when both a `memory_format` and `options` are in scope, we label the memory format as `possibly_redundant_memory_format`. This will be used in translation - tools/codegen/api/dispatcher.py and tools/codegen/api/native.py - same deal as cpp.py. One thing is that `cpparguments_exprs` is deleted; that is in the translator - tools/codegen/api/translate.py - the translator! It uses a very simple backwards deduction engine to work out how to fill in the arguments of functions. There are comments in the file that explain how it works. - Everything else: just some small call site tweaks for places when I changed API. Signed-off-by: Edward Z. Yang <[email protected]> Differential Revision: [D25455887](https://our.internmc.facebook.com/intern/diff/D25455887) [ghstack-poisoned]
2 parents d02b7a4 + cb091ee commit b2cee0e

File tree

188 files changed

+5900
-2312
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

188 files changed

+5900
-2312
lines changed

.circleci/cimodel/data/simple/util/versions.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,6 @@ def __init__(self, major, minor):
2929
self.minor = minor
3030

3131
super().__init__([self.major, self.minor], "cuda")
32+
33+
def __str__(self):
34+
return f"{self.major}.{self.minor}"

.circleci/cimodel/data/windows_build_definitions.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,11 @@ def gen_tree(self):
8686
props_dict["executor"] = "windows-with-nvidia-gpu"
8787

8888
props_dict["cuda_version"] = (
89-
miniutils.quote(str(self.cuda_version.major))
89+
miniutils.quote(str(self.cuda_version))
9090
if self.cuda_version
9191
else "cpu"
9292
)
93+
9394
props_dict["name"] = "_".join(name_parts)
9495

9596
return [{key_name: props_dict}]

.circleci/config.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ pytorch_windows_params: &pytorch_windows_params
325325
default: ""
326326
cuda_version:
327327
type: string
328-
default: "10"
328+
default: "10.1"
329329
python_version:
330330
type: string
331331
default: "3.6"
@@ -675,7 +675,7 @@ jobs:
675675
default: ""
676676
cuda_version:
677677
type: string
678-
default: "10"
678+
default: "10.1"
679679
python_version:
680680
type: string
681681
default: "3.6"
@@ -737,7 +737,7 @@ jobs:
737737
default: ""
738738
cuda_version:
739739
type: string
740-
default: "10"
740+
default: "10.1"
741741
python_version:
742742
type: string
743743
default: "3.6"
@@ -8077,7 +8077,7 @@ workflows:
80778077
- postnightly
80788078
- pytorch_windows_build:
80798079
build_environment: pytorch-win-vs2019-cuda10-cudnn7-py3
8080-
cuda_version: "10"
8080+
cuda_version: "10.1"
80818081
name: pytorch_windows_vs2019_py36_cuda10.1_build
80828082
python_version: "3.6"
80838083
use_cuda: "1"
@@ -8086,7 +8086,7 @@ workflows:
80868086
vc_year: "2019"
80878087
- pytorch_windows_test:
80888088
build_environment: pytorch-win-vs2019-cuda10-cudnn7-py3
8089-
cuda_version: "10"
8089+
cuda_version: "10.1"
80908090
executor: windows-with-nvidia-gpu
80918091
name: pytorch_windows_vs2019_py36_cuda10.1_test1
80928092
python_version: "3.6"
@@ -8099,7 +8099,7 @@ workflows:
80998099
vc_year: "2019"
81008100
- pytorch_windows_test:
81018101
build_environment: pytorch-win-vs2019-cuda10-cudnn7-py3
8102-
cuda_version: "10"
8102+
cuda_version: "10.1"
81038103
executor: windows-with-nvidia-gpu
81048104
name: pytorch_windows_vs2019_py36_cuda10.1_test2
81058105
python_version: "3.6"
@@ -8112,7 +8112,7 @@ workflows:
81128112
vc_year: "2019"
81138113
- pytorch_windows_build:
81148114
build_environment: pytorch-win-vs2019-cuda11-cudnn8-py3
8115-
cuda_version: "11"
8115+
cuda_version: "11.1"
81168116
name: pytorch_windows_vs2019_py36_cuda11.1_build
81178117
python_version: "3.6"
81188118
use_cuda: "1"
@@ -8121,7 +8121,7 @@ workflows:
81218121
vc_year: "2019"
81228122
- pytorch_windows_test:
81238123
build_environment: pytorch-win-vs2019-cuda11-cudnn8-py3
8124-
cuda_version: "11"
8124+
cuda_version: "11.1"
81258125
executor: windows-with-nvidia-gpu
81268126
filters:
81278127
branches:
@@ -8140,7 +8140,7 @@ workflows:
81408140
vc_year: "2019"
81418141
- pytorch_windows_test:
81428142
build_environment: pytorch-win-vs2019-cuda11-cudnn8-py3
8143-
cuda_version: "11"
8143+
cuda_version: "11.1"
81448144
executor: windows-with-nvidia-gpu
81458145
filters:
81468146
branches:
@@ -8204,7 +8204,7 @@ workflows:
82048204
vc_year: "2019"
82058205
- pytorch_windows_test:
82068206
build_environment: pytorch-win-vs2019-cuda10-cudnn7-py3
8207-
cuda_version: "10"
8207+
cuda_version: "10.1"
82088208
filters:
82098209
branches:
82108210
only:

.circleci/scripts/binary_linux_test.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ set -eux -o pipefail
77
88
python_nodot="\$(echo $DESIRED_PYTHON | tr -d m.u)"
99
10+
# There was a bug that was introduced in conda-package-handling >= 1.6.1 that makes archives
11+
# above a certain size fail out when attempting to extract
12+
# see: https://github.com/conda/conda-package-handling/issues/71
13+
conda install -y conda-package-handling=1.6.0
14+
1015
# Set up Python
1116
if [[ "$PACKAGE_TYPE" == conda ]]; then
1217
retry conda create -qyn testenv python="$DESIRED_PYTHON"

.circleci/scripts/windows_cuda_install.sh

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
#!/bin/bash
22
set -eux -o pipefail
33

4-
if [[ "$CUDA_VERSION" == "10" ]]; then
5-
cuda_complete_version="10.1"
4+
if [[ "$CUDA_VERSION" =~ ^10.* ]]; then
65
cuda_installer_name="cuda_10.1.243_426.00_win10"
76
msbuild_project_dir="CUDAVisualStudioIntegration/extras/visual_studio_integration/MSBuildExtensions"
87
cuda_install_packages="nvcc_10.1 cuobjdump_10.1 nvprune_10.1 cupti_10.1 cublas_10.1 cublas_dev_10.1 cudart_10.1 cufft_10.1 cufft_dev_10.1 curand_10.1 curand_dev_10.1 cusolver_10.1 cusolver_dev_10.1 cusparse_10.1 cusparse_dev_10.1 nvgraph_10.1 nvgraph_dev_10.1 npp_10.1 npp_dev_10.1 nvrtc_10.1 nvrtc_dev_10.1 nvml_dev_10.1"
9-
elif [[ "$CUDA_VERSION" == "11" ]]; then
10-
cuda_complete_version="11.1"
8+
elif [[ "$CUDA_VERSION" =~ ^11.* ]]; then
119
cuda_installer_name="cuda_11.1.0_456.43_win10"
1210
msbuild_project_dir="visual_studio_integration/CUDAVisualStudioIntegration/extras/visual_studio_integration/MSBuildExtensions"
1311
cuda_install_packages="nvcc_11.1 cuobjdump_11.1 nvprune_11.1 nvprof_11.1 cupti_11.1 cublas_11.1 cublas_dev_11.1 cudart_11.1 cufft_11.1 cufft_dev_11.1 curand_11.1 curand_dev_11.1 cusolver_11.1 cusolver_dev_11.1 cusparse_11.1 cusparse_dev_11.1 npp_11.1 npp_dev_11.1 nvrtc_11.1 nvrtc_dev_11.1 nvml_dev_11.1"
@@ -16,7 +14,7 @@ else
1614
exit 1
1715
fi
1816

19-
if [[ "${CUDA_VERSION}" != "10" && "${JOB_EXECUTOR}" == "windows-with-nvidia-gpu" ]]; then
17+
if [[ "$CUDA_VERSION" =~ ^11.* && "${JOB_EXECUTOR}" == "windows-with-nvidia-gpu" ]]; then
2018
cuda_install_packages="${cuda_install_packages} Display.Driver"
2119
fi
2220

@@ -48,7 +46,7 @@ then
4846
export NVTOOLSEXT_PATH="C:\\Program Files\\NVIDIA Corporation\\NvToolsExt\\"
4947
fi
5048

51-
if ! ls "/c/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v${cuda_complete_version}/bin/nvcc.exe"
49+
if ! ls "/c/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v${CUDA_VERSION}/bin/nvcc.exe"
5250
then
5351
echo "CUDA installation failed"
5452
mkdir -p /c/w/build-results
Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
#!/bin/bash
22
set -eux -o pipefail
33

4-
if [[ "$CUDA_VERSION" == "10" ]]; then
5-
cuda_complete_version="10.1"
6-
cudnn_installer_name="cudnn-10.1-windows10-x64-v7.6.4.38"
7-
elif [[ "$CUDA_VERSION" == "11" ]]; then
8-
cuda_complete_version="11.1"
9-
cudnn_installer_name="cudnn-11.1-windows-x64-v8.0.5.39"
4+
if [[ "$CUDA_VERSION" =~ ^10.* ]]; then
5+
cudnn_installer_name="cudnn-${CUDA_VERSION}-windows10-x64-v7.6.4.38"
6+
elif [[ "$CUDA_VERSION" =~ ^11.* ]]; then
7+
cudnn_installer_name="cudnn-${CUDA_VERSION}-windows-x64-v8.0.5.39"
108
else
119
echo "CUDNN for CUDA_VERSION $CUDA_VERSION is not supported yet"
1210
exit 1
@@ -16,6 +14,6 @@ cudnn_installer_link="https://ossci-windows.s3.amazonaws.com/${cudnn_installer_n
1614

1715
curl --retry 3 -O $cudnn_installer_link
1816
7z x ${cudnn_installer_name}.zip -ocudnn
19-
cp -r cudnn/cuda/* "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v${cuda_complete_version}/"
17+
cp -r cudnn/cuda/* "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v${CUDA_VERSION}/"
2018
rm -rf cudnn
2119
rm -f ${cudnn_installer_name}.zip

.circleci/verbatim-sources/build-parameters/pytorch-build-params.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pytorch_windows_params: &pytorch_windows_params
5959
default: ""
6060
cuda_version:
6161
type: string
62-
default: "10"
62+
default: "10.1"
6363
python_version:
6464
type: string
6565
default: "3.6"

.circleci/verbatim-sources/job-specs/pytorch-job-specs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ jobs:
237237
default: ""
238238
cuda_version:
239239
type: string
240-
default: "10"
240+
default: "10.1"
241241
python_version:
242242
type: string
243243
default: "3.6"
@@ -299,7 +299,7 @@ jobs:
299299
default: ""
300300
cuda_version:
301301
type: string
302-
default: "10"
302+
default: "10.1"
303303
python_version:
304304
type: string
305305
default: "3.6"

.jenkins/pytorch/test.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ source "$(dirname "${BASH_SOURCE[0]}")/common.sh"
1111

1212
echo "Testing pytorch"
1313

14+
export LANG=C.UTF-8
15+
1416
if [[ "$BUILD_ENVIRONMENT" == *-slow-* ]]; then
1517
export PYTORCH_TEST_WITH_SLOW=1
1618
export PYTORCH_TEST_SKIP_FAST=1

.jenkins/pytorch/win-test-helpers/build_pytorch.bat

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -37,33 +37,19 @@ if "%VC_VERSION%" == "" (
3737
@echo on
3838
popd
3939

40-
if "%CUDA_VERSION%" == "9" goto cuda_build_9
41-
if "%CUDA_VERSION%" == "10" goto cuda_build_10
42-
if "%CUDA_VERSION%" == "11" goto cuda_build_11
43-
goto cuda_build_end
40+
if not "%USE_CUDA%"=="1" goto cuda_build_end
4441

45-
:cuda_build_9
42+
set CUDA_PATH=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v%CUDA_VERSION%
4643

47-
set CUDA_PATH=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.2
48-
set CUDA_PATH_V9_2=%CUDA_PATH%
44+
rem version transformer, for example 10.1 to 10_1.
45+
set VERSION_SUFFIX=%CUDA_VERSION:.=_%
46+
set CUDA_PATH_V%VERSION_SUFFIX%=%CUDA_PATH%
4947

50-
goto cuda_build_common
51-
52-
:cuda_build_10
53-
54-
set CUDA_PATH=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1
55-
set CUDA_PATH_V10_1=%CUDA_PATH%
56-
57-
goto cuda_build_common
58-
59-
:cuda_build_11
60-
61-
set CUDA_PATH=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.1
62-
set CUDA_PATH_V11_1=%CUDA_PATH%
63-
64-
goto cuda_build_common
65-
66-
:cuda_build_common
48+
set CUDNN_LIB_DIR=%CUDA_PATH%\lib\x64
49+
set CUDA_TOOLKIT_ROOT_DIR=%CUDA_PATH%
50+
set CUDNN_ROOT_DIR=%CUDA_PATH%
51+
set NVTOOLSEXT_PATH=C:\Program Files\NVIDIA Corporation\NvToolsExt
52+
set PATH=%CUDA_PATH%\bin;%CUDA_PATH%\libnvvp;%PATH%
6753

6854
set CUDNN_LIB_DIR=%CUDA_PATH%\lib\x64
6955
set CUDA_TOOLKIT_ROOT_DIR=%CUDA_PATH%

0 commit comments

Comments
 (0)