Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrate cmake workflows from CircleCI to GHA #7417

Merged
merged 67 commits into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
502d5da
migrate cmake workflows from CircleCI to GHA
pmeier Mar 14, 2023
436f3ae
Merge branch 'main' into cmake-gha
pmeier May 9, 2023
29373c0
update
pmeier May 9, 2023
f9c371c
[REVERTME] disable unrelated CI
pmeier May 9, 2023
e69c38c
standalone cmake build
pmeier May 9, 2023
3abebff
fix parallelism
pmeier May 9, 2023
5824c74
fix naming
pmeier May 9, 2023
399f545
trigger CI
pmeier May 10, 2023
fb4a55c
put back lint to debug
pmeier May 10, 2023
de5d298
Revert "[REVERTME] disable unrelated CI"
pmeier May 10, 2023
14e2e6d
Merge branch 'main' into cmake-gha
pmeier May 10, 2023
db44fef
allow unset MAX_JOBS
pmeier May 10, 2023
405ea39
use full cmake script
pmeier May 10, 2023
58c5394
refactor
pmeier May 10, 2023
6ed5400
add support for macOS and Windows
pmeier May 10, 2023
426887f
remove parallelism flag
pmeier May 10, 2023
298a236
trigger CI
pmeier May 10, 2023
1af9dbb
trigger CI
pmeier May 11, 2023
1dc42f9
fix naming
pmeier May 11, 2023
16d0293
consolidate workflows
pmeier May 11, 2023
b0ca52b
Merge branch 'main' into cmake-gha
pmeier May 11, 2023
40eecae
fix cmake install prefix
pmeier May 11, 2023
280868a
fix torchdir on Windows
pmeier May 11, 2023
82c038a
also uninstall system libpng on macos x86
pmeier May 11, 2023
26c6d86
put back parallel builds
pmeier May 11, 2023
7917396
try windows helper
pmeier May 11, 2023
e28f1cb
fix number of jobs on macos
pmeier May 11, 2023
7cec87c
try adding more to the PATH on Windows
pmeier May 11, 2023
0dc5587
reenable the examples
pmeier May 11, 2023
ca04d9c
fix parallel
pmeier May 11, 2023
3d01320
fix windows examples
pmeier May 11, 2023
3a46510
reduce verbosity during conda eval
pmeier May 11, 2023
2aea9bb
fix Windows CUDA
pmeier May 11, 2023
d88228d
add debug print
pmeier May 11, 2023
33a4df1
fix prefix path
pmeier May 11, 2023
08ae9e4
try fix windows
pmeier May 11, 2023
64d2b0e
revert unrelated
pmeier May 11, 2023
f1e1201
add find debug
pmeier May 11, 2023
ce90113
trigger CI
pmeier May 11, 2023
10a6b80
add more debug
pmeier May 12, 2023
534147d
use otool
pmeier May 12, 2023
0f7f126
set CMAKE_FIND_FRAMEWORK
pmeier May 12, 2023
8048e47
fix otool invocation
pmeier May 12, 2023
c6e77d2
drop otool
pmeier May 12, 2023
8a3f9d7
remove debug and add comments
pmeier May 12, 2023
27725ca
disable windows for now
pmeier May 12, 2023
9db8e0c
remove CMake find debug
pmeier May 12, 2023
b056963
remove unnecessary path
pmeier May 12, 2023
1d213c5
put windows CPU back
pmeier May 12, 2023
9c6f463
fix inline comments
pmeier May 12, 2023
1938a0d
add torch to PATH on Windows
pmeier May 12, 2023
1ec0514
fix TORCH_PATH
pmeier May 12, 2023
1db13d6
fix TORCH_PATH on Windows
pmeier May 12, 2023
9f8f48c
put Windows GPU jobs back
pmeier May 12, 2023
c4a5802
Merge branch 'main' into cmake-gha
pmeier May 16, 2023
72835b9
try nuclear CUDA reinstall on GPU runner
pmeier May 16, 2023
427c82e
add find debug for CUDA
pmeier May 16, 2023
862f268
dont delete extracted file
pmeier May 16, 2023
9baaf70
Change integration path to reflect new AMI
atalman May 19, 2023
9a86559
CXX_STANDARD 14 -> 17
pmeier May 20, 2023
b43ee33
Merge branch 'main' into cmake-gha
pmeier May 20, 2023
24e0b2b
Merge branch 'main' into cmake-gha
pmeier May 20, 2023
d0f41ce
cleanup
pmeier May 20, 2023
b98cf3e
add ref
pmeier May 20, 2023
c7a860f
Merge branch 'main' into cmake-gha
pmeier May 22, 2023
0b91c3d
Merge branch 'main' into cmake-gha
pmeier May 23, 2023
79ae3e6
CUDA 11.7 -> 11.8
pmeier May 23, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 124 additions & 0 deletions .github/scripts/cmake.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
#!/usr/bin/env bash
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


set -euxo pipefail

./.github/scripts/setup-env.sh

# Activate conda environment
set +x && eval "$($(which conda) shell.bash hook)" && conda deactivate && conda activate ci && set -x

# Setup the OS_TYPE environment variable that should be used for conditions involving the OS below.
case $(uname) in
Linux)
OS_TYPE=linux
;;
Darwin)
OS_TYPE=macos
;;
MSYS*)
OS_TYPE=windows
;;
*)
echo "Unknown OS type:" $(uname)
exit 1
;;
esac

if [[ $OS_TYPE == macos ]]; then
JOBS=$(sysctl -n hw.logicalcpu)
else
JOBS=$(nproc)
fi

TORCH_PATH=$(python -c "import pathlib, torch; print(pathlib.Path(torch.__path__[0]))")
if [[ $OS_TYPE == windows ]]; then
PACKAGING_DIR="${PWD}/packaging"
export PATH="${TORCH_PATH}/lib:${PATH}"
fi

Torch_DIR="${TORCH_PATH}/share/cmake/Torch"
if [[ "${GPU_ARCH_TYPE}" == "cuda" ]]; then
WITH_CUDA=1
else
WITH_CUDA=0
fi

echo '::group::Prepare CMake builds'
mkdir -p cpp_build

pushd test/tracing/frcnn
python trace_model.py
mkdir -p build
mv fasterrcnn_resnet50_fpn.pt build
popd

pushd examples/cpp/hello_world
python trace_model.py
mkdir -p build
mv resnet18.pt build
popd

# This was only needed for the tracing above
pip uninstall -y torchvision
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not needed, but we are making sure here that we don't need to have a torchvision Python install for anything below.

echo '::endgroup::'

echo '::group::Build and install libtorchvision'
pushd cpp_build

# On macOS, CMake is looking for the library (*.dylib) and the header (*.h) separately. By default, it prefers to load
# the header from other packages that install the library. This easily leads to a mismatch if the library installed
# from conda doesn't have the exact same version. Thus, we need to explicitly set CMAKE_FIND_FRAMEWORK=NEVER to force
# it to not load anything from other installed frameworks. Resources:
# https://stackoverflow.com/questions/36523911/osx-homebrew-cmake-libpng-version-mismatch-issue
# https://cmake.org/cmake/help/latest/variable/CMAKE_FIND_FRAMEWORK.html
cmake .. -DTorch_DIR="${Torch_DIR}" -DWITH_CUDA="${WITH_CUDA}" \
-DCMAKE_PREFIX_PATH="${CONDA_PREFIX}" \
-DCMAKE_FIND_FRAMEWORK=NEVER \
-DCMAKE_INSTALL_PREFIX="${CONDA_PREFIX}"
if [[ $OS_TYPE == windows ]]; then
"${PACKAGING_DIR}/windows/internal/vc_env_helper.bat" "${PACKAGING_DIR}/windows/internal/build_cmake.bat" $JOBS
else
make -j$JOBS
make install
fi

popd
echo '::endgroup::'

echo '::group::Build and run project that uses Faster-RCNN'
pushd test/tracing/frcnn/build

cmake .. -DTorch_DIR="${Torch_DIR}" -DWITH_CUDA="${WITH_CUDA}" \
-DCMAKE_PREFIX_PATH="${CONDA_PREFIX}" \
-DCMAKE_FIND_FRAMEWORK=NEVER
if [[ $OS_TYPE == windows ]]; then
"${PACKAGING_DIR}/windows/internal/vc_env_helper.bat" "${PACKAGING_DIR}/windows/internal/build_frcnn.bat" $JOBS
cd Release
cp ../fasterrcnn_resnet50_fpn.pt .
else
make -j$JOBS
fi

./test_frcnn_tracing

popd
echo '::endgroup::'

echo '::group::Build and run C++ example'
pushd examples/cpp/hello_world/build

cmake .. -DTorch_DIR="${Torch_DIR}" \
-DCMAKE_PREFIX_PATH="${CONDA_PREFIX}" \
-DCMAKE_FIND_FRAMEWORK=NEVER
if [[ $OS_TYPE == windows ]]; then
"${PACKAGING_DIR}/windows/internal/vc_env_helper.bat" "${PACKAGING_DIR}/windows/internal/build_cpp_example.bat" $JOBS
cd Release
cp ../resnet18.pt .
else
make -j$JOBS
fi

./hello-world

popd
echo '::endgroup::'
19 changes: 9 additions & 10 deletions .github/scripts/setup-env.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#!/usr/bin/env bash

set -euo pipefail
set -euxo pipefail

# Prepare conda
CONDA_PATH=$(which conda)
eval "$(${CONDA_PATH} shell.bash hook)"
set +x && eval "$($(which conda) shell.bash hook)" && set -x

# Setup the OS_TYPE environment variable that should be used for conditions involving the OS below.
case $(uname) in
Expand All @@ -25,12 +24,12 @@ esac

if [[ "${OS_TYPE}" == "macos" && $(uname -m) == x86_64 ]]; then
echo '::group::Uninstall system JPEG libraries on macOS'
# The x86 macOS runners, e.g. the GitHub Actions native "macos-12" runner, has some JPEG libraries installed by
# default that interfere with our build. We uninstall them here and use the one from conda below.
JPEG_LIBS=$(brew list | grep jpeg)
echo $JPEG_LIBS
for lib in $JPEG_LIBS; do
brew uninstall --ignore-dependencies --force $lib || true
# The x86 macOS runners, e.g. the GitHub Actions native "macos-12" runner, has some JPEG and PNG libraries
# installed by default that interfere with our build. We uninstall them here and use the one from conda below.
IMAGE_LIBS=$(brew list | grep -E "jpeg|png")
echo "${IMAGE_LIBS}"
for lib in "${IMAGE_LIBS}"; do
brew uninstall --ignore-dependencies --force "${lib}" || true
done
echo '::endgroup::'
fi
Expand All @@ -41,7 +40,7 @@ conda create \
--name ci \
--quiet --yes \
python="${PYTHON_VERSION}" pip \
ninja \
ninja cmake \
libpng jpeg \
'ffmpeg<4.3'
conda activate ci
Expand Down
92 changes: 92 additions & 0 deletions .github/workflows/build-cmake.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
name: CMake

on:
pull_request:
push:
branches:
- nightly
- main
- release/*
workflow_dispatch:

jobs:
linux:
strategy:
matrix:
include:
- runner: linux.12xlarge
gpu-arch-type: cpu
- runner: linux.g5.4xlarge.nvidia.gpu
gpu-arch-type: cuda
gpu-arch-version: "11.8"
fail-fast: false
uses: pytorch/test-infra/.github/workflows/linux_job.yml@main
with:
repository: pytorch/vision
runner: ${{ matrix.runner }}
gpu-arch-type: ${{ matrix.gpu-arch-type }}
gpu-arch-version: ${{ matrix.gpu-arch-version }}
script: |
set -euo pipefail

export PYTHON_VERSION=3.8
export GPU_ARCH_TYPE=${{ matrix.gpu-arch-type }}
export GPU_ARCH_VERSION=${{ matrix.gpu-arch-version }}

./.github/scripts/cmake.sh

macos:
strategy:
matrix:
include:
- runner: macos-12
- runner: macos-m1-12
fail-fast: false
uses: pytorch/test-infra/.github/workflows/macos_job.yml@main
with:
repository: pytorch/vision
runner: ${{ matrix.runner }}
script: |
set -euo pipefail

export PYTHON_VERSION=3.8
export GPU_ARCH_TYPE=cpu
export GPU_ARCH_VERSION=''

./.github/scripts/cmake.sh

windows:
strategy:
matrix:
include:
- runner: windows.4xlarge
gpu-arch-type: cpu
- runner: windows.g5.4xlarge.nvidia.gpu
gpu-arch-type: cuda
gpu-arch-version: "11.8"
fail-fast: false
uses: pytorch/test-infra/.github/workflows/windows_job.yml@main
with:
repository: pytorch/vision
runner: ${{ matrix.runner }}
gpu-arch-type: ${{ matrix.gpu-arch-type }}
gpu-arch-version: ${{ matrix.gpu-arch-version }}
script: |
set -euo pipefail

source packaging/windows/internal/vc_install_helper.sh

# FIXME: Basically, we are reinstalling CUDA here. We only need this, because we need to copy some files that
# can be extracted from the CUDA installer, but are not available on our Windows AMI.
# See https://github.com/pytorch/test-infra/pull/4189
if [[ ${{ matrix.gpu-arch-type }} == cuda ]]; then
export CU_VERSION=cu$(echo ${{ matrix.gpu-arch-version }} | sed 's/\.//')
echo CU_VERSION="${CU_VERSION}"
packaging/windows/internal/cuda_install.bat
fi
Comment on lines +82 to +86
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@atalman Ideally, we don't need to reinstall CUDA here. We only do this to get access to your patch from 9baaf70. Could we include these files in the AMI directly?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@atalman atalman May 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HI @pmeir yes totally. However I think we should ship this PR for now calling packaging/windows/internal/cuda_install.bat . I will create new AMI and test it. Once new AMI is built we can remove this change.


export PYTHON_VERSION=3.8
export GPU_ARCH_TYPE=${{ matrix.gpu-arch-type }}
export GPU_ARCH_VERSION=${{ matrix.gpu-arch-version }}

./.github/scripts/cmake.sh
14 changes: 3 additions & 11 deletions packaging/windows/internal/cuda_install.bat
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,9 @@ echo %errorlevel%

popd

echo Installing VS integration...
rem It's for VS 2019
if "%CUDA_VER_MAJOR%" == "10" (
xcopy /Y "%SRC_DIR%\temp_build\cuda\CUDAVisualStudioIntegration\extras\visual_studio_integration\MSBuildExtensions\*.*" "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\BuildCustomizations"
)
if "%CUDA_VER_MAJOR%" == "11" (
xcopy /Y "%SRC_DIR%\temp_build\cuda\visual_studio_integration\CUDAVisualStudioIntegration\extras\visual_studio_integration\MSBuildExtensions\*.*" "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\BuildCustomizations"
)
echo Installing VS 2019 integration...
xcopy /YI "%SRC_DIR%\temp_build\cuda\visual_studio_integration\CUDAVisualStudioIntegration\extras\visual_studio_integration\MSBuildExtensions\*.*" "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Microsoft\VC\v160\BuildCustomizations"


echo Installing NvToolsExt...
7z x %SRC_DIR%\temp_build\NvToolsExt.7z -o"%SRC_DIR%\temp_build\NvToolsExt"
Expand Down Expand Up @@ -165,6 +160,3 @@ echo Installing cuDNN...
xcopy /Y "%SRC_DIR%\temp_build\cudnn\%CUDNN_FOLDER%\bin\*.*" "%ProgramFiles%\NVIDIA GPU Computing Toolkit\CUDA\v%CUDA_VERSION_STR%\bin"
xcopy /Y "%SRC_DIR%\temp_build\cudnn\%CUDNN_FOLDER%\%CUDNN_LIB_FOLDER%\*.*" "%ProgramFiles%\NVIDIA GPU Computing Toolkit\CUDA\v%CUDA_VERSION_STR%\lib\x64"
xcopy /Y "%SRC_DIR%\temp_build\cudnn\%CUDNN_FOLDER%\include\*.*" "%ProgramFiles%\NVIDIA GPU Computing Toolkit\CUDA\v%CUDA_VERSION_STR%\include"

echo Cleaning temp files
rd /s /q "%SRC_DIR%\temp_build" || ver > nul