|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +set -euxo pipefail |
| 4 | + |
| 5 | +./.github/scripts/setup-env.sh |
| 6 | + |
| 7 | +# Activate conda environment |
| 8 | +set +x && eval "$($(which conda) shell.bash hook)" && conda deactivate && conda activate ci && set -x |
| 9 | + |
| 10 | +# Setup the OS_TYPE environment variable that should be used for conditions involving the OS below. |
| 11 | +case $(uname) in |
| 12 | + Linux) |
| 13 | + OS_TYPE=linux |
| 14 | + ;; |
| 15 | + Darwin) |
| 16 | + OS_TYPE=macos |
| 17 | + ;; |
| 18 | + MSYS*) |
| 19 | + OS_TYPE=windows |
| 20 | + ;; |
| 21 | + *) |
| 22 | + echo "Unknown OS type:" $(uname) |
| 23 | + exit 1 |
| 24 | + ;; |
| 25 | +esac |
| 26 | + |
| 27 | +if [[ $OS_TYPE == macos ]]; then |
| 28 | + JOBS=$(sysctl -n hw.logicalcpu) |
| 29 | +else |
| 30 | + JOBS=$(nproc) |
| 31 | +fi |
| 32 | + |
| 33 | +TORCH_PATH=$(python -c "import pathlib, torch; print(pathlib.Path(torch.__path__[0]))") |
| 34 | +if [[ $OS_TYPE == windows ]]; then |
| 35 | + PACKAGING_DIR="${PWD}/packaging" |
| 36 | + export PATH="${TORCH_PATH}/lib:${PATH}" |
| 37 | +fi |
| 38 | + |
| 39 | +Torch_DIR="${TORCH_PATH}/share/cmake/Torch" |
| 40 | +if [[ "${GPU_ARCH_TYPE}" == "cuda" ]]; then |
| 41 | + WITH_CUDA=1 |
| 42 | +else |
| 43 | + WITH_CUDA=0 |
| 44 | +fi |
| 45 | + |
| 46 | +echo '::group::Prepare CMake builds' |
| 47 | +mkdir -p cpp_build |
| 48 | + |
| 49 | +pushd test/tracing/frcnn |
| 50 | +python trace_model.py |
| 51 | +mkdir -p build |
| 52 | +mv fasterrcnn_resnet50_fpn.pt build |
| 53 | +popd |
| 54 | + |
| 55 | +pushd examples/cpp/hello_world |
| 56 | +python trace_model.py |
| 57 | +mkdir -p build |
| 58 | +mv resnet18.pt build |
| 59 | +popd |
| 60 | + |
| 61 | +# This was only needed for the tracing above |
| 62 | +pip uninstall -y torchvision |
| 63 | +echo '::endgroup::' |
| 64 | + |
| 65 | +echo '::group::Build and install libtorchvision' |
| 66 | +pushd cpp_build |
| 67 | + |
| 68 | +# On macOS, CMake is looking for the library (*.dylib) and the header (*.h) separately. By default, it prefers to load |
| 69 | +# the header from other packages that install the library. This easily leads to a mismatch if the library installed |
| 70 | +# from conda doesn't have the exact same version. Thus, we need to explicitly set CMAKE_FIND_FRAMEWORK=NEVER to force |
| 71 | +# it to not load anything from other installed frameworks. Resources: |
| 72 | +# https://stackoverflow.com/questions/36523911/osx-homebrew-cmake-libpng-version-mismatch-issue |
| 73 | +# https://cmake.org/cmake/help/latest/variable/CMAKE_FIND_FRAMEWORK.html |
| 74 | +cmake .. -DTorch_DIR="${Torch_DIR}" -DWITH_CUDA="${WITH_CUDA}" \ |
| 75 | + -DCMAKE_PREFIX_PATH="${CONDA_PREFIX}" \ |
| 76 | + -DCMAKE_FIND_FRAMEWORK=NEVER \ |
| 77 | + -DCMAKE_INSTALL_PREFIX="${CONDA_PREFIX}" |
| 78 | +if [[ $OS_TYPE == windows ]]; then |
| 79 | + "${PACKAGING_DIR}/windows/internal/vc_env_helper.bat" "${PACKAGING_DIR}/windows/internal/build_cmake.bat" $JOBS |
| 80 | +else |
| 81 | + make -j$JOBS |
| 82 | + make install |
| 83 | +fi |
| 84 | + |
| 85 | +popd |
| 86 | +echo '::endgroup::' |
| 87 | + |
| 88 | +echo '::group::Build and run project that uses Faster-RCNN' |
| 89 | +pushd test/tracing/frcnn/build |
| 90 | + |
| 91 | +cmake .. -DTorch_DIR="${Torch_DIR}" -DWITH_CUDA="${WITH_CUDA}" \ |
| 92 | + -DCMAKE_PREFIX_PATH="${CONDA_PREFIX}" \ |
| 93 | + -DCMAKE_FIND_FRAMEWORK=NEVER |
| 94 | +if [[ $OS_TYPE == windows ]]; then |
| 95 | + "${PACKAGING_DIR}/windows/internal/vc_env_helper.bat" "${PACKAGING_DIR}/windows/internal/build_frcnn.bat" $JOBS |
| 96 | + cd Release |
| 97 | + cp ../fasterrcnn_resnet50_fpn.pt . |
| 98 | +else |
| 99 | + make -j$JOBS |
| 100 | +fi |
| 101 | + |
| 102 | +./test_frcnn_tracing |
| 103 | + |
| 104 | +popd |
| 105 | +echo '::endgroup::' |
| 106 | + |
| 107 | +echo '::group::Build and run C++ example' |
| 108 | +pushd examples/cpp/hello_world/build |
| 109 | + |
| 110 | +cmake .. -DTorch_DIR="${Torch_DIR}" \ |
| 111 | + -DCMAKE_PREFIX_PATH="${CONDA_PREFIX}" \ |
| 112 | + -DCMAKE_FIND_FRAMEWORK=NEVER |
| 113 | +if [[ $OS_TYPE == windows ]]; then |
| 114 | + "${PACKAGING_DIR}/windows/internal/vc_env_helper.bat" "${PACKAGING_DIR}/windows/internal/build_cpp_example.bat" $JOBS |
| 115 | + cd Release |
| 116 | + cp ../resnet18.pt . |
| 117 | +else |
| 118 | + make -j$JOBS |
| 119 | +fi |
| 120 | + |
| 121 | +./hello-world |
| 122 | + |
| 123 | +popd |
| 124 | +echo '::endgroup::' |
0 commit comments