build_cmake.sh 3.39 KB
Newer Older
1
2
3
#!/bin/bash
set -ex

4
5
6
7
8
PARALLELISM=8
if [ -n "$MAX_JOBS" ]; then
    PARALLELISM=$MAX_JOBS
fi

9
10
11
12
13
14
15
16
17
if [[ "$(uname)" != Darwin && "$OSTYPE" != "msys" ]]; then
    eval "$(./conda/bin/conda shell.bash hook)"
    conda activate ./env
fi

script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
. "$script_dir/pkg_helpers.bash"

export BUILD_TYPE=conda
Joao Gomes's avatar
Joao Gomes committed
18
setup_env 0.13.0
19
20
21
22
23
export SOURCE_ROOT_DIR="$PWD"
setup_conda_pytorch_constraint
setup_conda_cudatoolkit_plain_constraint

if [[ "$OSTYPE" == "msys" ]]; then
24
    conda install -yq conda-build cmake future
25
26
27
28
29
30
    pip install dataclasses
fi

setup_visual_studio_constraint
setup_junit_results_folder

31
32
33
34
35
36
37
38
if [[ "$(uname)" == Darwin ]]; then
  # TODO: this can be removed as soon as mkl's CMake support works with clang
  #  see https://github.com/pytorch/vision/pull/4203 for details
  MKL_CONSTRAINT='mkl==2021.2.0'
else
  MKL_CONSTRAINT=''
fi

39
40
41
42
43
44
if [[ $CONDA_BUILD_VARIANT == "cpu" ]]; then
  PYTORCH_MUTEX_CONSTRAINT='pytorch-mutex=1.0=cpu'
else
  PYTORCH_MUTEX_CONSTRAINT=''
fi

45
conda install -yq \pytorch=$PYTORCH_VERSION $CONDA_CUDATOOLKIT_CONSTRAINT $PYTORCH_MUTEX_CONSTRAINT $MKL_CONSTRAINT numpy -c nvidia -c "pytorch-${UPLOAD_CHANNEL}"
46
47
48
49
50
51
52
53
TORCH_PATH=$(dirname $(python -c "import torch; print(torch.__file__)"))

if [[ "$(uname)" == Darwin || "$OSTYPE" == "msys" ]]; then
    conda install -yq libpng jpeg
else
    yum install -y libpng-devel libjpeg-turbo-devel
fi

54
55
56
57
if [[ "$OSTYPE" == "msys" ]]; then
    source .circleci/unittest/windows/scripts/set_cuda_envs.sh
fi

58
59
60
61
62
63
64
65
mkdir cpp_build
pushd cpp_build

# Generate libtorchvision files
cmake .. -DTorch_DIR=$TORCH_PATH/share/cmake/Torch -DWITH_CUDA=$CMAKE_USE_CUDA

# Compile and install libtorchvision
if [[ "$OSTYPE" == "msys" ]]; then
66
    "$script_dir/windows/internal/vc_env_helper.bat" "$script_dir/windows/internal/build_cmake.bat" $PARALLELISM
67
68
69
    CONDA_PATH=$(dirname $(which python))
    cp -r "C:/Program Files (x86)/torchvision/include/torchvision" $CONDA_PATH/include
else
70
    make -j$PARALLELISM
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
    make install

    if [[ "$(uname)" == Darwin ]]; then
        CONDA_PATH=$(dirname $(dirname $(which python)))
        cp -r /usr/local/include/torchvision $CONDA_PATH/include/
        export C_INCLUDE_PATH=/usr/local/include
        export CPLUS_INCLUDE_PATH=/usr/local/include
    fi
fi

popd

# Install torchvision locally
python setup.py develop

# Trace, compile and run project that uses Faster-RCNN
87
pushd test/tracing/frcnn
88
89
90
91
92
93
94
95
96
mkdir build

# Trace model
python trace_model.py
cp fasterrcnn_resnet50_fpn.pt build

cd build
cmake .. -DTorch_DIR=$TORCH_PATH/share/cmake/Torch -DWITH_CUDA=$CMAKE_USE_CUDA
if [[ "$OSTYPE" == "msys" ]]; then
97
    "$script_dir/windows/internal/vc_env_helper.bat" "$script_dir/windows/internal/build_frcnn.bat" $PARALLELISM
98
99
100
101
    mv fasterrcnn_resnet50_fpn.pt Release
    cd Release
    export PATH=$(cygpath "C:/Program Files (x86)/torchvision/bin"):$(cygpath $TORCH_PATH)/lib:$PATH
else
102
    make -j$PARALLELISM
103
104
105
106
fi

# Run traced program
./test_frcnn_tracing
107
108
109
110
111

# Compile and run the CPP example
popd
cd examples/cpp/hello_world
mkdir build
112
113
114
115
116

# Trace model
python trace_model.py
cp resnet18.pt build

117
118
119
120
cd build
cmake .. -DTorch_DIR=$TORCH_PATH/share/cmake/Torch

if [[ "$OSTYPE" == "msys" ]]; then
121
    "$script_dir/windows/internal/vc_env_helper.bat" "$script_dir/windows/internal/build_cpp_example.bat" $PARALLELISM
122
    mv resnet18.pt Release
123
124
    cd Release
else
125
    make -j$PARALLELISM
126
127
128
129
fi

# Run CPP example
./hello-world