Skip to content

Commit d67b8f6

Browse files
committed
Switch DESIRED_CUDA -> GPU_ARCH_{TYPE,VERSION}
Switches most of the usages for building with DESIRED_CUDA to utilize the new environment variables of GPU_ARCH_TYPE / GPU_ARCH_VERSION Signed-off-by: Eli Uriegas <[email protected]>
1 parent c2c3243 commit d67b8f6

File tree

11 files changed

+39
-647
lines changed

11 files changed

+39
-647
lines changed

check_binary.sh

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ set -eux -o pipefail
1313
# 8. Magma is available for CUDA builds
1414
# 9. CuDNN is available for CUDA builds
1515
#
16-
# This script needs the env variables DESIRED_PYTHON, DESIRED_CUDA,
16+
# This script needs the env variables DESIRED_PYTHON, GPU_ARCH_VERSION
1717
# DESIRED_DEVTOOLSET and PACKAGE_TYPE
1818
#
1919
# This script expects PyTorch to be installed into the active Python (the
@@ -38,14 +38,9 @@ else
3838
install_root="$(dirname $(which python))/../lib/python${py_dot}/site-packages/torch/"
3939
fi
4040

41-
if [[ "$DESIRED_CUDA" != 'cpu' && "$DESIRED_CUDA" != *"rocm"* ]]; then
42-
# cu90, cu92, cu100, cu101
43-
if [[ ${#DESIRED_CUDA} -eq 4 ]]; then
44-
CUDA_VERSION="${DESIRED_CUDA:2:1}.${DESIRED_CUDA:3:1}"
45-
elif [[ ${#DESIRED_CUDA} -eq 5 ]]; then
46-
CUDA_VERSION="${DESIRED_CUDA:2:2}.${DESIRED_CUDA:4:1}"
47-
fi
48-
echo "Using CUDA $CUDA_VERSION as determined by DESIRED_CUDA"
41+
if [[ "$GPU_ARCH_TYPE" = 'cuda' ]]; then
42+
CUDA_VERSION=${GPU_ARCH_VERSION}
43+
echo "Using CUDA $CUDA_VERSION as determined by GPU_ARCH_VERSION"
4944

5045
# Switch `/usr/local/cuda` to the desired CUDA version
5146
rm -rf /usr/local/cuda || true
@@ -366,7 +361,7 @@ if [[ "$OSTYPE" == "msys" ]]; then
366361
fi
367362

368363
# Test that CUDA builds are setup correctly
369-
if [[ "$DESIRED_CUDA" != 'cpu' && "$DESIRED_CUDA" != *"rocm"* ]]; then
364+
if [[ "$GPU_ARCH_TYPE" == 'cuda' ]]; then
370365
if [[ "$PACKAGE_TYPE" == 'libtorch' ]]; then
371366
build_and_run_example_cpp check-torch-cuda
372367
else

conda/Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,26 +43,32 @@ RUN bash ./install_conda.sh && rm install_conda.sh
4343
FROM base as cuda
4444
RUN rm -rf /usr/local/cuda-*
4545
ADD ./common/install_cuda.sh install_cuda.sh
46+
ENV GPU_ARCH_TYPE=cuda
4647

4748
FROM cuda as cuda10.2
4849
RUN bash ./install_cuda.sh 10.2
4950
ENV DESIRED_CUDA=10.2
51+
ENV GPU_ARCH_TYPE=10.2
5052

5153
FROM cuda as cuda11.3
5254
RUN bash ./install_cuda.sh 11.3
5355
ENV DESIRED_CUDA=11.3
56+
ENV GPU_ARCH_TYPE=11.3
5457

5558
FROM cuda as cuda11.5
5659
RUN bash ./install_cuda.sh 11.5
5760
ENV DESIRED_CUDA=11.5
61+
ENV GPU_ARCH_TYPE=11.5
5862

5963
FROM cuda as cuda11.6
6064
RUN bash ./install_cuda.sh 11.6
6165
ENV DESIRED_CUDA=11.6
66+
ENV GPU_ARCH_TYPE=11.6
6267

6368
FROM cuda as cuda11.7
6469
RUN bash ./install_cuda.sh 11.7
6570
ENV DESIRED_CUDA=11.7
71+
ENV GPU_ARCH_TYPE=11.7
6672

6773
# Install MNIST test data
6874
FROM base as mnist

conda/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ docker push pytorch/conda-builder
2020
# building pytorch
2121
docker run --rm -it \
2222
-e PACKAGE_TYPE=conda \
23-
-e DESIRED_CUDA=cu92 \
2423
-e DESIRED_PYTHON=3.8 \
2524
-e PYTORCH_BUILD_VERSION=1.5.0 \
2625
-e PYTORCH_BUILD_NUMBER=1 \

conda/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
# TODO: Remove this once we fully move binary builds on master to GHA
66

77
SCRIPTPATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
8-
DESIRED_CUDA=${DESIRED_CUDA:-cpu} bash ${SCRIPTPATH}/build_pytorch.sh
8+
bash ${SCRIPTPATH}/build_pytorch.sh

conda/build_pytorch.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ retry () {
3333

3434
# Parse arguments and determmine version
3535
###########################################################
36-
if [[ -n "$DESIRED_CUDA" && -n "$PYTORCH_BUILD_VERSION" && -n "$PYTORCH_BUILD_NUMBER" ]]; then
37-
desired_cuda="$DESIRED_CUDA"
36+
if [[ -n "$GPU_ARCH_VERSION" && -n "$PYTORCH_BUILD_VERSION" && -n "$PYTORCH_BUILD_NUMBER" ]]; then
37+
desired_cuda="$GPU_ARCH_VERSION"
3838
build_version="$PYTORCH_BUILD_VERSION"
3939
build_number="$PYTORCH_BUILD_NUMBER"
4040
else
@@ -49,9 +49,11 @@ else
4949
build_version="$2"
5050
build_number="$3"
5151
fi
52-
if [[ "$desired_cuda" != cpu ]]; then
53-
desired_cuda="$(echo $desired_cuda | tr -d cuda. )"
52+
53+
if [[ $desired_cuda = "" ]]; then
54+
desired_cuda="cpu"
5455
fi
56+
5557
echo "Building cuda version $desired_cuda and pytorch version: $build_version build_number: $build_number"
5658

5759
if [[ "$OSTYPE" == "msys" ]]; then

manywheel/build_common.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ else
147147
export LLVM_DIR="$USE_LLVM/lib/cmake/llvm"
148148
fi
149149

150-
if [[ "$DESIRED_CUDA" == *"rocm"* ]]; then
150+
if [[ "$GPU_ARCH_TYPE" = "rocm" ]]; then
151151
echo "Calling build_amd.py at $(date)"
152152
python tools/amd_build/build_amd.py
153153
fi
@@ -326,7 +326,7 @@ for pkg in /$WHEELHOUSE_DIR/torch*linux*.whl /$LIBTORCH_HOUSE_DIR/libtorch*.zip;
326326
fi
327327

328328
# ROCm workaround for roctracer dlopens
329-
if [[ "$DESIRED_CUDA" == *"rocm"* ]]; then
329+
if [[ "${GPU_ARCH_TYPE}" = "rocm" ]]; then
330330
patchedpath=$(fname_without_so_number $destpath)
331331
else
332332
patchedpath=$(fname_with_sha256 $destpath)
@@ -459,7 +459,10 @@ if [[ -z "$BUILD_PYTHONLESS" ]]; then
459459
echo "$(date) :: Running tests"
460460
pushd "$PYTORCH_ROOT"
461461
LD_LIBRARY_PATH=/usr/local/nvidia/lib64 \
462-
"${SOURCE_DIR}/../run_tests.sh" manywheel "${py_majmin}" "$DESIRED_CUDA"
462+
PACAKGE_TYPE=manywheel \
463+
DESIRED_PYTHON="${py_majmin}" \
464+
GPU_ARCH_TYPE=${GPU_ARCH_TYPE} \
465+
"${SOURCE_DIR}/../run_tests.sh"
463466
popd
464467
echo "$(date) :: Finished tests"
465468
fi

manywheel/build_cuda.sh

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,17 @@ if [[ -z "$EXTRA_CAFFE2_CMAKE_FLAGS" ]]; then
2424
EXTRA_CAFFE2_CMAKE_FLAGS=()
2525
fi
2626

27+
2728
# Determine CUDA version and architectures to build for
28-
#
29-
# NOTE: We should first check `DESIRED_CUDA` when determining `CUDA_VERSION`,
30-
# because in some cases a single Docker image can have multiple CUDA versions
31-
# on it, and `nvcc --version` might not show the CUDA version we want.
32-
if [[ -n "$DESIRED_CUDA" ]]; then
33-
# If the DESIRED_CUDA already matches the format that we expect
34-
if [[ ${DESIRED_CUDA} =~ ^[0-9]+\.[0-9]+$ ]]; then
35-
CUDA_VERSION=${DESIRED_CUDA}
36-
else
37-
# cu90, cu92, cu100, cu101
38-
if [[ ${#DESIRED_CUDA} -eq 4 ]]; then
39-
CUDA_VERSION="${DESIRED_CUDA:2:1}.${DESIRED_CUDA:3:1}"
40-
elif [[ ${#DESIRED_CUDA} -eq 5 ]]; then
41-
CUDA_VERSION="${DESIRED_CUDA:2:2}.${DESIRED_CUDA:4:1}"
42-
fi
43-
fi
44-
echo "Using CUDA $CUDA_VERSION as determined by DESIRED_CUDA"
29+
if [[ -n "$GPU_ARCH_VERSION" ]]; then
30+
# CUDA_VERSION should look like ${MAJOR}.${MINOR} (ex. 11.2)
31+
CUDA_VERSION="${GPU_ARCH_VERSION:-}"
4532

4633
# There really has to be a better way to do this - eli
4734
# Possibly limiting builds to specific cuda versions be delimiting images would be a choice
4835
if [[ "$OS_NAME" == *"Ubuntu"* ]]; then
49-
echo "Switching to CUDA version $desired_cuda"
50-
/builder/conda/switch_cuda_version.sh "${DESIRED_CUDA}"
36+
echo "Switching to CUDA version ${CUDA_VERSION}"
37+
/builder/conda/switch_cuda_version.sh "${CUDA_VERSION}"
5138
fi
5239
else
5340
CUDA_VERSION=$(nvcc --version|grep release|cut -f5 -d" "|cut -f1 -d",")
@@ -273,9 +260,6 @@ else
273260
exit 1
274261
fi
275262

276-
# builder/test.sh requires DESIRED_CUDA to know what tests to exclude
277-
export DESIRED_CUDA="$cuda_version_nodot"
278-
279263
# Switch `/usr/local/cuda` to the desired CUDA version
280264
rm -rf /usr/local/cuda || true
281265
ln -s "/usr/local/cuda-${CUDA_VERSION}" /usr/local/cuda

manywheel/build_libtorch.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ else
113113
export LLVM_DIR="$USE_LLVM/lib/cmake/llvm"
114114
fi
115115

116-
if [[ "$DESIRED_CUDA" == *"rocm"* ]]; then
116+
if [[ "$GPU_ARCH_TYPE" = "rocm" ]]; then
117117
echo "Calling build_amd.py at $(date)"
118118
python tools/amd_build/build_amd.py
119119
# TODO remove this work-around once pytorch sources are updated

manywheel/build_rocm.sh

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,8 @@ if [[ -z "$EXTRA_CAFFE2_CMAKE_FLAGS" ]]; then
2525
fi
2626

2727
# Determine ROCm version and architectures to build for
28-
#
29-
# NOTE: We should first check `DESIRED_CUDA` when determining `ROCM_VERSION`
30-
if [[ -n "$DESIRED_CUDA" ]]; then
31-
if ! echo "${DESIRED_CUDA}"| grep "^rocm" >/dev/null 2>/dev/null; then
32-
export DESIRED_CUDA="rocm${DESIRED_CUDA}"
33-
fi
34-
# rocm3.7, rocm3.5.1
35-
ROCM_VERSION="$DESIRED_CUDA"
36-
echo "Using $ROCM_VERSION as determined by DESIRED_CUDA"
37-
else
38-
echo "Must set DESIRED_CUDA"
39-
exit 1
40-
fi
28+
ROCM_VERSION="$GPU_ARCH_VERSION"
29+
echo "Using $ROCM_VERSION as determined by GPU_ARCH_VERSION"
4130

4231
# Package directories
4332
WHEELHOUSE_DIR="wheelhouse$ROCM_VERSION"

0 commit comments

Comments
 (0)