diff --git a/.jenkins/caffe2/bench.sh b/.jenkins/caffe2/bench.sh deleted file mode 100755 index 55ac4e94df214..0000000000000 --- a/.jenkins/caffe2/bench.sh +++ /dev/null @@ -1,54 +0,0 @@ -#!/bin/bash - -# shellcheck source=./common.sh -source "$(dirname "${BASH_SOURCE[0]}")/common.sh" - -# Anywhere except $ROOT_DIR should work. This is so the python import doesn't -# get confused by any 'caffe2' directory in cwd -cd "$INSTALL_PREFIX" - -if [[ $BUILD_ENVIRONMENT == *-cuda* ]]; then - num_gpus=$(nvidia-smi -L | wc -l) -elif [[ $BUILD_ENVIRONMENT == *-rocm* ]]; then - num_gpus=$(rocminfo | grep 'Device Type.*GPU' | wc -l) -else - num_gpus=0 -fi - -caffe2_pypath="$(cd /usr && $PYTHON -c 'import os; import caffe2; print(os.path.dirname(os.path.realpath(caffe2.__file__)))')" -# Resnet50 -if (( $num_gpus == 0 )); then - "$PYTHON" "$caffe2_pypath/python/examples/imagenet_trainer.py" --train_data null --batch_size 128 --epoch_size 12800 --num_epochs 2 --use_cpu -fi -if (( $num_gpus >= 1 )); then - "$PYTHON" "$caffe2_pypath/python/examples/imagenet_trainer.py" --train_data null --batch_size 128 --epoch_size 12800 --num_epochs 2 --num_gpus 1 - # Let's skip the fp16 bench runs for now, as it recompiles the miopen kernels and can take 10+min to run. - # We can resume when we (1) bindmount the miopen cache folder in jenkins; (2) install the pre-compiled miopen kernel library in the docker - # "$PYTHON" "$caffe2_pypath/python/examples/imagenet_trainer.py" --train_data null --batch_size 256 --epoch_size 25600 --num_epochs 2 --num_gpus 1 --float16_compute --dtype float16 -fi -if (( $num_gpus >= 4 )); then - "$PYTHON" "$caffe2_pypath/python/examples/imagenet_trainer.py" --train_data null --batch_size 512 --epoch_size 51200 --num_epochs 2 --num_gpus 4 -fi - -# ResNext -if (( $num_gpus == 0 )); then - "$PYTHON" "$caffe2_pypath/python/examples/imagenet_trainer.py" --resnext_num_groups 32 --resnext_width_per_group 4 --num_layers 101 --train_data null --batch_size 32 --epoch_size 3200 --num_epochs 2 --use_cpu -fi -if (( $num_gpus >= 1 )); then - "$PYTHON" "$caffe2_pypath/python/examples/imagenet_trainer.py" --resnext_num_groups 32 --resnext_width_per_group 4 --num_layers 101 --train_data null --batch_size 32 --epoch_size 3200 --num_epochs 2 --num_gpus 1 - # "$PYTHON" "$caffe2_pypath/python/examples/imagenet_trainer.py" --resnext_num_groups 32 --resnext_width_per_group 4 --num_layers 101 --train_data null --batch_size 64 --epoch_size 3200 --num_epochs 2 --num_gpus 1 --float16_compute --dtype float16 -fi -if (( $num_gpus >= 4 )); then - "$PYTHON" "$caffe2_pypath/python/examples/imagenet_trainer.py" --resnext_num_groups 32 --resnext_width_per_group 4 --num_layers 101 --train_data null --batch_size 128 --epoch_size 12800 --num_epochs 2 --num_gpus 4 -fi - -# Shufflenet -if (( $num_gpus == 0 )); then - "$PYTHON" "$caffe2_pypath/python/examples/imagenet_trainer.py" --train_data null --batch_size 32 --epoch_size 3200 --num_epochs 2 --use_cpu --model shufflenet -fi -if (( $num_gpus >= 1 )); then - "$PYTHON" "$caffe2_pypath/python/examples/imagenet_trainer.py" --train_data null --batch_size 32 --epoch_size 3200 --num_epochs 2 --num_gpus 1 --model shufflenet -fi -if (( $num_gpus >= 4 )); then - "$PYTHON" "$caffe2_pypath/python/examples/imagenet_trainer.py" --train_data null --batch_size 128 --epoch_size 12800 --num_epochs 2 --num_gpus 4 --model shufflenet -fi diff --git a/.jenkins/caffe2/build.sh b/.jenkins/caffe2/build.sh deleted file mode 100755 index e6e06c1d7db5a..0000000000000 --- a/.jenkins/caffe2/build.sh +++ /dev/null @@ -1,231 +0,0 @@ -#!/bin/bash - -set -ex - -# shellcheck source=./common.sh -source "$(dirname "${BASH_SOURCE[0]}")/common.sh" - -# CMAKE_ARGS are only passed to 'cmake' and the -Dfoo=bar does not work with -# setup.py, so we build a list of foo=bars and then either convert it to -# -Dfoo=bars or export them before running setup.py -build_args=() -build_to_cmake () { - cmake_args=() - for build_arg in $*; do - cmake_args+=("-D$build_arg") - done - echo ${cmake_args[@]} -} - - -SCCACHE="$(which sccache)" - -# Setup ccache if configured to use it (and not sccache) -if [ -z "${SCCACHE}" ] && which ccache > /dev/null; then - mkdir -p ./ccache - ln -sf "$(which ccache)" ./ccache/cc - ln -sf "$(which ccache)" ./ccache/c++ - ln -sf "$(which ccache)" ./ccache/gcc - ln -sf "$(which ccache)" ./ccache/g++ - ln -sf "$(which ccache)" ./ccache/x86_64-linux-gnu-gcc - if [[ "${BUILD_ENVIRONMENT}" == *-cuda* ]]; then - mkdir -p ./ccache/cuda - ln -sf "$(which ccache)" ./ccache/cuda/nvcc - fi - export CACHE_WRAPPER_DIR="$PWD/ccache" - export PATH="$CACHE_WRAPPER_DIR:$PATH" -fi - -# sccache will fail for CUDA builds if all cores are used for compiling -if [ -z "$MAX_JOBS" ]; then - if [[ "${BUILD_ENVIRONMENT}" == *-cuda* ]] && [ -n "${SCCACHE}" ]; then - MAX_JOBS=`expr $(nproc) - 1` - else - MAX_JOBS=$(nproc) - fi -fi - -report_compile_cache_stats() { - if [[ -n "${SCCACHE}" ]]; then - "$SCCACHE" --show-stats - elif which ccache > /dev/null; then - ccache -s - fi -} - - -############################################################################### -# Use special scripts for Android and setup builds -############################################################################### -if [[ "${BUILD_ENVIRONMENT}" == *-android* ]]; then - export ANDROID_NDK=/opt/ndk - build_args+=("BUILD_BINARY=ON") - build_args+=("BUILD_TEST=ON") - build_args+=("USE_OBSERVERS=ON") - build_args+=("USE_ZSTD=ON") - BUILD_CAFFE2_MOBILE=1 "${ROOT_DIR}/scripts/build_android.sh" $(build_to_cmake ${build_args[@]}) "$@" - exit 0 -fi - -############################################################################### -# Set parameters -############################################################################### -if [[ "$BUILD_ENVIRONMENT" == *cmake* ]]; then - build_args+=("BUILD_PYTHON=OFF") -else - build_args+=("BUILD_PYTHON=ON") - build_args+=("PYTHON_EXECUTABLE=${PYTHON}") -fi -if [[ $BUILD_ENVIRONMENT == *mkl* ]]; then - build_args+=("BLAS=MKL") - build_args+=("USE_MKLDNN=ON") -fi -build_args+=("BUILD_BINARY=ON") -build_args+=("BUILD_TEST=ON") -build_args+=("INSTALL_TEST=ON") -build_args+=("USE_ZSTD=ON") - -if [[ $BUILD_ENVIRONMENT == *cuda* ]]; then - build_args+=("USE_CUDA=ON") - build_args+=("USE_NNPACK=OFF") - - # Target only our CI GPU machine's CUDA arch to speed up the build - build_args+=("TORCH_CUDA_ARCH_LIST=Maxwell") - - # Explicitly set path to NVCC such that the symlink to ccache or sccache is used - if [ -n "${CACHE_WRAPPER_DIR}" ]; then - build_args+=("CUDA_NVCC_EXECUTABLE=${CACHE_WRAPPER_DIR}/cuda/nvcc") - build_args+=("CMAKE_CUDA_COMPILER_LAUNCHER=${CACHE_WRAPPER_DIR}/ccache") - fi - - # Ensure FindCUDA.cmake can infer the right path to the CUDA toolkit. - # Setting PATH to resolve to the right nvcc alone isn't enough. - # See /usr/share/cmake-3.5/Modules/FindCUDA.cmake, block at line 589. - export CUDA_PATH="/usr/local/cuda" - - # Ensure the ccache symlink can still find the real nvcc binary. - export PATH="/usr/local/cuda/bin:$PATH" -fi -if [[ $BUILD_ENVIRONMENT == *rocm* ]]; then - if [[ -n "$CI" && -z "$PYTORCH_ROCM_ARCH" ]]; then - # Set ROCM_ARCH to gfx900 and gfx906 for CI builds, if user doesn't override. - echo "Limiting PYTORCH_ROCM_ARCH to gfx90[06] for CI builds" - export PYTORCH_ROCM_ARCH="gfx900;gfx906" - fi - # This is needed to enable ImageInput operator in resnet50_trainer - build_args+=("USE_OPENCV=ON") - # This is needed to read datasets from https://download.caffe2.ai/databases/resnet_trainer.zip - build_args+=("USE_LMDB=ON") - # hcc used to run out of memory, silently exiting without stopping - # the build process, leaving undefined symbols in the shared lib, - # causing undefined symbol errors when later running tests. - # We used to set MAX_JOBS to 4 to avoid, but this is no longer an issue. - if [ -z "$MAX_JOBS" ]; then - export MAX_JOBS=$(($(nproc) - 1)) - fi - - ########## HIPIFY Caffe2 operators - ${PYTHON} "${ROOT_DIR}/tools/amd_build/build_amd.py" -fi - -# Try to include Redis support for Linux builds -if [ "$(uname)" == "Linux" ]; then - build_args+=("USE_REDIS=ON") -fi - -# Use a specialized onnx namespace in CI to catch hardcoded onnx namespace -build_args+=("ONNX_NAMESPACE=ONNX_NAMESPACE_FOR_C2_CI") - -############################################################################### -# Configure and make -############################################################################### - -if [[ "$BUILD_ENVIRONMENT" == *cmake* ]]; then - # cmake-only non-setup.py build, to test cpp only bits. This installs into - # /usr/local/caffe2 and installs no Python tests - build_args+=("CMAKE_INSTALL_PREFIX=${INSTALL_PREFIX}") - - # Run cmake from ./build_caffe2 directory so it doesn't conflict with - # standard PyTorch build directory. Eventually these won't need to - # be separate. - rm -rf build_caffe2 - mkdir build_caffe2 - cd ./build_caffe2 - - # We test the presence of cmake3 (for platforms like Centos and Ubuntu 14.04) - # and use that if so. - if [[ -x "$(command -v cmake3)" ]]; then - CMAKE_BINARY=cmake3 - else - CMAKE_BINARY=cmake - fi - - # Configure - ${CMAKE_BINARY} "${ROOT_DIR}" $(build_to_cmake ${build_args[@]}) "$@" - - # Build - if [ "$(uname)" == "Linux" ]; then - make "-j${MAX_JOBS}" install - else - echo "Don't know how to build on $(uname)" - exit 1 - fi - - # This is to save test binaries for testing - mv "$INSTALL_PREFIX/test/" "$INSTALL_PREFIX/cpp_test/" - - ls -lah $INSTALL_PREFIX - -else - # Python build. Uses setup.py to install into site-packages - build_args+=("USE_LEVELDB=ON") - build_args+=("USE_LMDB=ON") - build_args+=("USE_OPENCV=ON") - build_args+=("BUILD_TEST=ON") - # These flags preserve the flags that were used before this refactor (blame - # me) - build_args+=("USE_GLOG=ON") - build_args+=("USE_GFLAGS=ON") - build_args+=("USE_FBGEMM=OFF") - build_args+=("USE_MKLDNN=OFF") - build_args+=("USE_DISTRIBUTED=ON") - for build_arg in "${build_args[@]}"; do - export $build_arg - done - - # sccache will be stuck if all cores are used for compiling - # see https://github.com/pytorch/pytorch/pull/7361 - if [[ -n "${SCCACHE}" && $BUILD_ENVIRONMENT != *rocm* ]]; then - export MAX_JOBS=`expr $(nproc) - 1` - fi - - pip install --user dataclasses typing_extensions - - $PYTHON setup.py install --user - - report_compile_cache_stats -fi - -############################################################################### -# Install ONNX -############################################################################### - -# Install ONNX into a local directory -pip install --user "file://${ROOT_DIR}/third_party/onnx#egg=onnx" - -report_compile_cache_stats - -if [[ $BUILD_ENVIRONMENT == *rocm* ]]; then - # remove sccache wrappers post-build; runtime compilation of MIOpen kernels does not yet fully support them - sudo rm -f /opt/cache/bin/cc - sudo rm -f /opt/cache/bin/c++ - sudo rm -f /opt/cache/bin/gcc - sudo rm -f /opt/cache/bin/g++ - pushd /opt/rocm/llvm/bin - if [[ -d original ]]; then - sudo mv original/clang . - sudo mv original/clang++ . - fi - sudo rm -rf original - popd -fi diff --git a/.jenkins/caffe2/dirty.sh b/.jenkins/caffe2/dirty.sh deleted file mode 100755 index 6b9ba544dab94..0000000000000 --- a/.jenkins/caffe2/dirty.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash -set -ex -upstream="$1" -pr="$2" -git diff --name-only "$upstream" "$pr" -# For safety, unconditionally trigger for any changes. -#git diff --name-only "$upstream" "$pr" | grep -Eq '^(CMakeLists.txt|Makefile|.gitmodules|.jenkins/caffe2|binaries|caffe|caffe2|cmake|conda|docker|docs/caffe2|modules|scripts|third_party)' diff --git a/.jenkins/pytorch/dirty.sh b/.jenkins/pytorch/dirty.sh deleted file mode 100755 index 230d696066645..0000000000000 --- a/.jenkins/pytorch/dirty.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash -set -ex -upstream="$1" -pr="$2" -git diff --name-only "$upstream" "$pr" -# Now that PyTorch build depends on Caffe2, unconditionally trigger -# for any changes. -# TODO: Replace this with a NEGATIVE regex that allows us to skip builds when they are unnecessary -#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/)' diff --git a/CMakeLists.txt b/CMakeLists.txt index 9b6fedca3f719..379fa2fd7c7e5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -165,9 +165,6 @@ option(BUILD_LITE_INTERPRETER "Master flag to build Lite Interpreter" OFF) cmake_dependent_option( BUILD_CAFFE2_OPS "Build Caffe2 operators" ON "BUILD_CAFFE2" OFF) -cmake_dependent_option( - BUILD_CAFFE2_MOBILE "Build libcaffe2 for mobile (deprecating)" OFF - "BUILD_CAFFE2" OFF) option(BUILD_SHARED_LIBS "Build libcaffe2.so" ON) cmake_dependent_option( CAFFE2_LINK_LOCAL_PROTOBUF "If set, build protobuf inside libcaffe2.so." ON @@ -591,18 +588,11 @@ if(ANDROID OR IOS OR DEFINED ENV{BUILD_PYTORCH_MOBILE_WITH_HOST_TOOLCHAIN}) endif() # INTERN_BUILD_ATEN_OPS is used to control whether to build ATen/TH operators. -# It's disabled for caffe2 mobile library. -if(INTERN_BUILD_MOBILE AND BUILD_CAFFE2_MOBILE) - set(INTERN_BUILD_ATEN_OPS OFF) -else() - set(INTERN_BUILD_ATEN_OPS ON) -endif() +set(INTERN_BUILD_ATEN_OPS ON) -# BUILD_CAFFE2_MOBILE is the master switch to choose between libcaffe2 v.s. libtorch mobile build. -# When it's enabled it builds original libcaffe2 mobile library without ATen/TH ops nor TorchScript support; -# When it's disabled it builds libtorch mobile library, which contains ATen/TH ops and native support for +# Build libtorch mobile library, which contains ATen/TH ops and native support for # TorchScript model, but doesn't contain not-yet-unified caffe2 ops; -if(INTERN_BUILD_MOBILE AND NOT BUILD_CAFFE2_MOBILE) +if(INTERN_BUILD_MOBILE) if(NOT BUILD_SHARED_LIBS AND NOT "${SELECTED_OP_LIST}" STREQUAL "") string(APPEND CMAKE_CXX_FLAGS " -DNO_EXPORT") endif() diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a007cedbdcac1..e2101017d99c5 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1246,13 +1246,6 @@ In 2018, we merged Caffe2 into the PyTorch source repository. While the steady state aspiration is that Caffe2 and PyTorch share code freely, in the meantime there will be some separation. -If you submit a PR to only PyTorch or only Caffe2 code, CI will only -run for the project you edited. The logic for this is implemented -in `.jenkins/pytorch/dirty.sh` and `.jenkins/caffe2/dirty.sh`; you -can look at this to see what path prefixes constitute changes. -This also means if you ADD a new top-level path, or you start -sharing code between projects, you need to modify these files. - There are a few "unusual" directories which, for historical reasons, are Caffe2/PyTorch specific. Here they are: diff --git a/binaries/CMakeLists.txt b/binaries/CMakeLists.txt index b683ee002280c..15f47bf52aee5 100644 --- a/binaries/CMakeLists.txt +++ b/binaries/CMakeLists.txt @@ -1,13 +1,8 @@ if(INTERN_BUILD_MOBILE) - if(BUILD_CAFFE2_MOBILE) - #caffe2_binary_target("predictor_verifier.cc") - caffe2_binary_target("speed_benchmark.cc") - else() - caffe2_binary_target("speed_benchmark_torch.cc") - caffe2_binary_target("load_benchmark_torch.cc") - if(NOT BUILD_LITE_INTERPRETER) - caffe2_binary_target("compare_models_torch.cc") - endif() + caffe2_binary_target("speed_benchmark_torch.cc") + caffe2_binary_target("load_benchmark_torch.cc") + if(NOT BUILD_LITE_INTERPRETER) + caffe2_binary_target("compare_models_torch.cc") endif() return() endif() diff --git a/caffe2/CMakeLists.txt b/caffe2/CMakeLists.txt index 584d550b2e87f..ba24386487f59 100644 --- a/caffe2/CMakeLists.txt +++ b/caffe2/CMakeLists.txt @@ -22,7 +22,7 @@ endif() # OMP - OpenMP for intra-op, native thread pool for inter-op parallelism # NATIVE - using native thread pool for intra- and inter-op parallelism # TBB - using TBB for intra- and native thread pool for inter-op parallelism -if(INTERN_BUILD_MOBILE AND NOT BUILD_CAFFE2_MOBILE) +if(INTERN_BUILD_MOBILE) set(ATEN_THREADING "NATIVE" CACHE STRING "ATen parallel backend") else() if(USE_OPENMP) @@ -129,7 +129,7 @@ if(BUILD_CAFFE2 OR (NOT USE_FBGEMM)) endif() # Skip modules that are not used by libtorch mobile yet. -if(BUILD_CAFFE2 AND (NOT INTERN_BUILD_MOBILE OR BUILD_CAFFE2_MOBILE)) +if(BUILD_CAFFE2 AND NOT INTERN_BUILD_MOBILE) add_subdirectory(contrib) add_subdirectory(predictor) add_subdirectory(predictor/emulator) @@ -166,7 +166,7 @@ if(BUILD_CAFFE2 AND (NOT INTERN_BUILD_MOBILE OR BUILD_CAFFE2_MOBILE)) # add_subdirectory(test) # todo: use caffe2_gtest_main instead of gtest_main because we will need to call GlobalInit add_subdirectory(transforms) endif() -if(NOT BUILD_CAFFE2 AND (NOT INTERN_BUILD_MOBILE OR BUILD_CAFFE2_MOBILE)) +if(NOT BUILD_CAFFE2 AND NOT INTERN_BUILD_MOBILE) add_subdirectory(proto) endif() @@ -269,7 +269,7 @@ if(PRINT_CMAKE_DEBUG_INFO) endif() -if(NOT INTERN_BUILD_MOBILE OR BUILD_CAFFE2_MOBILE) +if(NOT INTERN_BUILD_MOBILE) # ---[ List of libraries to link with add_library(caffe2_protos STATIC $) add_dependencies(caffe2_protos Caffe2_PROTO) @@ -326,441 +326,437 @@ if(NOT TORCH_INSTALL_LIB_DIR) set(TORCH_INSTALL_LIB_DIR lib) endif() +set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) +# Generate files +set(TOOLS_PATH "${TORCH_ROOT}/tools") -if(NOT INTERN_BUILD_MOBILE OR NOT BUILD_CAFFE2_MOBILE) - set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) - - # Generate files - set(TOOLS_PATH "${TORCH_ROOT}/tools") - - configure_file("${TORCH_SRC_DIR}/_utils_internal.py" - "${TOOLS_PATH}/shared/_utils_internal.py" - COPYONLY) +configure_file("${TORCH_SRC_DIR}/_utils_internal.py" + "${TOOLS_PATH}/shared/_utils_internal.py" + COPYONLY) - # Generate header with version info - configure_file("${TORCH_SRC_DIR}/csrc/api/include/torch/version.h.in" - "${TORCH_SRC_DIR}/csrc/api/include/torch/version.h" - @ONLY) +# Generate header with version info +configure_file("${TORCH_SRC_DIR}/csrc/api/include/torch/version.h.in" + "${TORCH_SRC_DIR}/csrc/api/include/torch/version.h" + @ONLY) - set(GENERATED_CXX_TORCH - "${TORCH_SRC_DIR}/csrc/autograd/generated/Functions.cpp" - ) +set(GENERATED_CXX_TORCH + "${TORCH_SRC_DIR}/csrc/autograd/generated/Functions.cpp" + ) - if(NOT INTERN_DISABLE_AUTOGRAD AND NOT BUILD_LITE_INTERPRETER) +if(NOT INTERN_DISABLE_AUTOGRAD AND NOT BUILD_LITE_INTERPRETER) + list(APPEND GENERATED_CXX_TORCH + "${TORCH_SRC_DIR}/csrc/autograd/generated/VariableType_0.cpp" + "${TORCH_SRC_DIR}/csrc/autograd/generated/VariableType_1.cpp" + "${TORCH_SRC_DIR}/csrc/autograd/generated/VariableType_2.cpp" + "${TORCH_SRC_DIR}/csrc/autograd/generated/VariableType_3.cpp" + "${TORCH_SRC_DIR}/csrc/autograd/generated/VariableType_4.cpp" + "${TORCH_SRC_DIR}/csrc/autograd/generated/TraceType_0.cpp" + "${TORCH_SRC_DIR}/csrc/autograd/generated/TraceType_1.cpp" + "${TORCH_SRC_DIR}/csrc/autograd/generated/TraceType_2.cpp" + "${TORCH_SRC_DIR}/csrc/autograd/generated/TraceType_3.cpp" + "${TORCH_SRC_DIR}/csrc/autograd/generated/TraceType_4.cpp" + "${TORCH_SRC_DIR}/csrc/autograd/generated/ADInplaceOrViewType_0.cpp" + "${TORCH_SRC_DIR}/csrc/autograd/generated/ADInplaceOrViewType_1.cpp" + ) + if(BUILD_LAZY_TS_BACKEND) list(APPEND GENERATED_CXX_TORCH - "${TORCH_SRC_DIR}/csrc/autograd/generated/VariableType_0.cpp" - "${TORCH_SRC_DIR}/csrc/autograd/generated/VariableType_1.cpp" - "${TORCH_SRC_DIR}/csrc/autograd/generated/VariableType_2.cpp" - "${TORCH_SRC_DIR}/csrc/autograd/generated/VariableType_3.cpp" - "${TORCH_SRC_DIR}/csrc/autograd/generated/VariableType_4.cpp" - "${TORCH_SRC_DIR}/csrc/autograd/generated/TraceType_0.cpp" - "${TORCH_SRC_DIR}/csrc/autograd/generated/TraceType_1.cpp" - "${TORCH_SRC_DIR}/csrc/autograd/generated/TraceType_2.cpp" - "${TORCH_SRC_DIR}/csrc/autograd/generated/TraceType_3.cpp" - "${TORCH_SRC_DIR}/csrc/autograd/generated/TraceType_4.cpp" - "${TORCH_SRC_DIR}/csrc/autograd/generated/ADInplaceOrViewType_0.cpp" - "${TORCH_SRC_DIR}/csrc/autograd/generated/ADInplaceOrViewType_1.cpp" + "${TORCH_SRC_DIR}/csrc/lazy/generated/LazyNativeFunctions.cpp" + "${TORCH_SRC_DIR}/csrc/lazy/generated/RegisterAutogradLazy.cpp" + "${TORCH_SRC_DIR}/csrc/lazy/generated/RegisterLazy.cpp" ) - if(BUILD_LAZY_TS_BACKEND) - list(APPEND GENERATED_CXX_TORCH - "${TORCH_SRC_DIR}/csrc/lazy/generated/LazyNativeFunctions.cpp" - "${TORCH_SRC_DIR}/csrc/lazy/generated/RegisterAutogradLazy.cpp" - "${TORCH_SRC_DIR}/csrc/lazy/generated/RegisterLazy.cpp" - ) - endif() endif() +endif() - set(GENERATED_H_TORCH - "${TORCH_SRC_DIR}/csrc/autograd/generated/Functions.h" - "${TORCH_SRC_DIR}/csrc/autograd/generated/variable_factories.h" - ) +set(GENERATED_H_TORCH + "${TORCH_SRC_DIR}/csrc/autograd/generated/Functions.h" + "${TORCH_SRC_DIR}/csrc/autograd/generated/variable_factories.h" + ) - if(NOT INTERN_DISABLE_AUTOGRAD) - list(APPEND GENERATED_H_TORCH - "${TORCH_SRC_DIR}/csrc/autograd/generated/VariableType.h" - "${TORCH_SRC_DIR}/csrc/lazy/generated/LazyIr.h" - "${TORCH_SRC_DIR}/csrc/lazy/generated/LazyNonNativeIr.h" - "${TORCH_SRC_DIR}/csrc/lazy/generated/LazyNativeFunctions.h" - ) - endif() +if(NOT INTERN_DISABLE_AUTOGRAD) + list(APPEND GENERATED_H_TORCH + "${TORCH_SRC_DIR}/csrc/autograd/generated/VariableType.h" + "${TORCH_SRC_DIR}/csrc/lazy/generated/LazyIr.h" + "${TORCH_SRC_DIR}/csrc/lazy/generated/LazyNonNativeIr.h" + "${TORCH_SRC_DIR}/csrc/lazy/generated/LazyNativeFunctions.h" + ) +endif() - set(GENERATED_CXX_PYTHON - "${TORCH_SRC_DIR}/csrc/autograd/generated/python_functions_0.cpp" - "${TORCH_SRC_DIR}/csrc/autograd/generated/python_functions_1.cpp" - "${TORCH_SRC_DIR}/csrc/autograd/generated/python_functions_2.cpp" - "${TORCH_SRC_DIR}/csrc/autograd/generated/python_functions_3.cpp" - "${TORCH_SRC_DIR}/csrc/autograd/generated/python_functions_4.cpp" - "${TORCH_SRC_DIR}/csrc/autograd/generated/python_variable_methods.cpp" - "${TORCH_SRC_DIR}/csrc/autograd/generated/python_torch_functions_0.cpp" - "${TORCH_SRC_DIR}/csrc/autograd/generated/python_torch_functions_1.cpp" - "${TORCH_SRC_DIR}/csrc/autograd/generated/python_torch_functions_2.cpp" - "${TORCH_SRC_DIR}/csrc/autograd/generated/python_nn_functions.cpp" - "${TORCH_SRC_DIR}/csrc/autograd/generated/python_fft_functions.cpp" - "${TORCH_SRC_DIR}/csrc/autograd/generated/python_linalg_functions.cpp" - "${TORCH_SRC_DIR}/csrc/autograd/generated/python_sparse_functions.cpp" - "${TORCH_SRC_DIR}/csrc/autograd/generated/python_special_functions.cpp" - "${TORCH_SRC_DIR}/csrc/autograd/generated/python_return_types.cpp" - "${TORCH_SRC_DIR}/csrc/autograd/generated/python_enum_tag.cpp" - ) +set(GENERATED_CXX_PYTHON + "${TORCH_SRC_DIR}/csrc/autograd/generated/python_functions_0.cpp" + "${TORCH_SRC_DIR}/csrc/autograd/generated/python_functions_1.cpp" + "${TORCH_SRC_DIR}/csrc/autograd/generated/python_functions_2.cpp" + "${TORCH_SRC_DIR}/csrc/autograd/generated/python_functions_3.cpp" + "${TORCH_SRC_DIR}/csrc/autograd/generated/python_functions_4.cpp" + "${TORCH_SRC_DIR}/csrc/autograd/generated/python_variable_methods.cpp" + "${TORCH_SRC_DIR}/csrc/autograd/generated/python_torch_functions_0.cpp" + "${TORCH_SRC_DIR}/csrc/autograd/generated/python_torch_functions_1.cpp" + "${TORCH_SRC_DIR}/csrc/autograd/generated/python_torch_functions_2.cpp" + "${TORCH_SRC_DIR}/csrc/autograd/generated/python_nn_functions.cpp" + "${TORCH_SRC_DIR}/csrc/autograd/generated/python_fft_functions.cpp" + "${TORCH_SRC_DIR}/csrc/autograd/generated/python_linalg_functions.cpp" + "${TORCH_SRC_DIR}/csrc/autograd/generated/python_sparse_functions.cpp" + "${TORCH_SRC_DIR}/csrc/autograd/generated/python_special_functions.cpp" + "${TORCH_SRC_DIR}/csrc/autograd/generated/python_return_types.cpp" + "${TORCH_SRC_DIR}/csrc/autograd/generated/python_enum_tag.cpp" + ) - set(GENERATED_H_PYTHON - "${TORCH_SRC_DIR}/csrc/autograd/generated/python_functions.h" - ) +set(GENERATED_H_PYTHON + "${TORCH_SRC_DIR}/csrc/autograd/generated/python_functions.h" + ) - set(GENERATED_TESTING_PYTHON - "${TORCH_SRC_DIR}/testing/_internal/generated/annotated_fn_args.py" - ) +set(GENERATED_TESTING_PYTHON + "${TORCH_SRC_DIR}/testing/_internal/generated/annotated_fn_args.py" + ) - set(TORCH_GENERATED_CODE - ${GENERATED_CXX_TORCH} - ${GENERATED_H_TORCH} - ${GENERATED_CXX_PYTHON} - ${GENERATED_H_PYTHON} - ${GENERATED_TESTING_PYTHON} - ) +set(TORCH_GENERATED_CODE + ${GENERATED_CXX_TORCH} + ${GENERATED_H_TORCH} + ${GENERATED_CXX_PYTHON} + ${GENERATED_H_PYTHON} + ${GENERATED_TESTING_PYTHON} + ) - set(GEN_PER_OPERATOR_FLAG) - if(USE_PER_OPERATOR_HEADERS) - list(APPEND GEN_PER_OPERATOR_FLAG "--per_operator_headers") - endif() - - file(GLOB_RECURSE autograd_python "${TOOLS_PATH}/autograd/*.py") - file(GLOB_RECURSE autograd_yaml "${TOOLS_PATH}/autograd/*.yaml") - file(GLOB_RECURSE autograd_templates "${TOOLS_PATH}/autograd/templates/*") - add_custom_command( - OUTPUT - ${TORCH_GENERATED_CODE} - COMMAND - "${PYTHON_EXECUTABLE}" tools/setup_helpers/generate_code.py - --native-functions-path "aten/src/ATen/native/native_functions.yaml" - --tags-path "aten/src/ATen/native/tags.yaml" - $<$:--disable-autograd> - $<$:--selected-op-list-path="${SELECTED_OP_LIST}"> - --force_schema_registration - --gen_lazy_ts_backend - ${GEN_PER_OPERATOR_FLAG} - DEPENDS - "${TORCH_ROOT}/aten/src/ATen/native/native_functions.yaml" - "${TORCH_ROOT}/aten/src/ATen/native/tags.yaml" - "${TORCH_ROOT}/aten/src/ATen/native/ts_native_functions.yaml" - "${TORCH_ROOT}/torch/csrc/lazy/core/shape_inference.h" - "${TORCH_ROOT}/torch/csrc/lazy/ts_backend/ts_native_functions.cpp" - "${TORCH_ROOT}/aten/src/ATen/templates/DispatchKeyNativeFunctions.h" - "${TORCH_ROOT}/aten/src/ATen/templates/DispatchKeyNativeFunctions.cpp" - "${TORCH_ROOT}/aten/src/ATen/templates/LazyIr.h" - "${TORCH_ROOT}/aten/src/ATen/templates/LazyNonNativeIr.h" - "${TORCH_ROOT}/aten/src/ATen/templates/RegisterDispatchKey.cpp" - ${autograd_python} - ${autograd_yaml} - ${autograd_templates} - ${torchgen_python} - WORKING_DIRECTORY "${TORCH_ROOT}") - - - # Required workaround for libtorch_python.so build - # see https://samthursfield.wordpress.com/2015/11/21/cmake-dependencies-between-targets-and-files-and-custom-commands/#custom-commands-in-different-directories - add_custom_target( - generate-torch-sources - DEPENDS ${TORCH_GENERATED_CODE} - ) +set(GEN_PER_OPERATOR_FLAG) +if(USE_PER_OPERATOR_HEADERS) + list(APPEND GEN_PER_OPERATOR_FLAG "--per_operator_headers") +endif() - set(TORCH_SRCS ${GENERATED_CXX_TORCH}) - list(APPEND TORCH_SRCS ${GENERATED_H_TORCH}) - list(APPEND LIBTORCH_CMAKE_SRCS "") - - list(APPEND LITE_EAGER_SYMOBLICATION_SRCS "") - if(USE_SOURCE_DEBUG_ON_MOBILE) - append_filelist("libtorch_lite_eager_symbolication" LITE_EAGER_SYMOBLICATION_SRCS) - # For source debug on lite interpreter, we have to add dependency on pickling - # but references to read/writeArchiveAndTensor is not built for mobile - # so this condition specifically says we are building for source debug - # on mobile. - if(BUILD_LITE_INTERPRETER) - set_source_files_properties(${TORCH_SRC_DIR}/csrc/jit/serialization/pickle.cpp PROPERTIES COMPILE_FLAGS "-DC10_MOBILE -DFEATURE_TORCH_MOBILE") - endif() - endif() +file(GLOB_RECURSE autograd_python "${TOOLS_PATH}/autograd/*.py") +file(GLOB_RECURSE autograd_yaml "${TOOLS_PATH}/autograd/*.yaml") +file(GLOB_RECURSE autograd_templates "${TOOLS_PATH}/autograd/templates/*") +add_custom_command( + OUTPUT + ${TORCH_GENERATED_CODE} + COMMAND + "${PYTHON_EXECUTABLE}" tools/setup_helpers/generate_code.py + --native-functions-path "aten/src/ATen/native/native_functions.yaml" + --tags-path "aten/src/ATen/native/tags.yaml" + $<$:--disable-autograd> + $<$:--selected-op-list-path="${SELECTED_OP_LIST}"> + --force_schema_registration + --gen_lazy_ts_backend + ${GEN_PER_OPERATOR_FLAG} + DEPENDS + "${TORCH_ROOT}/aten/src/ATen/native/native_functions.yaml" + "${TORCH_ROOT}/aten/src/ATen/native/tags.yaml" + "${TORCH_ROOT}/aten/src/ATen/native/ts_native_functions.yaml" + "${TORCH_ROOT}/torch/csrc/lazy/core/shape_inference.h" + "${TORCH_ROOT}/torch/csrc/lazy/ts_backend/ts_native_functions.cpp" + "${TORCH_ROOT}/aten/src/ATen/templates/DispatchKeyNativeFunctions.h" + "${TORCH_ROOT}/aten/src/ATen/templates/DispatchKeyNativeFunctions.cpp" + "${TORCH_ROOT}/aten/src/ATen/templates/LazyIr.h" + "${TORCH_ROOT}/aten/src/ATen/templates/LazyNonNativeIr.h" + "${TORCH_ROOT}/aten/src/ATen/templates/RegisterDispatchKey.cpp" + ${autograd_python} + ${autograd_yaml} + ${autograd_templates} + ${torchgen_python} + WORKING_DIRECTORY "${TORCH_ROOT}") + + +# Required workaround for libtorch_python.so build +# see https://samthursfield.wordpress.com/2015/11/21/cmake-dependencies-between-targets-and-files-and-custom-commands/#custom-commands-in-different-directories +add_custom_target( + generate-torch-sources + DEPENDS ${TORCH_GENERATED_CODE} + ) - list(APPEND LITE_PROFILER_SRCS "") - if(USE_LITE_INTERPRETER_PROFILER) - append_filelist("libtorch_edge_profiler_sources " LITE_PROFILER_SRCS) +set(TORCH_SRCS ${GENERATED_CXX_TORCH}) +list(APPEND TORCH_SRCS ${GENERATED_H_TORCH}) +list(APPEND LIBTORCH_CMAKE_SRCS "") + +list(APPEND LITE_EAGER_SYMOBLICATION_SRCS "") +if(USE_SOURCE_DEBUG_ON_MOBILE) + append_filelist("libtorch_lite_eager_symbolication" LITE_EAGER_SYMOBLICATION_SRCS) + # For source debug on lite interpreter, we have to add dependency on pickling + # but references to read/writeArchiveAndTensor is not built for mobile + # so this condition specifically says we are building for source debug + # on mobile. + if(BUILD_LITE_INTERPRETER) + set_source_files_properties(${TORCH_SRC_DIR}/csrc/jit/serialization/pickle.cpp PROPERTIES COMPILE_FLAGS "-DC10_MOBILE -DFEATURE_TORCH_MOBILE") endif() +endif() - # Switch between the full jit interpreter and lite interpreter - if(BUILD_LITE_INTERPRETER) - append_filelist("libtorch_lite_cmake_sources" LIBTORCH_CMAKE_SRCS) - list(APPEND LIBTORCH_CMAKE_SRCS ${LITE_EAGER_SYMOBLICATION_SRCS}) - list(APPEND LIBTORCH_CMAKE_SRCS ${LITE_PROFILER_SRCS}) - set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) - else() - append_filelist("libtorch_cmake_sources" LIBTORCH_CMAKE_SRCS) - if(BUILD_LAZY_TS_BACKEND) - append_filelist("lazy_tensor_ts_sources" LIBTORCH_CMAKE_SRCS) - endif() - if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - # TODO: Delete this line once https://github.com/pytorch/pytorch/pull/55889 lands - set_source_files_properties(../torch/csrc/jit/serialization/export.cpp PROPERTIES COMPILE_FLAGS -Wno-deprecated-declarations) +list(APPEND LITE_PROFILER_SRCS "") +if(USE_LITE_INTERPRETER_PROFILER) + append_filelist("libtorch_edge_profiler_sources " LITE_PROFILER_SRCS) +endif() - # TODO: Delete this when https://github.com/pytorch/pytorch/issues/35026 is fixed - set_source_files_properties(../torch/csrc/autograd/record_function_ops.cpp PROPERTIES COMPILE_FLAGS -Wno-deprecated-declarations) - endif() +# Switch between the full jit interpreter and lite interpreter +if(BUILD_LITE_INTERPRETER) + append_filelist("libtorch_lite_cmake_sources" LIBTORCH_CMAKE_SRCS) + list(APPEND LIBTORCH_CMAKE_SRCS ${LITE_EAGER_SYMOBLICATION_SRCS}) + list(APPEND LIBTORCH_CMAKE_SRCS ${LITE_PROFILER_SRCS}) + set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) +else() + append_filelist("libtorch_cmake_sources" LIBTORCH_CMAKE_SRCS) + if(BUILD_LAZY_TS_BACKEND) + append_filelist("lazy_tensor_ts_sources" LIBTORCH_CMAKE_SRCS) endif() - list(APPEND TORCH_SRCS ${LIBTORCH_CMAKE_SRCS}) + if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + # TODO: Delete this line once https://github.com/pytorch/pytorch/pull/55889 lands + set_source_files_properties(../torch/csrc/jit/serialization/export.cpp PROPERTIES COMPILE_FLAGS -Wno-deprecated-declarations) - if(PRINT_CMAKE_DEBUG_INFO) - message(STATUS "Interpreter sources: ") - foreach(tmp ${LIBTORCH_CMAKE_SRCS}) - message(STATUS " " ${tmp}) - endforeach() + # TODO: Delete this when https://github.com/pytorch/pytorch/issues/35026 is fixed + set_source_files_properties(../torch/csrc/autograd/record_function_ops.cpp PROPERTIES COMPILE_FLAGS -Wno-deprecated-declarations) endif() +endif() +list(APPEND TORCH_SRCS ${LIBTORCH_CMAKE_SRCS}) - # Mobile backend delegate srcs - if(INTERN_BUILD_MOBILE AND NOT BUILD_CAFFE2_MOBILE) - set(DELEGATE_SRCS - ${TORCH_SRC_DIR}/csrc/jit/backends/backend_debug_info.cpp - ${TORCH_SRC_DIR}/csrc/jit/backends/backend_interface.cpp +if(PRINT_CMAKE_DEBUG_INFO) + message(STATUS "Interpreter sources: ") + foreach(tmp ${LIBTORCH_CMAKE_SRCS}) + message(STATUS " " ${tmp}) + endforeach() +endif() + +# Mobile backend delegate srcs +if(INTERN_BUILD_MOBILE) + set(DELEGATE_SRCS + ${TORCH_SRC_DIR}/csrc/jit/backends/backend_debug_info.cpp + ${TORCH_SRC_DIR}/csrc/jit/backends/backend_interface.cpp + ) + list(APPEND TORCH_SRCS ${DELEGATE_SRCS}) + if(IOS AND USE_COREML_DELEGATE) + set(COREML_DELEGATE_SRCS + ${TORCH_SRC_DIR}/csrc/jit/backends/coreml/cpp/context.cpp + ${TORCH_SRC_DIR}/csrc/jit/backends/coreml/objc/PTMCoreMLBackend.mm + ${TORCH_SRC_DIR}/csrc/jit/backends/coreml/objc/PTMCoreMLExecutor.mm + ${TORCH_SRC_DIR}/csrc/jit/backends/coreml/objc/PTMCoreMLCompiler.mm + ${TORCH_SRC_DIR}/csrc/jit/backends/coreml/objc/PTMCoreMLFeatureProvider.mm ) - list(APPEND TORCH_SRCS ${DELEGATE_SRCS}) - if(IOS AND USE_COREML_DELEGATE) - set(COREML_DELEGATE_SRCS - ${TORCH_SRC_DIR}/csrc/jit/backends/coreml/cpp/context.cpp - ${TORCH_SRC_DIR}/csrc/jit/backends/coreml/objc/PTMCoreMLBackend.mm - ${TORCH_SRC_DIR}/csrc/jit/backends/coreml/objc/PTMCoreMLExecutor.mm - ${TORCH_SRC_DIR}/csrc/jit/backends/coreml/objc/PTMCoreMLCompiler.mm - ${TORCH_SRC_DIR}/csrc/jit/backends/coreml/objc/PTMCoreMLFeatureProvider.mm - ) - set_source_files_properties(${TORCH_SRC_DIR}/csrc/jit/backends/coreml/objc/PTMCoreMLBackend.mm PROPERTIES COMPILE_FLAGS "-fno-objc-arc") - include_directories(${TORCH_ROOT}/third_party/nlohmann/single_include) - list(APPEND TORCH_SRCS ${COREML_DELEGATE_SRCS}) - endif() - endif() + set_source_files_properties(${TORCH_SRC_DIR}/csrc/jit/backends/coreml/objc/PTMCoreMLBackend.mm PROPERTIES COMPILE_FLAGS "-fno-objc-arc") + include_directories(${TORCH_ROOT}/third_party/nlohmann/single_include) + list(APPEND TORCH_SRCS ${COREML_DELEGATE_SRCS}) + endif() +endif() + +# Required workaround for LLVM 9 includes. +if(NOT MSVC) + set_source_files_properties(${TORCH_SRC_DIR}/csrc/jit/tensorexpr/llvm_jit.cpp PROPERTIES COMPILE_FLAGS -Wno-noexcept-type) + # Force -Werror on several files + set_source_files_properties(${CMAKE_CURRENT_LIST_DIR}/../aten/src/ATen/native/mkldnn/Pooling.cpp PROPERTIES COMPILE_FLAGS "-Werror") +endif() +# Disable certain warnings for GCC-9.X +if(CMAKE_COMPILER_IS_GNUCXX AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 9.0.0)) + # See https://github.com/pytorch/pytorch/issues/38856 + set_source_files_properties(${TORCH_SRC_DIR}/csrc/jit/tensorexpr/llvm_jit.cpp PROPERTIES COMPILE_FLAGS "-Wno-redundant-move -Wno-noexcept-type") + set_source_files_properties(${TORCH_SRC_DIR}/csrc/jit/tensorexpr/llvm_codegen.cpp PROPERTIES COMPILE_FLAGS "-Wno-init-list-lifetime") +endif() + +if(NOT INTERN_DISABLE_MOBILE_INTERP) + set(MOBILE_SRCS + ${TORCH_SRC_DIR}/csrc/jit/mobile/function.cpp + ${TORCH_SRC_DIR}/csrc/jit/mobile/import.cpp + ${TORCH_SRC_DIR}/csrc/jit/mobile/import_data.cpp + ${TORCH_SRC_DIR}/csrc/jit/mobile/interpreter.cpp + ${TORCH_SRC_DIR}/csrc/jit/mobile/compatibility/model_compatibility.cpp + ${TORCH_SRC_DIR}/csrc/jit/mobile/module.cpp + ${TORCH_SRC_DIR}/csrc/jit/mobile/flatbuffer_loader.cpp + ${TORCH_SRC_DIR}/csrc/jit/mobile/observer.cpp + ${TORCH_SRC_DIR}/csrc/jit/mobile/parse_bytecode.cpp + ${TORCH_SRC_DIR}/csrc/jit/mobile/parse_operators.cpp + ${TORCH_SRC_DIR}/csrc/jit/mobile/quantization.cpp + ${TORCH_SRC_DIR}/csrc/jit/mobile/train/export_data.cpp + ${TORCH_SRC_DIR}/csrc/jit/mobile/train/optim/sgd.cpp + ${TORCH_SRC_DIR}/csrc/jit/mobile/train/random.cpp + ${TORCH_SRC_DIR}/csrc/jit/mobile/train/sequential.cpp + ${TORCH_SRC_DIR}/csrc/jit/mobile/upgrader_mobile.cpp + ) + list(APPEND TORCH_SRCS ${MOBILE_SRCS}) + list(APPEND TORCH_SRCS ${LITE_EAGER_SYMOBLICATION_SRCS}) +endif() + +# This one needs to be unconditionally added as Functions.cpp is also unconditionally added +list(APPEND TORCH_SRCS + ${TORCH_SRC_DIR}/csrc/autograd/FunctionsManual.cpp + ${TORCH_SRC_DIR}/csrc/utils/out_types.cpp +) + +if(NOT INTERN_DISABLE_AUTOGRAD AND NOT BUILD_LITE_INTERPRETER) + list(APPEND TORCH_SRCS + ${TORCH_SRC_DIR}/csrc/autograd/TraceTypeManual.cpp + ${TORCH_SRC_DIR}/csrc/autograd/VariableTypeManual.cpp + ) +endif() - # Required workaround for LLVM 9 includes. - if(NOT MSVC) - set_source_files_properties(${TORCH_SRC_DIR}/csrc/jit/tensorexpr/llvm_jit.cpp PROPERTIES COMPILE_FLAGS -Wno-noexcept-type) - # Force -Werror on several files - set_source_files_properties(${CMAKE_CURRENT_LIST_DIR}/../aten/src/ATen/native/mkldnn/Pooling.cpp PROPERTIES COMPILE_FLAGS "-Werror") - endif() - # Disable certain warnings for GCC-9.X - if(CMAKE_COMPILER_IS_GNUCXX AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 9.0.0)) - # See https://github.com/pytorch/pytorch/issues/38856 - set_source_files_properties(${TORCH_SRC_DIR}/csrc/jit/tensorexpr/llvm_jit.cpp PROPERTIES COMPILE_FLAGS "-Wno-redundant-move -Wno-noexcept-type") - set_source_files_properties(${TORCH_SRC_DIR}/csrc/jit/tensorexpr/llvm_codegen.cpp PROPERTIES COMPILE_FLAGS "-Wno-init-list-lifetime") - endif() - - if(NOT INTERN_DISABLE_MOBILE_INTERP) - set(MOBILE_SRCS - ${TORCH_SRC_DIR}/csrc/jit/mobile/function.cpp - ${TORCH_SRC_DIR}/csrc/jit/mobile/import.cpp - ${TORCH_SRC_DIR}/csrc/jit/mobile/import_data.cpp - ${TORCH_SRC_DIR}/csrc/jit/mobile/interpreter.cpp - ${TORCH_SRC_DIR}/csrc/jit/mobile/compatibility/model_compatibility.cpp - ${TORCH_SRC_DIR}/csrc/jit/mobile/module.cpp - ${TORCH_SRC_DIR}/csrc/jit/mobile/flatbuffer_loader.cpp - ${TORCH_SRC_DIR}/csrc/jit/mobile/observer.cpp - ${TORCH_SRC_DIR}/csrc/jit/mobile/parse_bytecode.cpp - ${TORCH_SRC_DIR}/csrc/jit/mobile/parse_operators.cpp - ${TORCH_SRC_DIR}/csrc/jit/mobile/quantization.cpp - ${TORCH_SRC_DIR}/csrc/jit/mobile/train/export_data.cpp - ${TORCH_SRC_DIR}/csrc/jit/mobile/train/optim/sgd.cpp - ${TORCH_SRC_DIR}/csrc/jit/mobile/train/random.cpp - ${TORCH_SRC_DIR}/csrc/jit/mobile/train/sequential.cpp - ${TORCH_SRC_DIR}/csrc/jit/mobile/upgrader_mobile.cpp - ) - list(APPEND TORCH_SRCS ${MOBILE_SRCS}) - list(APPEND TORCH_SRCS ${LITE_EAGER_SYMOBLICATION_SRCS}) - endif() - - # This one needs to be unconditionally added as Functions.cpp is also unconditionally added +if(${USE_ITT}) list(APPEND TORCH_SRCS - ${TORCH_SRC_DIR}/csrc/autograd/FunctionsManual.cpp - ${TORCH_SRC_DIR}/csrc/utils/out_types.cpp + ${TORCH_SRC_DIR}/csrc/itt_wrapper.cpp + ${TORCH_SRC_DIR}/csrc/profiler/itt.cpp ) +endif() - if(NOT INTERN_DISABLE_AUTOGRAD AND NOT BUILD_LITE_INTERPRETER) - list(APPEND TORCH_SRCS - ${TORCH_SRC_DIR}/csrc/autograd/TraceTypeManual.cpp - ${TORCH_SRC_DIR}/csrc/autograd/VariableTypeManual.cpp - ) - endif() +if(NOT INTERN_BUILD_MOBILE AND NOT BUILD_LITE_INTERPRETER) + list(APPEND TORCH_SRCS + ${TORCH_SRC_DIR}/csrc/api/src/jit.cpp + ${TORCH_SRC_DIR}/csrc/jit/mobile/compatibility/backport.cpp + ${TORCH_SRC_DIR}/csrc/jit/mobile/compatibility/backport_manager.cpp + ${TORCH_SRC_DIR}/csrc/jit/serialization/onnx.cpp + ${TORCH_SRC_DIR}/csrc/jit/serialization/export.cpp + ${TORCH_SRC_DIR}/csrc/jit/serialization/export_bytecode.cpp + ${TORCH_SRC_DIR}/csrc/jit/serialization/export_module.cpp + ${TORCH_SRC_DIR}/csrc/jit/serialization/flatbuffer_serializer.cpp + ${TORCH_SRC_DIR}/csrc/jit/serialization/flatbuffer_serializer_jit.cpp + ${TORCH_SRC_DIR}/csrc/jit/codegen/fuser/cpu/fused_kernel.cpp + ${TORCH_SRC_DIR}/csrc/jit/api/module_save.cpp + ${TORCH_SRC_DIR}/csrc/utils/byte_order.cpp + ) - if(${USE_ITT}) + # Disable legacy import of building without Caffe2 support + if(BUILD_CAFFE2) list(APPEND TORCH_SRCS - ${TORCH_SRC_DIR}/csrc/itt_wrapper.cpp - ${TORCH_SRC_DIR}/csrc/profiler/itt.cpp + ${TORCH_SRC_DIR}/csrc/jit/serialization/import_legacy.cpp ) - endif() - - if(NOT INTERN_BUILD_MOBILE AND NOT BUILD_LITE_INTERPRETER) - list(APPEND TORCH_SRCS - ${TORCH_SRC_DIR}/csrc/api/src/jit.cpp - ${TORCH_SRC_DIR}/csrc/jit/mobile/compatibility/backport.cpp - ${TORCH_SRC_DIR}/csrc/jit/mobile/compatibility/backport_manager.cpp - ${TORCH_SRC_DIR}/csrc/jit/serialization/onnx.cpp - ${TORCH_SRC_DIR}/csrc/jit/serialization/export.cpp - ${TORCH_SRC_DIR}/csrc/jit/serialization/export_bytecode.cpp - ${TORCH_SRC_DIR}/csrc/jit/serialization/export_module.cpp - ${TORCH_SRC_DIR}/csrc/jit/serialization/flatbuffer_serializer.cpp - ${TORCH_SRC_DIR}/csrc/jit/serialization/flatbuffer_serializer_jit.cpp - ${TORCH_SRC_DIR}/csrc/jit/codegen/fuser/cpu/fused_kernel.cpp - ${TORCH_SRC_DIR}/csrc/jit/api/module_save.cpp - ${TORCH_SRC_DIR}/csrc/utils/byte_order.cpp + else() + set_source_files_properties( + ${TORCH_SRC_DIR}/csrc/jit/serialization/import.cpp + PROPERTIES COMPILE_FLAGS "-DC10_DISABLE_LEGACY_IMPORT" ) - - # Disable legacy import of building without Caffe2 support - if(BUILD_CAFFE2) - list(APPEND TORCH_SRCS - ${TORCH_SRC_DIR}/csrc/jit/serialization/import_legacy.cpp - ) - else() - set_source_files_properties( - ${TORCH_SRC_DIR}/csrc/jit/serialization/import.cpp - PROPERTIES COMPILE_FLAGS "-DC10_DISABLE_LEGACY_IMPORT" - ) - endif() - if(USE_DISTRIBUTED) - append_filelist("libtorch_distributed_base_sources" TORCH_SRCS) - if(NOT WIN32) - append_filelist("libtorch_distributed_extra_sources" TORCH_SRCS) - endif() + endif() + if(USE_DISTRIBUTED) + append_filelist("libtorch_distributed_base_sources" TORCH_SRCS) + if(NOT WIN32) + append_filelist("libtorch_distributed_extra_sources" TORCH_SRCS) endif() endif() +endif() - if(USE_CUDA OR USE_ROCM) - append_filelist("libtorch_cuda_core_sources" Caffe2_GPU_HIP_JIT_FUSERS_SRCS) - endif() +if(USE_CUDA OR USE_ROCM) + append_filelist("libtorch_cuda_core_sources" Caffe2_GPU_HIP_JIT_FUSERS_SRCS) +endif() - if(USE_CUDA) - list(APPEND Caffe2_GPU_CU_SRCS ${Caffe2_GPU_HIP_JIT_FUSERS_SRCS}) - add_library(caffe2_nvrtc SHARED ${ATen_NVRTC_STUB_SRCS}) - if(MSVC) - # Delay load nvcuda.dll so we can import torch compiled with cuda on a CPU-only machine - set(DELAY_LOAD_FLAGS "-DELAYLOAD:nvcuda.dll;delayimp.lib") - else() - set(DELAY_LOAD_FLAGS "") - endif() - target_link_libraries(caffe2_nvrtc ${CUDA_NVRTC} ${CUDA_CUDA_LIB} ${CUDA_NVRTC_LIB} ${DELAY_LOAD_FLAGS}) - target_include_directories(caffe2_nvrtc PRIVATE ${CUDA_INCLUDE_DIRS}) - install(TARGETS caffe2_nvrtc DESTINATION "${TORCH_INSTALL_LIB_DIR}") - if(USE_NCCL) - list(APPEND Caffe2_GPU_SRCS - ${TORCH_SRC_DIR}/csrc/cuda/nccl.cpp) - endif() - if(USE_DISTRIBUTED) - append_filelist("libtorch_cuda_distributed_base_sources" Caffe2_GPU_SRCS) - if(NOT WIN32) - append_filelist("libtorch_cuda_distributed_extra_sources" Caffe2_GPU_SRCS) - endif() - endif() - set_source_files_properties( - ${TORCH_ROOT}/aten/src/ATen/cuda/detail/LazyNVRTC.cpp - PROPERTIES COMPILE_DEFINITIONS "NVRTC_SHORTHASH=${CUDA_NVRTC_SHORTHASH}" - ) - set_source_files_properties(${TORCH_SRC_DIR}/csrc/jit/passes/frozen_conv_add_relu_fusion.cpp PROPERTIES COMPILE_FLAGS "-DUSE_CUDA=1") - endif() - - if(BUILD_ONEDNN_GRAPH) - list(APPEND Caffe2_CPU_SRCS - ${TORCH_SRC_DIR}/csrc/jit/codegen/onednn/LlgaTensorImpl.cpp - ${TORCH_SRC_DIR}/csrc/jit/codegen/onednn/graph_fuser.cpp - ${TORCH_SRC_DIR}/csrc/jit/codegen/onednn/graph_rewriter.cpp - ${TORCH_SRC_DIR}/csrc/jit/codegen/onednn/graph_helper.cpp - ${TORCH_SRC_DIR}/csrc/jit/codegen/onednn/register_interface.cpp - ${TORCH_SRC_DIR}/csrc/jit/codegen/onednn/interface.cpp - ${TORCH_SRC_DIR}/csrc/jit/codegen/onednn/kernel.cpp - ${TORCH_SRC_DIR}/csrc/jit/codegen/onednn/defer_size_check.cpp - ${TORCH_SRC_DIR}/csrc/jit/codegen/onednn/layout_propagation.cpp - ${TORCH_SRC_DIR}/csrc/jit/codegen/onednn/prepare_binary.cpp - ${TORCH_SRC_DIR}/csrc/jit/codegen/onednn/guard_shape.cpp - ) +if(USE_CUDA) + list(APPEND Caffe2_GPU_CU_SRCS ${Caffe2_GPU_HIP_JIT_FUSERS_SRCS}) + add_library(caffe2_nvrtc SHARED ${ATen_NVRTC_STUB_SRCS}) + if(MSVC) + # Delay load nvcuda.dll so we can import torch compiled with cuda on a CPU-only machine + set(DELAY_LOAD_FLAGS "-DELAYLOAD:nvcuda.dll;delayimp.lib") + else() + set(DELAY_LOAD_FLAGS "") endif() - - if(USE_ROCM) - list(APPEND Caffe2_HIP_SRCS ${Caffe2_GPU_HIP_JIT_FUSERS_SRCS}) - if(USE_NCCL) - list(APPEND Caffe2_HIP_SRCS - ${TORCH_SRC_DIR}/csrc/cuda/nccl.cpp) - endif() - if(USE_DISTRIBUTED) - append_filelist("libtorch_cuda_distributed_base_sources" Caffe2_HIP_SRCS) - if(NOT WIN32) - append_filelist("libtorch_cuda_distributed_extra_sources" Caffe2_HIP_SRCS) - endif() + target_link_libraries(caffe2_nvrtc ${CUDA_NVRTC} ${CUDA_CUDA_LIB} ${CUDA_NVRTC_LIB} ${DELAY_LOAD_FLAGS}) + target_include_directories(caffe2_nvrtc PRIVATE ${CUDA_INCLUDE_DIRS}) + install(TARGETS caffe2_nvrtc DESTINATION "${TORCH_INSTALL_LIB_DIR}") + if(USE_NCCL) + list(APPEND Caffe2_GPU_SRCS + ${TORCH_SRC_DIR}/csrc/cuda/nccl.cpp) + endif() + if(USE_DISTRIBUTED) + append_filelist("libtorch_cuda_distributed_base_sources" Caffe2_GPU_SRCS) + if(NOT WIN32) + append_filelist("libtorch_cuda_distributed_extra_sources" Caffe2_GPU_SRCS) endif() - # caffe2_nvrtc's stubs to driver APIs are useful for HIP. - # See NOTE [ ATen NVRTC Stub and HIP ] - add_library(caffe2_nvrtc SHARED ${ATen_NVRTC_STUB_SRCS}) - target_link_libraries(caffe2_nvrtc ${PYTORCH_HIP_HCC_LIBRARIES} ${ROCM_HIPRTC_LIB}) - target_compile_definitions(caffe2_nvrtc PRIVATE USE_ROCM __HIP_PLATFORM_HCC__) - install(TARGETS caffe2_nvrtc DESTINATION "${TORCH_INSTALL_LIB_DIR}") endif() + set_source_files_properties( + ${TORCH_ROOT}/aten/src/ATen/cuda/detail/LazyNVRTC.cpp + PROPERTIES COMPILE_DEFINITIONS "NVRTC_SHORTHASH=${CUDA_NVRTC_SHORTHASH}" + ) + set_source_files_properties(${TORCH_SRC_DIR}/csrc/jit/passes/frozen_conv_add_relu_fusion.cpp PROPERTIES COMPILE_FLAGS "-DUSE_CUDA=1") +endif() + +if(BUILD_ONEDNN_GRAPH) + list(APPEND Caffe2_CPU_SRCS + ${TORCH_SRC_DIR}/csrc/jit/codegen/onednn/LlgaTensorImpl.cpp + ${TORCH_SRC_DIR}/csrc/jit/codegen/onednn/graph_fuser.cpp + ${TORCH_SRC_DIR}/csrc/jit/codegen/onednn/graph_rewriter.cpp + ${TORCH_SRC_DIR}/csrc/jit/codegen/onednn/graph_helper.cpp + ${TORCH_SRC_DIR}/csrc/jit/codegen/onednn/register_interface.cpp + ${TORCH_SRC_DIR}/csrc/jit/codegen/onednn/interface.cpp + ${TORCH_SRC_DIR}/csrc/jit/codegen/onednn/kernel.cpp + ${TORCH_SRC_DIR}/csrc/jit/codegen/onednn/defer_size_check.cpp + ${TORCH_SRC_DIR}/csrc/jit/codegen/onednn/layout_propagation.cpp + ${TORCH_SRC_DIR}/csrc/jit/codegen/onednn/prepare_binary.cpp + ${TORCH_SRC_DIR}/csrc/jit/codegen/onednn/guard_shape.cpp + ) +endif() - if(NOT NO_API AND NOT BUILD_LITE_INTERPRETER) - list(APPEND TORCH_SRCS - ${TORCH_SRC_DIR}/csrc/api/src/cuda.cpp - ${TORCH_SRC_DIR}/csrc/api/src/data/datasets/mnist.cpp - ${TORCH_SRC_DIR}/csrc/api/src/data/samplers/distributed.cpp - ${TORCH_SRC_DIR}/csrc/api/src/data/samplers/random.cpp - ${TORCH_SRC_DIR}/csrc/api/src/data/samplers/sequential.cpp - ${TORCH_SRC_DIR}/csrc/api/src/data/samplers/stream.cpp - ${TORCH_SRC_DIR}/csrc/api/src/enum.cpp - ${TORCH_SRC_DIR}/csrc/api/src/imethod.cpp - ${TORCH_SRC_DIR}/csrc/api/src/serialize.cpp - ${TORCH_SRC_DIR}/csrc/api/src/jit.cpp - ${TORCH_SRC_DIR}/csrc/api/src/nn/init.cpp - ${TORCH_SRC_DIR}/csrc/api/src/nn/module.cpp - ${TORCH_SRC_DIR}/csrc/api/src/nn/modules/_functions.cpp - ${TORCH_SRC_DIR}/csrc/api/src/nn/modules/activation.cpp - ${TORCH_SRC_DIR}/csrc/api/src/nn/modules/adaptive.cpp - ${TORCH_SRC_DIR}/csrc/api/src/nn/modules/batchnorm.cpp - ${TORCH_SRC_DIR}/csrc/api/src/nn/modules/normalization.cpp - ${TORCH_SRC_DIR}/csrc/api/src/nn/modules/instancenorm.cpp - ${TORCH_SRC_DIR}/csrc/api/src/nn/modules/conv.cpp - ${TORCH_SRC_DIR}/csrc/api/src/nn/modules/dropout.cpp - ${TORCH_SRC_DIR}/csrc/api/src/nn/modules/distance.cpp - ${TORCH_SRC_DIR}/csrc/api/src/nn/modules/embedding.cpp - ${TORCH_SRC_DIR}/csrc/api/src/nn/modules/fold.cpp - ${TORCH_SRC_DIR}/csrc/api/src/nn/modules/linear.cpp - ${TORCH_SRC_DIR}/csrc/api/src/nn/modules/loss.cpp - ${TORCH_SRC_DIR}/csrc/api/src/nn/modules/padding.cpp - ${TORCH_SRC_DIR}/csrc/api/src/nn/modules/pixelshuffle.cpp - ${TORCH_SRC_DIR}/csrc/api/src/nn/modules/pooling.cpp - ${TORCH_SRC_DIR}/csrc/api/src/nn/modules/rnn.cpp - ${TORCH_SRC_DIR}/csrc/api/src/nn/modules/upsampling.cpp - ${TORCH_SRC_DIR}/csrc/api/src/nn/modules/transformer.cpp - ${TORCH_SRC_DIR}/csrc/api/src/nn/modules/container/functional.cpp - ${TORCH_SRC_DIR}/csrc/api/src/nn/options/activation.cpp - ${TORCH_SRC_DIR}/csrc/api/src/nn/options/adaptive.cpp - ${TORCH_SRC_DIR}/csrc/api/src/nn/options/batchnorm.cpp - ${TORCH_SRC_DIR}/csrc/api/src/nn/options/embedding.cpp - ${TORCH_SRC_DIR}/csrc/api/src/nn/options/instancenorm.cpp - ${TORCH_SRC_DIR}/csrc/api/src/nn/options/normalization.cpp - ${TORCH_SRC_DIR}/csrc/api/src/nn/options/conv.cpp - ${TORCH_SRC_DIR}/csrc/api/src/nn/options/dropout.cpp - ${TORCH_SRC_DIR}/csrc/api/src/nn/options/linear.cpp - ${TORCH_SRC_DIR}/csrc/api/src/nn/options/padding.cpp - ${TORCH_SRC_DIR}/csrc/api/src/nn/options/pooling.cpp - ${TORCH_SRC_DIR}/csrc/api/src/nn/options/rnn.cpp - ${TORCH_SRC_DIR}/csrc/api/src/nn/options/vision.cpp - ${TORCH_SRC_DIR}/csrc/api/src/nn/options/transformer.cpp - ${TORCH_SRC_DIR}/csrc/api/src/optim/adagrad.cpp - ${TORCH_SRC_DIR}/csrc/api/src/optim/adam.cpp - ${TORCH_SRC_DIR}/csrc/api/src/optim/adamw.cpp - ${TORCH_SRC_DIR}/csrc/api/src/optim/lbfgs.cpp - ${TORCH_SRC_DIR}/csrc/api/src/optim/optimizer.cpp - ${TORCH_SRC_DIR}/csrc/api/src/optim/rmsprop.cpp - ${TORCH_SRC_DIR}/csrc/api/src/optim/serialize.cpp - ${TORCH_SRC_DIR}/csrc/api/src/optim/sgd.cpp - ${TORCH_SRC_DIR}/csrc/api/src/optim/schedulers/lr_scheduler.cpp - ${TORCH_SRC_DIR}/csrc/api/src/optim/schedulers/step_lr.cpp - ${TORCH_SRC_DIR}/csrc/api/src/serialize/input-archive.cpp - ${TORCH_SRC_DIR}/csrc/api/src/serialize/output-archive.cpp - ) +if(USE_ROCM) + list(APPEND Caffe2_HIP_SRCS ${Caffe2_GPU_HIP_JIT_FUSERS_SRCS}) + if(USE_NCCL) + list(APPEND Caffe2_HIP_SRCS + ${TORCH_SRC_DIR}/csrc/cuda/nccl.cpp) + endif() + if(USE_DISTRIBUTED) + append_filelist("libtorch_cuda_distributed_base_sources" Caffe2_HIP_SRCS) + if(NOT WIN32) + append_filelist("libtorch_cuda_distributed_extra_sources" Caffe2_HIP_SRCS) + endif() endif() + # caffe2_nvrtc's stubs to driver APIs are useful for HIP. + # See NOTE [ ATen NVRTC Stub and HIP ] + add_library(caffe2_nvrtc SHARED ${ATen_NVRTC_STUB_SRCS}) + target_link_libraries(caffe2_nvrtc ${PYTORCH_HIP_HCC_LIBRARIES} ${ROCM_HIPRTC_LIB}) + target_compile_definitions(caffe2_nvrtc PRIVATE USE_ROCM __HIP_PLATFORM_HCC__) + install(TARGETS caffe2_nvrtc DESTINATION "${TORCH_INSTALL_LIB_DIR}") +endif() - list(APPEND Caffe2_CPU_SRCS ${TORCH_SRCS}) +if(NOT NO_API AND NOT BUILD_LITE_INTERPRETER) + list(APPEND TORCH_SRCS + ${TORCH_SRC_DIR}/csrc/api/src/cuda.cpp + ${TORCH_SRC_DIR}/csrc/api/src/data/datasets/mnist.cpp + ${TORCH_SRC_DIR}/csrc/api/src/data/samplers/distributed.cpp + ${TORCH_SRC_DIR}/csrc/api/src/data/samplers/random.cpp + ${TORCH_SRC_DIR}/csrc/api/src/data/samplers/sequential.cpp + ${TORCH_SRC_DIR}/csrc/api/src/data/samplers/stream.cpp + ${TORCH_SRC_DIR}/csrc/api/src/enum.cpp + ${TORCH_SRC_DIR}/csrc/api/src/imethod.cpp + ${TORCH_SRC_DIR}/csrc/api/src/serialize.cpp + ${TORCH_SRC_DIR}/csrc/api/src/jit.cpp + ${TORCH_SRC_DIR}/csrc/api/src/nn/init.cpp + ${TORCH_SRC_DIR}/csrc/api/src/nn/module.cpp + ${TORCH_SRC_DIR}/csrc/api/src/nn/modules/_functions.cpp + ${TORCH_SRC_DIR}/csrc/api/src/nn/modules/activation.cpp + ${TORCH_SRC_DIR}/csrc/api/src/nn/modules/adaptive.cpp + ${TORCH_SRC_DIR}/csrc/api/src/nn/modules/batchnorm.cpp + ${TORCH_SRC_DIR}/csrc/api/src/nn/modules/normalization.cpp + ${TORCH_SRC_DIR}/csrc/api/src/nn/modules/instancenorm.cpp + ${TORCH_SRC_DIR}/csrc/api/src/nn/modules/conv.cpp + ${TORCH_SRC_DIR}/csrc/api/src/nn/modules/dropout.cpp + ${TORCH_SRC_DIR}/csrc/api/src/nn/modules/distance.cpp + ${TORCH_SRC_DIR}/csrc/api/src/nn/modules/embedding.cpp + ${TORCH_SRC_DIR}/csrc/api/src/nn/modules/fold.cpp + ${TORCH_SRC_DIR}/csrc/api/src/nn/modules/linear.cpp + ${TORCH_SRC_DIR}/csrc/api/src/nn/modules/loss.cpp + ${TORCH_SRC_DIR}/csrc/api/src/nn/modules/padding.cpp + ${TORCH_SRC_DIR}/csrc/api/src/nn/modules/pixelshuffle.cpp + ${TORCH_SRC_DIR}/csrc/api/src/nn/modules/pooling.cpp + ${TORCH_SRC_DIR}/csrc/api/src/nn/modules/rnn.cpp + ${TORCH_SRC_DIR}/csrc/api/src/nn/modules/upsampling.cpp + ${TORCH_SRC_DIR}/csrc/api/src/nn/modules/transformer.cpp + ${TORCH_SRC_DIR}/csrc/api/src/nn/modules/container/functional.cpp + ${TORCH_SRC_DIR}/csrc/api/src/nn/options/activation.cpp + ${TORCH_SRC_DIR}/csrc/api/src/nn/options/adaptive.cpp + ${TORCH_SRC_DIR}/csrc/api/src/nn/options/batchnorm.cpp + ${TORCH_SRC_DIR}/csrc/api/src/nn/options/embedding.cpp + ${TORCH_SRC_DIR}/csrc/api/src/nn/options/instancenorm.cpp + ${TORCH_SRC_DIR}/csrc/api/src/nn/options/normalization.cpp + ${TORCH_SRC_DIR}/csrc/api/src/nn/options/conv.cpp + ${TORCH_SRC_DIR}/csrc/api/src/nn/options/dropout.cpp + ${TORCH_SRC_DIR}/csrc/api/src/nn/options/linear.cpp + ${TORCH_SRC_DIR}/csrc/api/src/nn/options/padding.cpp + ${TORCH_SRC_DIR}/csrc/api/src/nn/options/pooling.cpp + ${TORCH_SRC_DIR}/csrc/api/src/nn/options/rnn.cpp + ${TORCH_SRC_DIR}/csrc/api/src/nn/options/vision.cpp + ${TORCH_SRC_DIR}/csrc/api/src/nn/options/transformer.cpp + ${TORCH_SRC_DIR}/csrc/api/src/optim/adagrad.cpp + ${TORCH_SRC_DIR}/csrc/api/src/optim/adam.cpp + ${TORCH_SRC_DIR}/csrc/api/src/optim/adamw.cpp + ${TORCH_SRC_DIR}/csrc/api/src/optim/lbfgs.cpp + ${TORCH_SRC_DIR}/csrc/api/src/optim/optimizer.cpp + ${TORCH_SRC_DIR}/csrc/api/src/optim/rmsprop.cpp + ${TORCH_SRC_DIR}/csrc/api/src/optim/serialize.cpp + ${TORCH_SRC_DIR}/csrc/api/src/optim/sgd.cpp + ${TORCH_SRC_DIR}/csrc/api/src/optim/schedulers/lr_scheduler.cpp + ${TORCH_SRC_DIR}/csrc/api/src/optim/schedulers/step_lr.cpp + ${TORCH_SRC_DIR}/csrc/api/src/serialize/input-archive.cpp + ${TORCH_SRC_DIR}/csrc/api/src/serialize/output-archive.cpp + ) endif() +list(APPEND Caffe2_CPU_SRCS ${TORCH_SRCS}) + if(USE_MPS) list(APPEND Caffe2_CPU_SRCS ${Caffe2_MPS_SRCS}) endif() @@ -1079,47 +1075,46 @@ if(BUILD_LITE_INTERPRETER AND SELECTED_OP_LIST) add_dependencies(torch_cpu __selected_mobile_ops_header_gen) endif() -if(NOT INTERN_BUILD_MOBILE OR NOT BUILD_CAFFE2_MOBILE) - if(NOT NO_API) - target_include_directories(torch_cpu PRIVATE - ${TORCH_SRC_DIR}/csrc/api - ${TORCH_SRC_DIR}/csrc/api/include) - endif() - - if(BUILD_SPLIT_CUDA AND MSVC) - # -INCLUDE is used to ensure torch_cuda_cpp/cu are linked against in a project that relies on them. - target_link_libraries(torch_cuda_cpp INTERFACE "-INCLUDE:?warp_size@cuda@at@@YAHXZ") - # See [Note about _torch_cuda_cu_linker_symbol_op and torch_cuda_cu] in native_functions.yaml - target_link_libraries(torch_cuda_cu INTERFACE "-INCLUDE:?_torch_cuda_cu_linker_symbol_op_cuda@native@at@@YA?AVTensor@2@AEBV32@@Z") - elseif(USE_CUDA AND MSVC) - # -INCLUDE is used to ensure torch_cuda is linked against in a project that relies on them. - # Related issue: https://github.com/pytorch/pytorch/issues/31611 - target_link_libraries(torch_cuda INTERFACE "-INCLUDE:?warp_size@cuda@at@@YAHXZ") - endif() - - if(NOT BUILD_LITE_INTERPRETER) - set(TH_CPU_INCLUDE - # dense - aten/src/TH - ${CMAKE_CURRENT_BINARY_DIR}/aten/src/TH - ${TORCH_ROOT}/aten/src - ${CMAKE_CURRENT_BINARY_DIR}/aten/src - - ${CMAKE_BINARY_DIR}/aten/src) - target_include_directories(torch_cpu PRIVATE ${TH_CPU_INCLUDE}) - endif() - - set(ATen_CPU_INCLUDE +if(NOT NO_API) + target_include_directories(torch_cpu PRIVATE + ${TORCH_SRC_DIR}/csrc/api + ${TORCH_SRC_DIR}/csrc/api/include) +endif() + +if(BUILD_SPLIT_CUDA AND MSVC) + # -INCLUDE is used to ensure torch_cuda_cpp/cu are linked against in a project that relies on them. + target_link_libraries(torch_cuda_cpp INTERFACE "-INCLUDE:?warp_size@cuda@at@@YAHXZ") + # See [Note about _torch_cuda_cu_linker_symbol_op and torch_cuda_cu] in native_functions.yaml + target_link_libraries(torch_cuda_cu INTERFACE "-INCLUDE:?_torch_cuda_cu_linker_symbol_op_cuda@native@at@@YA?AVTensor@2@AEBV32@@Z") +elseif(USE_CUDA AND MSVC) + # -INCLUDE is used to ensure torch_cuda is linked against in a project that relies on them. + # Related issue: https://github.com/pytorch/pytorch/issues/31611 + target_link_libraries(torch_cuda INTERFACE "-INCLUDE:?warp_size@cuda@at@@YAHXZ") +endif() + +if(NOT BUILD_LITE_INTERPRETER) + set(TH_CPU_INCLUDE + # dense + aten/src/TH + ${CMAKE_CURRENT_BINARY_DIR}/aten/src/TH ${TORCH_ROOT}/aten/src - ${CMAKE_CURRENT_BINARY_DIR}/../aten/src + ${CMAKE_CURRENT_BINARY_DIR}/aten/src + ${CMAKE_BINARY_DIR}/aten/src) + target_include_directories(torch_cpu PRIVATE ${TH_CPU_INCLUDE}) +endif() - if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/../aten/src/ATen/native/QuantizedLinear.cpp PROPERTIES COMPILE_FLAGS -Wno-deprecated-declarations) - set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/../aten/src/ATen/native/RNN.cpp PROPERTIES COMPILE_FLAGS -Wno-deprecated-declarations) - set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/../aten/src/ATen/native/quantized/cpu/qlinear_prepack.cpp PROPERTIES COMPILE_FLAGS -Wno-deprecated-declarations) - set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/../aten/src/ATen/native/quantized/qlinear_unpack.cpp PROPERTIES COMPILE_FLAGS -Wno-deprecated-declarations) - endif() +set(ATen_CPU_INCLUDE + ${TORCH_ROOT}/aten/src + ${CMAKE_CURRENT_BINARY_DIR}/../aten/src + ${CMAKE_BINARY_DIR}/aten/src) + +if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/../aten/src/ATen/native/QuantizedLinear.cpp PROPERTIES COMPILE_FLAGS -Wno-deprecated-declarations) + set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/../aten/src/ATen/native/RNN.cpp PROPERTIES COMPILE_FLAGS -Wno-deprecated-declarations) + set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/../aten/src/ATen/native/quantized/cpu/qlinear_prepack.cpp PROPERTIES COMPILE_FLAGS -Wno-deprecated-declarations) + set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/../aten/src/ATen/native/quantized/qlinear_unpack.cpp PROPERTIES COMPILE_FLAGS -Wno-deprecated-declarations) +endif() if(USE_TBB) list(APPEND ATen_CPU_INCLUDE ${TBB_INCLUDE_DIR}) @@ -1131,135 +1126,128 @@ if(BUILD_CAFFE2 AND BUILD_CAFFE2_OPS AND USE_FBGEMM) target_include_directories(torch_cpu PRIVATE ${CMAKE_CURRENT_LIST_DIR}/../third_party) endif() - target_include_directories(torch_cpu PRIVATE ${ATen_CPU_INCLUDE}) +target_include_directories(torch_cpu PRIVATE ${ATen_CPU_INCLUDE}) - target_include_directories(torch_cpu PRIVATE - ${TORCH_SRC_DIR}/csrc) +target_include_directories(torch_cpu PRIVATE + ${TORCH_SRC_DIR}/csrc) - target_include_directories(torch_cpu PRIVATE - ${TORCH_ROOT}/third_party/miniz-2.1.0) - - target_include_directories(torch_cpu PRIVATE - ${TORCH_ROOT}/third_party/kineto/libkineto/include) +target_include_directories(torch_cpu PRIVATE + ${TORCH_ROOT}/third_party/miniz-2.1.0) - if(USE_KINETO) - target_include_directories(torch_cpu PRIVATE - ${TORCH_ROOT}/third_party/kineto/libkineto/src) - endif() +target_include_directories(torch_cpu PRIVATE + ${TORCH_ROOT}/third_party/kineto/libkineto/include) - install(DIRECTORY "${TORCH_SRC_DIR}/csrc" - DESTINATION ${TORCH_INSTALL_INCLUDE_DIR}/torch - FILES_MATCHING PATTERN "*.h" PATTERN "*.hpp") - install(DIRECTORY "${TORCH_SRC_DIR}/csrc/distributed/c10d" - DESTINATION ${TORCH_INSTALL_INCLUDE_DIR} - FILES_MATCHING PATTERN "*.h" PATTERN "*.hpp") +if(USE_KINETO) + target_include_directories(torch_cpu PRIVATE + ${TORCH_ROOT}/third_party/kineto/libkineto/src) +endif() + +install(DIRECTORY "${TORCH_SRC_DIR}/csrc" + DESTINATION ${TORCH_INSTALL_INCLUDE_DIR}/torch + FILES_MATCHING PATTERN "*.h" PATTERN "*.hpp") +install(DIRECTORY "${TORCH_SRC_DIR}/csrc/distributed/c10d" + DESTINATION ${TORCH_INSTALL_INCLUDE_DIR} + FILES_MATCHING PATTERN "*.h" PATTERN "*.hpp") +install(FILES + "${TORCH_SRC_DIR}/script.h" + "${TORCH_SRC_DIR}/extension.h" + "${TORCH_SRC_DIR}/custom_class.h" + "${TORCH_SRC_DIR}/library.h" + "${TORCH_SRC_DIR}/custom_class_detail.h" + DESTINATION ${TORCH_INSTALL_INCLUDE_DIR}/torch) +if(USE_DEPLOY) install(FILES - "${TORCH_SRC_DIR}/script.h" - "${TORCH_SRC_DIR}/extension.h" - "${TORCH_SRC_DIR}/custom_class.h" - "${TORCH_SRC_DIR}/library.h" - "${TORCH_SRC_DIR}/custom_class_detail.h" + "${TORCH_SRC_DIR}/deploy.h" DESTINATION ${TORCH_INSTALL_INCLUDE_DIR}/torch) - if(USE_DEPLOY) - install(FILES - "${TORCH_SRC_DIR}/deploy.h" - DESTINATION ${TORCH_INSTALL_INCLUDE_DIR}/torch) - endif() +endif() - if(BUILD_TEST) - if(BUILD_LITE_INTERPRETER) - add_subdirectory( - ${TORCH_ROOT}/test/cpp/lite_interpreter_runtime - ${CMAKE_BINARY_DIR}/test_lite_interpreter_runtime - ) - add_subdirectory( - ${TORCH_ROOT}/test/mobile/lightweight_dispatch - ${CMAKE_BINARY_DIR}/test_codegen_unboxing - ) - else() - add_subdirectory(${TORCH_ROOT}/test/cpp/jit ${CMAKE_BINARY_DIR}/test_jit) - add_subdirectory( - ${TORCH_ROOT}/test/cpp/tensorexpr - ${CMAKE_BINARY_DIR}/test_tensorexpr - ) - if(USE_DISTRIBUTED) - add_subdirectory(${TORCH_ROOT}/test/cpp/c10d ${CMAKE_BINARY_DIR}/test_cpp_c10d) - if(NOT WIN32) - add_subdirectory(${TORCH_ROOT}/test/cpp/dist_autograd ${CMAKE_BINARY_DIR}/dist_autograd) - add_subdirectory(${TORCH_ROOT}/test/cpp/rpc ${CMAKE_BINARY_DIR}/test_cpp_rpc) - endif() - endif() - if(NOT NO_API) - add_subdirectory(${TORCH_ROOT}/test/cpp/api ${CMAKE_BINARY_DIR}/test_api) +if(BUILD_TEST) + if(BUILD_LITE_INTERPRETER) + add_subdirectory( + ${TORCH_ROOT}/test/cpp/lite_interpreter_runtime + ${CMAKE_BINARY_DIR}/test_lite_interpreter_runtime + ) + add_subdirectory( + ${TORCH_ROOT}/test/mobile/lightweight_dispatch + ${CMAKE_BINARY_DIR}/test_codegen_unboxing + ) + else() + add_subdirectory(${TORCH_ROOT}/test/cpp/jit ${CMAKE_BINARY_DIR}/test_jit) + add_subdirectory( + ${TORCH_ROOT}/test/cpp/tensorexpr + ${CMAKE_BINARY_DIR}/test_tensorexpr + ) + if(USE_DISTRIBUTED) + add_subdirectory(${TORCH_ROOT}/test/cpp/c10d ${CMAKE_BINARY_DIR}/test_cpp_c10d) + if(NOT WIN32) + add_subdirectory(${TORCH_ROOT}/test/cpp/dist_autograd ${CMAKE_BINARY_DIR}/dist_autograd) + add_subdirectory(${TORCH_ROOT}/test/cpp/rpc ${CMAKE_BINARY_DIR}/test_cpp_rpc) endif() + endif() + if(NOT NO_API) + add_subdirectory(${TORCH_ROOT}/test/cpp/api ${CMAKE_BINARY_DIR}/test_api) + endif() - if(USE_LLVM AND LLVM_FOUND) - add_subdirectory( - ${TORCH_ROOT}/test/mobile/nnc - ${CMAKE_BINARY_DIR}/test_mobile_nnc - ) - endif() - add_subdirectory(${TORCH_ROOT}/test/cpp/lazy - ${CMAKE_BINARY_DIR}/test_lazy) + if(USE_LLVM AND LLVM_FOUND) + add_subdirectory( + ${TORCH_ROOT}/test/mobile/nnc + ${CMAKE_BINARY_DIR}/test_mobile_nnc + ) endif() + add_subdirectory(${TORCH_ROOT}/test/cpp/lazy + ${CMAKE_BINARY_DIR}/test_lazy) endif() +endif() - # XXX This ABI check cannot be run with arm-linux-androideabi-g++ - if(CMAKE_SYSTEM_NAME STREQUAL "Linux") - if(DEFINED GLIBCXX_USE_CXX11_ABI) - message(STATUS "_GLIBCXX_USE_CXX11_ABI is already defined as a cmake variable") - else() - message(STATUS "${CMAKE_CXX_COMPILER} ${TORCH_SRC_DIR}/abi-check.cpp -o ${CMAKE_BINARY_DIR}/abi-check") - execute_process( - COMMAND - "${CMAKE_CXX_COMPILER}" - "${TORCH_SRC_DIR}/abi-check.cpp" - "-o" - "${CMAKE_BINARY_DIR}/abi-check" - RESULT_VARIABLE ABI_CHECK_COMPILE_RESULT) - if(ABI_CHECK_COMPILE_RESULT) - message(FATAL_ERROR "Could not compile ABI Check: ${ABI_CHECK_COMPILE_RESULT}") - endif() - execute_process( - COMMAND "${CMAKE_BINARY_DIR}/abi-check" - RESULT_VARIABLE ABI_CHECK_RESULT - OUTPUT_VARIABLE GLIBCXX_USE_CXX11_ABI) - if(ABI_CHECK_RESULT) - message(WARNING "Could not run ABI Check: ${ABI_CHECK_RESULT}") - endif() +# XXX This ABI check cannot be run with arm-linux-androideabi-g++ +if(CMAKE_SYSTEM_NAME STREQUAL "Linux") + if(DEFINED GLIBCXX_USE_CXX11_ABI) + message(STATUS "_GLIBCXX_USE_CXX11_ABI is already defined as a cmake variable") + else() + message(STATUS "${CMAKE_CXX_COMPILER} ${TORCH_SRC_DIR}/abi-check.cpp -o ${CMAKE_BINARY_DIR}/abi-check") + execute_process( + COMMAND + "${CMAKE_CXX_COMPILER}" + "${TORCH_SRC_DIR}/abi-check.cpp" + "-o" + "${CMAKE_BINARY_DIR}/abi-check" + RESULT_VARIABLE ABI_CHECK_COMPILE_RESULT) + if(ABI_CHECK_COMPILE_RESULT) + message(FATAL_ERROR "Could not compile ABI Check: ${ABI_CHECK_COMPILE_RESULT}") endif() - message(STATUS "Determined _GLIBCXX_USE_CXX11_ABI=${GLIBCXX_USE_CXX11_ABI}") - endif() - - # CMake config for external projects. - configure_file( - ${PROJECT_SOURCE_DIR}/cmake/TorchConfigVersion.cmake.in - ${PROJECT_BINARY_DIR}/TorchConfigVersion.cmake - @ONLY) - configure_file( - ${TORCH_ROOT}/cmake/TorchConfig.cmake.in - ${PROJECT_BINARY_DIR}/TorchConfig.cmake - @ONLY) - install(FILES - ${PROJECT_BINARY_DIR}/TorchConfigVersion.cmake - ${PROJECT_BINARY_DIR}/TorchConfig.cmake - DESTINATION share/cmake/Torch) + execute_process( + COMMAND "${CMAKE_BINARY_DIR}/abi-check" + RESULT_VARIABLE ABI_CHECK_RESULT + OUTPUT_VARIABLE GLIBCXX_USE_CXX11_ABI) + if(ABI_CHECK_RESULT) + message(WARNING "Could not run ABI Check: ${ABI_CHECK_RESULT}") + endif() + endif() + message(STATUS "Determined _GLIBCXX_USE_CXX11_ABI=${GLIBCXX_USE_CXX11_ABI}") +endif() +# CMake config for external projects. +configure_file( + ${PROJECT_SOURCE_DIR}/cmake/TorchConfigVersion.cmake.in + ${PROJECT_BINARY_DIR}/TorchConfigVersion.cmake + @ONLY) +configure_file( + ${TORCH_ROOT}/cmake/TorchConfig.cmake.in + ${PROJECT_BINARY_DIR}/TorchConfig.cmake + @ONLY) +install(FILES + ${PROJECT_BINARY_DIR}/TorchConfigVersion.cmake + ${PROJECT_BINARY_DIR}/TorchConfig.cmake + DESTINATION share/cmake/Torch) - # ---[ Torch python bindings build - add_subdirectory(../torch torch) +# ---[ Torch python bindings build +add_subdirectory(../torch torch) -endif() # ========================================================== # END formerly-libtorch flags # ========================================================== - - - - - if(NOT NO_API) target_include_directories(torch_cpu PUBLIC $ @@ -1399,7 +1387,7 @@ if(USE_DISTRIBUTED) endif() endif() -if(NOT INTERN_BUILD_MOBILE OR BUILD_CAFFE2_MOBILE) +if(NOT INTERN_BUILD_MOBILE) caffe2_interface_library(caffe2_protos caffe2_protos_whole) target_link_libraries(torch_cpu PRIVATE caffe2_protos_whole) if(${CAFFE2_LINK_LOCAL_PROTOBUF}) diff --git a/caffe2/core/CMakeLists.txt b/caffe2/core/CMakeLists.txt index 91cd11551b344..f59c0e703edf7 100644 --- a/caffe2/core/CMakeLists.txt +++ b/caffe2/core/CMakeLists.txt @@ -1,4 +1,4 @@ -if((NOT BUILD_CAFFE2) OR (INTERN_BUILD_MOBILE AND NOT BUILD_CAFFE2_MOBILE)) +if(NOT BUILD_CAFFE2 OR INTERN_BUILD_MOBILE) list(APPEND Caffe2_CPU_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/common.cc" ) diff --git a/caffe2/perfkernels/CMakeLists.txt b/caffe2/perfkernels/CMakeLists.txt index 4316900ba56a6..9510ec60dfef0 100644 --- a/caffe2/perfkernels/CMakeLists.txt +++ b/caffe2/perfkernels/CMakeLists.txt @@ -1,4 +1,4 @@ -if(INTERN_BUILD_MOBILE AND NOT BUILD_CAFFE2_MOBILE) +if(INTERN_BUILD_MOBILE) list(APPEND Caffe2_CPU_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/embedding_lookup_idx.cc" ) diff --git a/caffe2/utils/CMakeLists.txt b/caffe2/utils/CMakeLists.txt index 3e059d3f5eb38..a7dfe1181e31e 100644 --- a/caffe2/utils/CMakeLists.txt +++ b/caffe2/utils/CMakeLists.txt @@ -1,4 +1,4 @@ -if((NOT BUILD_CAFFE2) OR (INTERN_BUILD_MOBILE AND NOT BUILD_CAFFE2_MOBILE)) +if(NOT BUILD_CAFFE2 OR INTERN_BUILD_MOBILE) list(APPEND Caffe2_CPU_SRCS utils/string_utils.cc utils/threadpool/ThreadPool.cc diff --git a/cmake/Dependencies.cmake b/cmake/Dependencies.cmake index 0e96653967da6..873ea3e13105a 100644 --- a/cmake/Dependencies.cmake +++ b/cmake/Dependencies.cmake @@ -78,7 +78,7 @@ if(USE_CUDA) endif() # ---[ Custom Protobuf -if(CAFFE2_CMAKE_BUILDING_WITH_MAIN_REPO AND (NOT INTERN_BUILD_MOBILE OR BUILD_CAFFE2_MOBILE)) +if(CAFFE2_CMAKE_BUILDING_WITH_MAIN_REPO AND NOT INTERN_BUILD_MOBILE) disable_ubsan() include(${CMAKE_CURRENT_LIST_DIR}/ProtoBuf.cmake) enable_ubsan() diff --git a/cmake/Summary.cmake b/cmake/Summary.cmake index a9c6201fb6bef..27f8381209e6a 100644 --- a/cmake/Summary.cmake +++ b/cmake/Summary.cmake @@ -26,7 +26,6 @@ function(caffe2_print_configuration_summary) message(STATUS " CAFFE2_VERSION : ${CAFFE2_VERSION}") message(STATUS " BUILD_CAFFE2 : ${BUILD_CAFFE2}") message(STATUS " BUILD_CAFFE2_OPS : ${BUILD_CAFFE2_OPS}") - message(STATUS " BUILD_CAFFE2_MOBILE : ${BUILD_CAFFE2_MOBILE}") message(STATUS " BUILD_STATIC_RUNTIME_BENCHMARK: ${BUILD_STATIC_RUNTIME_BENCHMARK}") message(STATUS " BUILD_TENSOREXPR_BENCHMARK: ${BUILD_TENSOREXPR_BENCHMARK}") message(STATUS " BUILD_NVFUSER_BENCHMARK: ${BUILD_NVFUSER_BENCHMARK}") diff --git a/cmake/public/utils.cmake b/cmake/public/utils.cmake index b0c4cc6f08b56..5944a5a1a6269 100644 --- a/cmake/public/utils.cmake +++ b/cmake/public/utils.cmake @@ -415,72 +415,70 @@ function(torch_compile_options libname) list(APPEND private_compile_options -Werror) endif() - if(NOT INTERN_BUILD_MOBILE OR NOT BUILD_CAFFE2_MOBILE) - # until they can be unified, keep these lists synced with setup.py - if(MSVC) + # until they can be unified, keep these lists synced with setup.py + if(MSVC) - if(MSVC_Z7_OVERRIDE) - set(MSVC_DEBINFO_OPTION "/Z7") - else() - set(MSVC_DEBINFO_OPTION "/Zi") - endif() + if(MSVC_Z7_OVERRIDE) + set(MSVC_DEBINFO_OPTION "/Z7") + else() + set(MSVC_DEBINFO_OPTION "/Zi") + endif() - target_compile_options(${libname} PUBLIC - $<$: - ${MSVC_RUNTIME_LIBRARY_OPTION} - $<$,$>:${MSVC_DEBINFO_OPTION}> - /EHsc - /DNOMINMAX - /wd4267 - /wd4251 - /wd4522 - /wd4522 - /wd4838 - /wd4305 - /wd4244 - /wd4190 - /wd4101 - /wd4996 - /wd4275 - /bigobj> - ) + target_compile_options(${libname} PUBLIC + $<$: + ${MSVC_RUNTIME_LIBRARY_OPTION} + $<$,$>:${MSVC_DEBINFO_OPTION}> + /EHsc + /DNOMINMAX + /wd4267 + /wd4251 + /wd4522 + /wd4522 + /wd4838 + /wd4305 + /wd4244 + /wd4190 + /wd4101 + /wd4996 + /wd4275 + /bigobj> + ) + else() + list(APPEND private_compile_options + -Wall + -Wextra + -Wno-unused-parameter + -Wno-unused-function + -Wno-unused-result + -Wno-missing-field-initializers + -Wno-write-strings + -Wno-unknown-pragmas + -Wno-type-limits + -Wno-array-bounds + -Wno-unknown-pragmas + -Wno-sign-compare + -Wno-strict-overflow + -Wno-strict-aliasing + -Wno-error=deprecated-declarations + # Clang has an unfixed bug leading to spurious missing braces + # warnings, see https://bugs.llvm.org/show_bug.cgi?id=21629 + -Wno-missing-braces + ) + if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") + list(APPEND private_compile_options + -Wno-range-loop-analysis) else() list(APPEND private_compile_options - -Wall - -Wextra - -Wno-unused-parameter - -Wno-unused-function - -Wno-unused-result - -Wno-missing-field-initializers - -Wno-write-strings - -Wno-unknown-pragmas - -Wno-type-limits - -Wno-array-bounds - -Wno-unknown-pragmas - -Wno-sign-compare - -Wno-strict-overflow - -Wno-strict-aliasing - -Wno-error=deprecated-declarations - # Clang has an unfixed bug leading to spurious missing braces - # warnings, see https://bugs.llvm.org/show_bug.cgi?id=21629 - -Wno-missing-braces - ) - if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") - list(APPEND private_compile_options - -Wno-range-loop-analysis) - else() - list(APPEND private_compile_options - # Considered to be flaky. See the discussion at - # https://github.com/pytorch/pytorch/pull/9608 - -Wno-maybe-uninitialized) - endif() - + # Considered to be flaky. See the discussion at + # https://github.com/pytorch/pytorch/pull/9608 + -Wno-maybe-uninitialized) endif() - if(MSVC) - elseif(WERROR) - list(APPEND private_compile_options -Wno-strict-overflow) - endif() + endif() + + if(MSVC) + elseif(WERROR) + list(APPEND private_compile_options -Wno-strict-overflow) endif() target_compile_options(${libname} PRIVATE diff --git a/scripts/build_android.sh b/scripts/build_android.sh index 225caa68abfcd..2d6f051ea19fe 100755 --- a/scripts/build_android.sh +++ b/scripts/build_android.sh @@ -59,30 +59,20 @@ echo "Android NDK version: $ANDROID_NDK_VERSION" CMAKE_ARGS=() -if [ -z "${BUILD_CAFFE2_MOBILE:-}" ]; then - # Build PyTorch mobile - CMAKE_ARGS+=("-DCMAKE_PREFIX_PATH=$($PYTHON -c 'import sysconfig; print(sysconfig.get_path("purelib"))')") - CMAKE_ARGS+=("-DPYTHON_EXECUTABLE=$($PYTHON -c 'import sys; print(sys.executable)')") - CMAKE_ARGS+=("-DBUILD_CUSTOM_PROTOBUF=OFF") - # custom build with selected ops - if [ -n "${SELECTED_OP_LIST}" ]; then - SELECTED_OP_LIST="$(cd $(dirname $SELECTED_OP_LIST); pwd -P)/$(basename $SELECTED_OP_LIST)" - echo "Choose SELECTED_OP_LIST file: $SELECTED_OP_LIST" - if [ ! -r ${SELECTED_OP_LIST} ]; then - echo "Error: SELECTED_OP_LIST file ${SELECTED_OP_LIST} not found." - exit 1 - fi - CMAKE_ARGS+=("-DSELECTED_OP_LIST=${SELECTED_OP_LIST}") +# Build PyTorch mobile +CMAKE_ARGS+=("-DCMAKE_PREFIX_PATH=$($PYTHON -c 'import sysconfig; print(sysconfig.get_path("purelib"))')") +CMAKE_ARGS+=("-DPYTHON_EXECUTABLE=$($PYTHON -c 'import sys; print(sys.executable)')") +CMAKE_ARGS+=("-DBUILD_CUSTOM_PROTOBUF=OFF") + +# custom build with selected ops +if [ -n "${SELECTED_OP_LIST}" ]; then + SELECTED_OP_LIST="$(cd $(dirname $SELECTED_OP_LIST); pwd -P)/$(basename $SELECTED_OP_LIST)" + echo "Choose SELECTED_OP_LIST file: $SELECTED_OP_LIST" + if [ ! -r ${SELECTED_OP_LIST} ]; then + echo "Error: SELECTED_OP_LIST file ${SELECTED_OP_LIST} not found." + exit 1 fi -else - # Build Caffe2 mobile - CMAKE_ARGS+=("-DBUILD_CAFFE2_MOBILE=ON") - # Build protobuf from third_party so we have a host protoc binary. - echo "Building protoc" - $CAFFE2_ROOT/scripts/build_host_protoc.sh - # Use locally built protoc because we'll build libprotobuf for the - # target architecture and need an exact version match. - CMAKE_ARGS+=("-DCAFFE2_CUSTOM_PROTOC_EXECUTABLE=$CAFFE2_ROOT/build_host_protoc/bin/protoc") + CMAKE_ARGS+=("-DSELECTED_OP_LIST=${SELECTED_OP_LIST}") fi # If Ninja is installed, prefer it to Make diff --git a/scripts/build_ios.sh b/scripts/build_ios.sh index a0402db65a79b..335d14b52171a 100755 --- a/scripts/build_ios.sh +++ b/scripts/build_ios.sh @@ -11,37 +11,24 @@ CAFFE2_ROOT="$( cd "$(dirname "$0")"/.. ; pwd -P)" CMAKE_ARGS=() -if [ -z "${BUILD_CAFFE2_MOBILE:-}" ]; then - # Build PyTorch mobile - CMAKE_ARGS+=("-DCMAKE_PREFIX_PATH=$(python -c 'import sysconfig; print(sysconfig.get_path("purelib"))')") - CMAKE_ARGS+=("-DPYTHON_EXECUTABLE=$(python -c 'import sys; print(sys.executable)')") - CMAKE_ARGS+=("-DBUILD_CUSTOM_PROTOBUF=OFF") - # custom build with selected ops - if [ -n "${SELECTED_OP_LIST}" ]; then - SELECTED_OP_LIST="$(cd $(dirname $SELECTED_OP_LIST); pwd -P)/$(basename $SELECTED_OP_LIST)" - echo "Choose SELECTED_OP_LIST file: $SELECTED_OP_LIST" - if [ ! -r ${SELECTED_OP_LIST} ]; then - echo "Error: SELECTED_OP_LIST file ${SELECTED_OP_LIST} not found." - exit 1 - fi - CMAKE_ARGS+=("-DSELECTED_OP_LIST=${SELECTED_OP_LIST}") +# Build PyTorch mobile +CMAKE_ARGS+=("-DCMAKE_PREFIX_PATH=$(python -c 'import sysconfig; print(sysconfig.get_path("purelib"))')") +CMAKE_ARGS+=("-DPYTHON_EXECUTABLE=$(python -c 'import sys; print(sys.executable)')") +CMAKE_ARGS+=("-DBUILD_CUSTOM_PROTOBUF=OFF") + +# custom build with selected ops +if [ -n "${SELECTED_OP_LIST}" ]; then + SELECTED_OP_LIST="$(cd $(dirname $SELECTED_OP_LIST); pwd -P)/$(basename $SELECTED_OP_LIST)" + echo "Choose SELECTED_OP_LIST file: $SELECTED_OP_LIST" + if [ ! -r ${SELECTED_OP_LIST} ]; then + echo "Error: SELECTED_OP_LIST file ${SELECTED_OP_LIST} not found." + exit 1 fi - # bitcode - if [ "${ENABLE_BITCODE:-}" == '1' ]; then - CMAKE_ARGS+=("-DCMAKE_C_FLAGS=-fembed-bitcode") - CMAKE_ARGS+=("-DCMAKE_CXX_FLAGS=-fembed-bitcode") - fi -else - # Build Caffe2 mobile - CMAKE_ARGS+=("-DBUILD_CAFFE2_MOBILE=ON") - # Build protobuf from third_party so we have a host protoc binary. - echo "Building protoc" - BITCODE_FLAGS="-DCMAKE_C_FLAGS=-fembed-bitcode -DCMAKE_CXX_FLAGS=-fembed-bitcode " - $CAFFE2_ROOT/scripts/build_host_protoc.sh --other-flags $BITCODE_FLAGS - # Use locally built protoc because we'll build libprotobuf for the - # target architecture and need an exact version match. - CMAKE_ARGS+=("-DCAFFE2_CUSTOM_PROTOC_EXECUTABLE=$CAFFE2_ROOT/build_host_protoc/bin/protoc") - # Bitcode is enabled by default for caffe2 + CMAKE_ARGS+=("-DSELECTED_OP_LIST=${SELECTED_OP_LIST}") +fi + +# bitcode +if [ "${ENABLE_BITCODE:-}" == '1' ]; then CMAKE_ARGS+=("-DCMAKE_C_FLAGS=-fembed-bitcode") CMAKE_ARGS+=("-DCMAKE_CXX_FLAGS=-fembed-bitcode") fi