Skip to content

Commit 4bf0202

Browse files
authored
[build] Have PyTorch depend on minimal libcaffe2.so instead of libATen.so (pytorch#7399)
* Have PyTorch depend on minimal libcaffe2.so instead of libATen.so * Build ATen tests as a part of Caffe2 build * Hopefully cufft and nvcc fPIC fixes * Make ATen install components optional * Add tests back for ATen and fix TH build * Fixes for test_install.sh script * Fixes for cpp_build/build_all.sh * Fixes for aten/tools/run_tests.sh * Switch ATen cmake calls to USE_CUDA instead of NO_CUDA * Attempt at fix for aten/tools/run_tests.sh * Fix typo in last commit * Fix valgrind call after pushd * Be forgiving about USE_CUDA disable like PyTorch * More fixes on the install side * Link all libcaffe2 during test run * Make cuDNN optional for ATen right now * Potential fix for non-CUDA builds * Use NCCL_ROOT_DIR environment variable * Pass -fPIC through nvcc to base compiler/linker * Remove THCUNN.h requirement for libtorch gen * Add Mac test for -Wmaybe-uninitialized * Potential Windows and Mac fixes * Move MSVC target props to shared function * Disable cpp_build/libtorch tests on Mac * Disable sleef for Windows builds * Move protos under BUILD_CAFFE2 * Remove space from linker flags passed with -Wl * Remove ATen from Caffe2 dep libs since directly included * Potential Windows fixes * Preserve options while sleef builds * Force BUILD_SHARED_LIBS flag for Caffe2 builds * Set DYLD_LIBRARY_PATH and LD_LIBRARY_PATH for Mac testing * Pass TORCH_CUDA_ARCH_LIST directly in cuda.cmake * Fixes for the last two changes * Potential fix for Mac build failure * Switch Caffe2 to build_caffe2 dir to not conflict * Cleanup FindMKL.cmake * Another attempt at Mac cpp_build fix * Clear cpp-build directory for Mac builds * Disable test in Mac build/test to match cmake
1 parent f9633b9 commit 4bf0202

Some content is hidden

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

53 files changed

+1843
-1600
lines changed

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ torch/lib/*.lib
2525
torch/lib/*.dylib*
2626
torch/lib/*.h
2727
torch/lib/build
28+
torch/lib/cmake
29+
torch/lib/pkgconfig
30+
torch/lib/protoc
2831
torch/lib/tmp_install
2932
torch/lib/include
3033
torch/lib/torch_shm_manager
@@ -150,7 +153,7 @@ build
150153
build_host_protoc
151154
build_android
152155
build_ios
153-
build_*
156+
/build_*
154157
.build_debug/*
155158
.build_release/*
156159
distribute/*

.jenkins/caffe2/build.sh

+6-3
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,12 @@ if [[ "${BUILD_ENVIRONMENT}" == conda* ]]; then
9696
exit 0
9797
fi
9898

99-
# Run cmake from ./build directory
100-
mkdir -p ./build
101-
cd ./build
99+
# Run cmake from ./build_caffe2 directory so it doesn't conflict with
100+
# standard PyTorch build directory. Eventually these won't need to
101+
# be separate.
102+
rm -rf build_caffe2
103+
mkdir build_caffe2
104+
cd ./build_caffe2
102105

103106
INSTALL_PREFIX="/usr/local/caffe2"
104107
CMAKE_ARGS+=("-DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX}")

.jenkins/pytorch/build.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ fi
3535

3636
WERROR=1 python setup.py install
3737

38-
# Add the ATen test binaries so that they won't be git clean'ed away
39-
git add -f aten/build/src/ATen/test
38+
# Add the test binaries so that they won't be git clean'ed away
39+
git add -f build/bin
4040

4141
# Testing ATen install
4242
if [[ "$BUILD_ENVIRONMENT" != *cuda* ]]; then

.jenkins/pytorch/dirty.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ set -ex
33
upstream="$1"
44
pr="$2"
55
git diff --name-only "$upstream" "$pr"
6-
git diff --name-only "$upstream" "$pr" | grep -Eq '^(aten/|.jenkins/pytorch|docs/(make.bat|Makefile|requirements.txt|source)|mypy|requirements.txt|setup.py|test/|third_party/|tools/|\.gitmodules|torch/)'
6+
git diff --name-only "$upstream" "$pr" | grep -Eq '^(aten/|caffe2/|.jenkins/pytorch|docs/(make.bat|Makefile|requirements.txt|source)|mypy|requirements.txt|setup.py|test/|third_party/|tools/|\.gitmodules|torch/)'

.jenkins/pytorch/macos-build-test.sh

+12-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,18 @@ python test/run_test.py --verbose
2828

2929
# NB: Install outside of source directory (at the same level as the root
3030
# pytorch folder) so that it doesn't get cleaned away prior to docker push.
31+
# But still clean it before we perform our own build.
32+
#
3133
CPP_BUILD="$PWD/../cpp-build"
34+
rm -rf $CPP_BUILD
35+
mkdir -p $CPP_BUILD
3236
WERROR=1 VERBOSE=1 tools/cpp_build/build_all.sh "$CPP_BUILD"
3337

34-
python tools/download_mnist.py --quiet -d test/cpp/api/mnist
35-
"$CPP_BUILD"/libtorch/bin/test_api
38+
# TODO; Enable tests on Mac as soon as possible
39+
#python tools/download_mnist.py --quiet -d test/cpp/api/mnist
40+
#
41+
# # Unfortunately it seems like the test can't load from miniconda3
42+
# # without these paths being set
43+
# export DYLD_LIBRARY_PATH="$DYLD_LIBRARY_PATH:$PWD/miniconda3/lib"
44+
# export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$PWD/miniconda3/lib"
45+
# "$CPP_BUILD"/libtorch/bin/test_api

.jenkins/pytorch/test.sh

+4-3
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,14 @@ time python test/run_test.py --verbose
3131

3232
# Test ATen
3333
if [[ "$BUILD_ENVIRONMENT" != *asan* ]]; then
34-
echo "Testing ATen"
34+
echo "Running ATen tests with pytorch lib"
3535
TORCH_LIB_PATH=$(python -c "import site; print(site.getsitepackages()[0])")/torch/lib
3636
# NB: the ATen test binaries don't have RPATH set, so it's necessary to
3737
# put the dynamic libraries somewhere were the dynamic linker can find them.
3838
# This is a bit of a hack.
39-
ln -s "$TORCH_LIB_PATH"/libATen*.so aten/build/src/ATen
40-
aten/tools/run_tests.sh aten/build
39+
ln -s "$TORCH_LIB_PATH"/libcaffe2* build/bin
40+
ls build/bin
41+
aten/tools/run_tests.sh build/bin
4142
fi
4243

4344
rm -rf ninja

.travis.aten.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ script:
1616
- cd aten
1717
- mkdir build install
1818
- cd build
19-
- cmake .. -DNO_CUDA=1 -DCMAKE_INSTALL_PREFIX=../install
19+
- cmake .. -DUSE_CUDA=OFF -DCMAKE_INSTALL_PREFIX=../install
2020
- make install
2121
- ../tools/run_tests.sh .
2222
- cd ..

CMakeLists.txt

+23-16
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,11 @@ option(USE_ACL "Use ARM Compute Library" OFF)
4444
option(USE_ASAN "Use Address Sanitizer" OFF)
4545
option(USE_ATEN "Use ATen" OFF)
4646
option(USE_CUDA "Use CUDA" ON)
47+
option(USE_ROCM "Use ROCm" OFF)
4748
option(CAFFE2_STATIC_LINK_CUDA "Statically link CUDA libraries" OFF)
4849
cmake_dependent_option(
4950
USE_CUDNN "Use cuDNN" ON
50-
"USE_CUDA" OFF) # New option
51+
"USE_CUDA" OFF)
5152
option(USE_FFMPEG "Use ffmpeg" OFF)
5253
cmake_dependent_option(
5354
USE_GFLAGS "Use GFLAGS" ON
@@ -58,7 +59,7 @@ cmake_dependent_option(
5859
cmake_dependent_option(
5960
USE_GLOO "Use Gloo" ON
6061
"BUILD_CAFFE2" OFF)
61-
option(USE_GLOO_IBVERBS "Use Gloo IB verbs for distributed support" OFF) # New option
62+
option(USE_GLOO_IBVERBS "Use Gloo IB verbs for distributed support" OFF)
6263
cmake_dependent_option(
6364
USE_LEVELDB "Use LEVELDB" ON
6465
"BUILD_CAFFE2" OFF)
@@ -77,7 +78,7 @@ cmake_dependent_option(
7778
"BUILD_CAFFE2" OFF)
7879
option(USE_NATIVE_ARCH "Use -march=native" OFF)
7980
option(USE_NCCL "Use NCCL" ON)
80-
option(USE_SYSTEM_NCCL "Use system-wide NCCL" OFF) # New option
81+
option(USE_SYSTEM_NCCL "Use system-wide NCCL" OFF)
8182
option(USE_NERVANA_GPU "Use Nervana GPU backend" OFF)
8283
option(USE_NNAPI "Use NNAPI" OFF)
8384
option(USE_NNPACK "Use NNPACK" ON)
@@ -104,13 +105,16 @@ cmake_dependent_option(
104105
cmake_dependent_option(
105106
USE_MKLML "Use MKLML interface in MKL BLAS" ON
106107
"BUILD_CAFFE2" OFF)
107-
option(USE_DISTRIBUTED "Use THD (distributed)" OFF) # New option
108-
option(USE_DISTRIBUTED_MW "Use THD (distributed) master worker" OFF) # New option
108+
option(USE_DISTRIBUTED "Use THD (distributed)" OFF)
109+
option(USE_DISTRIBUTED_MW "Use THD (distributed) master worker" OFF)
109110

110111
# Legacy options, which we will eventually remove
111112
cmake_dependent_option(
112113
WITH_CUDA "Legacy CUDA" ON
113114
"USE_CUDA" OFF)
115+
cmake_dependent_option(
116+
WITH_ROCM "Legacy ROCm" ON
117+
"USE_ROCM" OFF)
114118
cmake_dependent_option(
115119
NO_CUDA "Legacy no CUDA" OFF
116120
"USE_CUDA" ON)
@@ -158,9 +162,18 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
158162

159163
enable_testing()
160164

165+
# ---[ Build variables set within the cmake tree
166+
include(cmake/BuildVariables.cmake)
167+
set(CAFFE2_WHITELIST "" CACHE STRING "A whitelist file of files that one should build.")
168+
169+
# Set default build type
170+
if(NOT CMAKE_BUILD_TYPE)
171+
message(STATUS "Build type not set - defaulting to Release")
172+
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build from: Debug Release RelWithDebInfo MinSizeRel Coverage." FORCE)
173+
endif()
174+
161175
# ---[ Misc checks to cope with various compiler modes
162176
include(cmake/MiscCheck.cmake)
163-
include(cmake/BuildVariables.cmake)
164177

165178
# External projects
166179
include(ExternalProject)
@@ -170,14 +183,6 @@ include(ExternalProject)
170183
include(cmake/Utils.cmake)
171184
include(cmake/public/utils.cmake)
172185

173-
set(CAFFE2_WHITELIST "" CACHE STRING "A whitelist file of files that one should build.")
174-
175-
# Set default build type
176-
if(NOT CMAKE_BUILD_TYPE)
177-
message(STATUS "Build type not set - defaulting to Release")
178-
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build from: Debug Release RelWithDebInfo MinSizeRel Coverage." FORCE)
179-
endif()
180-
181186
# ---[ Dependencies
182187
include(cmake/Dependencies.cmake)
183188

@@ -249,7 +254,9 @@ include_directories(BEFORE ${PROJECT_SOURCE_DIR})
249254
include_directories(BEFORE ${PROJECT_BINARY_DIR})
250255

251256
# ---[ Old caffe protobuf
252-
add_subdirectory(caffe/proto)
257+
if(BUILD_CAFFE2)
258+
add_subdirectory(caffe/proto)
259+
endif()
253260

254261
# ---[ Main build
255262
add_subdirectory(caffe2)
@@ -313,7 +320,7 @@ if ((NOT USE_GLOG) OR (NOT USE_GFLAGS) OR BUILD_CUSTOM_PROTOBUF)
313320
"generate files that are not well tested.")
314321
endif()
315322

316-
if (USE_CUDA)
323+
if (USE_CUDA OR USE_ROCM)
317324
# TODO: check if we should include other cuda dependency libraries
318325
# to the interface as well.
319326

0 commit comments

Comments
 (0)