Skip to content

Commit

Permalink
Remove caffe2 from more build files (pytorch#125898)
Browse files Browse the repository at this point in the history
Co-authored-by: Aaron Gokaslan <[email protected]>
Pull Request resolved: pytorch#125898
Approved by: https://github.com/Skylion007
  • Loading branch information
r-barnes authored and pytorchmergebot committed May 13, 2024
1 parent b620231 commit b9e7b35
Show file tree
Hide file tree
Showing 70 changed files with 36 additions and 5,361 deletions.
5 changes: 0 additions & 5 deletions .ci/pytorch/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,6 @@ if [[ "$BUILD_ENVIRONMENT" == *cuda11* ]]; then
fi
fi

if [[ ${BUILD_ENVIRONMENT} == *"caffe2"* ]]; then
echo "Caffe2 build is ON"
export BUILD_CAFFE2=ON
fi

if [[ ${BUILD_ENVIRONMENT} == *"paralleltbb"* ]]; then
export ATEN_THREADING=TBB
export USE_TBB=1
Expand Down
12 changes: 0 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,7 @@ option(BUILD_BINARY "Build C++ binaries" OFF)
option(BUILD_DOCS "Build Caffe2 documentation" OFF)
option(BUILD_CUSTOM_PROTOBUF "Build and use Caffe2's own protobuf under third_party" ON)
option(BUILD_PYTHON "Build Python binaries" ON)
option(BUILD_CAFFE2 "Master flag to build Caffe2" OFF)
option(BUILD_LITE_INTERPRETER "Master flag to build Lite Interpreter" OFF)
cmake_dependent_option(
BUILD_CAFFE2_OPS "Build Caffe2 operators" ON
"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
Expand Down Expand Up @@ -635,7 +631,6 @@ if(INTERN_BUILD_MOBILE)
endif()
set(BUILD_PYTHON OFF)
set(BUILD_FUNCTORCH OFF)
set(BUILD_CAFFE2_OPS OFF)
set(USE_DISTRIBUTED OFF)
set(NO_API ON)
set(USE_FBGEMM OFF)
Expand Down Expand Up @@ -1208,13 +1203,6 @@ else()
"shared libs.")
endif()

# ---[ Modules
# If master flag for buildling Caffe2 is disabled, we also disable the
# build for Caffe2 related operator modules.
if(BUILD_CAFFE2)
add_subdirectory(modules)
endif()

# ---[ Binaries
# Binaries will be built after the Caffe2 main libraries and the modules
# are built. For the binaries, they will be linked to the Caffe2 main
Expand Down
3 changes: 1 addition & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,6 @@ only interested in a specific component.
- Working on a test binary? Run `(cd build && ninja bin/test_binary_name)` to
rebuild only that test binary (without rerunning cmake). (Replace `ninja` with
`make` if you don't have ninja installed).
- Don't need Caffe2? Pass `BUILD_CAFFE2=0` to disable Caffe2 build.

On the initial build, you can also speed things up with the environment
variables `DEBUG`, `USE_DISTRIBUTED`, `USE_MKLDNN`, `USE_CUDA`, `USE_FLASH_ATTENTION`, `USE_MEM_EFF_ATTENTION`, `BUILD_TEST`, `USE_FBGEMM`, `USE_NNPACK` and `USE_QNNPACK`.
Expand Down Expand Up @@ -1196,7 +1195,7 @@ build_with_asan()
LDFLAGS="-stdlib=libstdc++" \
CFLAGS="-fsanitize=address -fno-sanitize-recover=all -shared-libasan -pthread" \
CXX_FLAGS="-pthread" \
USE_CUDA=0 USE_OPENMP=0 BUILD_CAFFE2_OPS=0 USE_DISTRIBUTED=0 DEBUG=1 \
USE_CUDA=0 USE_OPENMP=0 USE_DISTRIBUTED=0 DEBUG=1 \
python setup.py develop
}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ You can also pass the `CMAKE_VARS="..."` environment variable to specify additio
See [setup.py](./setup.py) for the list of available variables.

```bash
CMAKE_VARS="BUILD_CAFFE2=ON BUILD_CAFFE2_OPS=ON" make -f docker.Makefile
make -f docker.Makefile
```

### Building the Documentation
Expand Down
2 changes: 1 addition & 1 deletion aten/src/ATen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ if(NOT BUILD_LITE_INTERPRETER)
endif()
EXCLUDE(ATen_CORE_SRCS "${ATen_CORE_SRCS}" ${ATen_CORE_TEST_SRCS})
# Exclude TensorImpl_test.cpp if compiling without Caffe2
if(NOT BUILD_CAFFE2 AND NOT BUILD_LITE_INTERPRETER)
if(NOT BUILD_LITE_INTERPRETER)
file(GLOB_RECURSE ATen_CORE_EXCLUDED_TEST_SRCS "core/TensorImpl_test.cpp")
EXCLUDE(ATen_CORE_TEST_SRCS "${ATen_CORE_TEST_SRCS}" ${ATen_CORE_EXCLUDED_TEST_SRCS})
endif()
Expand Down
10 changes: 0 additions & 10 deletions aten/src/ATen/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,6 @@ list(APPEND ATen_XPU_TEST_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/xpu_generator_test.cpp
)

# Caffe2 specific tests
if(BUILD_CAFFE2)
list(APPEND ATen_CPU_TEST_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/ExclusivelyOwned_test.cpp
${CMAKE_CURRENT_SOURCE_DIR}/tensor_interop_test.cpp)
list(APPEND ATen_CUDA_TEST_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/cuda_tensor_interop_test.cpp)
endif()


# ---[ Send the lists to the parent scope.
set(ATen_CPU_TEST_SRCS ${ATen_CPU_TEST_SRCS} PARENT_SCOPE)
set(ATen_CUDA_TEST_SRCS ${ATen_CUDA_TEST_SRCS} PARENT_SCOPE)
Expand Down
10 changes: 0 additions & 10 deletions binaries/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,6 @@ if(INTERN_BUILD_MOBILE)
return()
endif()

if(BUILD_CAFFE2)
caffe2_binary_target("at_launch_benchmark.cc")
target_include_directories(at_launch_benchmark PUBLIC
${CMAKE_BINARY_DIR}/aten/src)

caffe2_binary_target("intra_inter_benchmark.cc")
target_include_directories(intra_inter_benchmark PUBLIC
${CMAKE_BINARY_DIR}/aten/src)
endif()

caffe2_binary_target("parallel_info.cc")
target_include_directories(parallel_info PUBLIC
${CMAKE_BINARY_DIR}/aten/src) # provides "ATen/TypeExtendedInterface.h" to ATen.h
Expand Down
1 change: 0 additions & 1 deletion buckbuild.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,6 @@ def get_pt_preprocessor_flags():
"-D_THP_CORE",
"-DUSE_SCALARS",
"-DNO_CUDNN_DESTROY_HANDLE",
"-DBUILD_CAFFE2",
]

if _is_build_mode_dev():
Expand Down
47 changes: 6 additions & 41 deletions caffe2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -110,21 +110,11 @@ endif()
add_subdirectory(core)
add_subdirectory(serialize)
add_subdirectory(utils)
if(BUILD_CAFFE2 OR (NOT USE_FBGEMM))
if(NOT USE_FBGEMM)
add_subdirectory(perfkernels)
endif()

# Skip modules that are not used by libtorch mobile yet.
if(BUILD_CAFFE2 AND NOT INTERN_BUILD_MOBILE)
add_subdirectory(core/nomnigraph)
if(USE_NVRTC)
add_subdirectory(cuda_rtc)
endif()
if(BUILD_CAFFE2_OPS)
endif()
add_subdirectory(proto)
endif()
if(NOT BUILD_CAFFE2 AND NOT INTERN_BUILD_MOBILE)
if(NOT INTERN_BUILD_MOBILE)
add_subdirectory(proto)
endif()

Expand Down Expand Up @@ -585,17 +575,10 @@ if(NOT INTERN_BUILD_MOBILE AND NOT BUILD_LITE_INTERPRETER)
${TORCH_SRC_DIR}/csrc/utils/byte_order.cpp
)

# 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()
set_source_files_properties(
${TORCH_SRC_DIR}/csrc/jit/serialization/import.cpp
PROPERTIES COMPILE_FLAGS "-DC10_DISABLE_LEGACY_IMPORT"
)
if(USE_DISTRIBUTED)
append_filelist("libtorch_distributed_base_sources" TORCH_SRCS)
if(NOT WIN32)
Expand Down Expand Up @@ -809,11 +792,6 @@ if(HAVE_SOVERSION)
VERSION ${TORCH_VERSION} SOVERSION ${TORCH_SOVERSION})
endif()
torch_compile_options(torch_cpu) # see cmake/public/utils.cmake
if(BUILD_CAFFE2 AND NOT MSVC)
# Caffe2 has too many signed-unsigned violation, but the framework is dead
# So no point in fixing those
target_compile_options(torch_cpu PRIVATE "-Wno-sign-compare")
endif()

# Ignore Wdeprecated-XXX errors from third-party libraries
if(NOT MSVC)
Expand Down Expand Up @@ -1921,14 +1899,6 @@ if(BUILD_TEST)
endif()
endforeach()
endif()

# For special tests that explicitly uses dependencies, we add them here
if(BUILD_CAFFE2 AND USE_MPI)
target_link_libraries(mpi_test MPI::MPI_CXX)
if(USE_CUDA)
target_link_libraries(mpi_gpu_test MPI::MPI_CXX)
endif()
endif()
endif()

if(MSVC)
Expand Down Expand Up @@ -1998,11 +1968,6 @@ if(BUILD_PYTHON)
set_source_files_properties(${TORCH_SRC_DIR}/../caffe2/operators/box_with_nms_limit_op.cc PROPERTIES COMPILE_FLAGS -Wno-attributes)
endif()

# ---[ Python.
if(BUILD_CAFFE2)
target_compile_definitions(torch PRIVATE BUILD_CAFFE2)
endif()

# generated pb files are copied from build/caffe2 to caffe2
# if we copied them back to build this would create a build cycle
# consider removing the need for globs
Expand Down
3 changes: 1 addition & 2 deletions caffe2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@
from torch.onnx import _CAFFE2_ATEN_FALLBACK

if not _CAFFE2_ATEN_FALLBACK:
warnings.warn("Caffe2 support is not fully enabled in this PyTorch build. "
"Please enable Caffe2 by building PyTorch from source with `BUILD_CAFFE2=1` flag.")
warnings.warn("Caffe2 support is no longer present in PyTorch.")
70 changes: 3 additions & 67 deletions caffe2/core/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,68 +1,4 @@
if(NOT BUILD_CAFFE2 OR INTERN_BUILD_MOBILE)
list(APPEND Caffe2_CPU_SRCS
"${CMAKE_CURRENT_SOURCE_DIR}/common.cc"
)
set(Caffe2_CPU_SRCS ${Caffe2_CPU_SRCS} PARENT_SCOPE)
return()
endif()

# ---[ GPU files
# ------[ cuDNN
if(USE_CUDNN)
file(GLOB tmp *_cudnn.cc)
set(Caffe2_GPU_SRCS ${Caffe2_GPU_SRCS} ${tmp})
endif()
# ------[ general GPU
file(GLOB tmp *_gpu.cc)
set(Caffe2_GPU_SRCS ${Caffe2_GPU_SRCS} ${tmp})
# ------[ CUDA sources
file(GLOB tmp *.cu)
set(Caffe2_GPU_SRCS ${Caffe2_GPU_SRCS} ${tmp})
# exclude test files
file(GLOB tmp *_test.cc)
exclude(Caffe2_GPU_SRCS "${Caffe2_GPU_SRCS}" ${tmp})

# ---[ general HIP files
file(GLOB tmp hip/*.cc)
set(Caffe2_HIP_SRCS ${Caffe2_HIP_SRCS} ${tmp})
# ------[ HIP sources
file(GLOB tmp hip/*.hip)
set(Caffe2_HIP_SRCS ${Caffe2_HIP_SRCS} ${tmp})
# exclude test files
file(GLOB tmp hip/*_test.cc)
exclude(Caffe2_HIP_SRCS "${Caffe2_HIP_SRCS}" ${tmp})

# ---[ CPU files.
file(GLOB tmp *.cc)
# Manually remove the cudnn files since we might be using USE_CUDNN=OFF
# TODO: when we move to explicit file list, this would not be needed.
file(GLOB tmp_cudnn *_cudnn.cc)
exclude(tmp "${tmp}" ${tmp_cudnn})
set(Caffe2_CPU_SRCS ${Caffe2_CPU_SRCS} ${tmp})
# exclude test files and gpu files
file(GLOB tmp *_test.cc)
exclude(Caffe2_CPU_SRCS "${Caffe2_CPU_SRCS}" ${tmp})
exclude(Caffe2_CPU_SRCS "${Caffe2_CPU_SRCS}" ${Caffe2_GPU_SRCS})
exclude(Caffe2_CPU_SRCS "${Caffe2_CPU_SRCS}" ${Caffe2_HIP_SRCS})

# ---[ GPU test files
file(GLOB tmp *_gpu_test.cc)
set(Caffe2_GPU_TEST_SRCS ${Caffe2_GPU_TEST_SRCS} ${tmp})

# ---[ HIP test files
file(GLOB tmp hip/*_test.cc)
set(Caffe2_HIP_TEST_SRCS ${Caffe2_HIP_TEST_SRCS} ${tmp})

# ---[ CPU test files
file(GLOB tmp *_test.cc)
set(Caffe2_CPU_TEST_SRCS ${Caffe2_CPU_TEST_SRCS} ${tmp})
exclude(Caffe2_CPU_TEST_SRCS "${Caffe2_CPU_TEST_SRCS}" ${Caffe2_GPU_TEST_SRCS})
exclude(Caffe2_CPU_TEST_SRCS "${Caffe2_CPU_TEST_SRCS}" ${Caffe2_HIP_TEST_SRCS})

# ---[ Send the lists to the parent scope.
list(APPEND Caffe2_CPU_SRCS
"${CMAKE_CURRENT_SOURCE_DIR}/common.cc"
)
set(Caffe2_CPU_SRCS ${Caffe2_CPU_SRCS} PARENT_SCOPE)
set(Caffe2_GPU_SRCS ${Caffe2_GPU_SRCS} PARENT_SCOPE)
set(Caffe2_HIP_SRCS ${Caffe2_HIP_SRCS} PARENT_SCOPE)
set(Caffe2_CPU_TEST_SRCS ${Caffe2_CPU_TEST_SRCS} PARENT_SCOPE)
set(Caffe2_GPU_TEST_SRCS ${Caffe2_GPU_TEST_SRCS} PARENT_SCOPE)
set(Caffe2_HIP_TEST_SRCS ${Caffe2_HIP_TEST_SRCS} PARENT_SCOPE)
28 changes: 10 additions & 18 deletions caffe2/core/blob_serialization.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "caffe2/core/blob_serialization.h"

#include <limits>
#include <mutex>
#include <sstream>
#include <utility>
Expand Down Expand Up @@ -83,8 +84,7 @@ Range<T*> GetMutableTensorDataRange(
size_t start,
size_t numElements) {
CAFFE_ENFORCE(
// NOLINTNEXTLINE(clang-diagnostic-sign-compare)
start + numElements <= tensor.numel(),
static_cast<int64_t>(start + numElements) <= tensor.numel(),
"Requested invalid mutable tensor range [",
start,
", ",
Expand All @@ -100,8 +100,7 @@ c10::ArrayRef<T> GetTensorDataRange(
size_t start,
size_t numElements) {
CAFFE_ENFORCE(
// NOLINTNEXTLINE(clang-diagnostic-sign-compare)
start + numElements <= tensor.numel(),
static_cast<int64_t>(start + numElements) <= tensor.numel(),
"Requested invalid tensor range [",
start,
", ",
Expand Down Expand Up @@ -390,8 +389,7 @@ void TensorSerializer::SerializeWithOptions(
// Poorman's IOBound ThreadPool
SimpleQueue<size_t> chunkQueue;
auto task = [&]() {
// NOLINTNEXTLINE(cppcoreguidelines-init-variables)
size_t chunkStart;
size_t chunkStart = std::numeric_limits<size_t>::max();
while (chunkQueue.Pop(&chunkStart)) {
processChunk(chunkStart);
}
Expand All @@ -409,8 +407,7 @@ void TensorSerializer::SerializeWithOptions(
VLOG(1) << "Serializing blob " << name;
// Serialize whole vector. If vector is empty, it's shape still needs to be
// serialized in empty proto
for (size_t chunkBegin = 0;
// NOLINTNEXTLINE(clang-diagnostic-sign-compare)
for (int64_t chunkBegin = 0;
chunkBegin < std::max(tensor.numel(), static_cast<int64_t>(1));
chunkBegin += chunk_size) {
VLOG(2) << "Starting a chunk at " << chunkBegin;
Expand Down Expand Up @@ -582,8 +579,7 @@ void SerializeTensorData(const SerializeParams<float>& params) {
BlobSerializationOptions_FloatFormat_FLOAT_BFLOAT16) {
// NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,modernize-avoid-c-arrays)
std::unique_ptr<float[]> tmp_buffer;
// NOLINTNEXTLINE(cppcoreguidelines-init-variables)
const float* src;
const float* src = nullptr;
if (params.context.device() == CPU) {
src = params.input.data();
} else {
Expand Down Expand Up @@ -653,14 +649,12 @@ void TensorSerializer::Serialize(
size_t chunkBegin,
int32_t chunkSize) {
CAFFE_ENFORCE(
// NOLINTNEXTLINE(clang-diagnostic-sign-compare)
chunkBegin <= input.numel(),
static_cast<int64_t>(chunkBegin) <= input.numel(),
"Chunk begin is out of tensor: ",
chunkBegin,
' ',
input.numel());
// NOLINTNEXTLINE(clang-diagnostic-sign-compare)
if (chunkBegin + chunkSize > input.numel()) {
if (static_cast<int64_t>(chunkBegin + chunkSize) > input.numel()) {
chunkSize = input.numel() - chunkBegin;
}

Expand Down Expand Up @@ -1029,8 +1023,7 @@ DESERIALIZE_IMPL(float, FMT_BFLOAT16) {
params.tensor_proto.raw_data().data());

// If we are on a big-endian machine, byte-swap the serialized data.
// NOLINTNEXTLINE(cppcoreguidelines-init-variables)
const fbgemm::bfloat16* src;
const fbgemm::bfloat16* src = nullptr;
// NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,modernize-avoid-c-arrays)
std::unique_ptr<fbgemm::bfloat16[]> bswap_buffer;
if (kIsLittleEndian) {
Expand All @@ -1045,8 +1038,7 @@ DESERIALIZE_IMPL(float, FMT_BFLOAT16) {
// bfloat16 to float conversion.
// NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,modernize-avoid-c-arrays)
std::unique_ptr<float[]> tmp_buffer;
// NOLINTNEXTLINE(cppcoreguidelines-init-variables)
float* dest;
float* dest = nullptr;
if (params.context.device() == CPU) {
dest = params.dest.data();
} else {
Expand Down
6 changes: 1 addition & 5 deletions caffe2/proto/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
if(BUILD_CAFFE2)
file(GLOB Caffe2_PROTOBUF_FILES "${CMAKE_CURRENT_SOURCE_DIR}/*.proto")
else()
set(Caffe2_PROTOBUF_FILES "${CMAKE_CURRENT_SOURCE_DIR}/torch.proto;${CMAKE_CURRENT_SOURCE_DIR}/caffe2.proto")
endif()
set(Caffe2_PROTOBUF_FILES "${CMAKE_CURRENT_SOURCE_DIR}/torch.proto;${CMAKE_CURRENT_SOURCE_DIR}/caffe2.proto")

caffe2_protobuf_generate_cpp_py(Caffe2_PROTO_SRCS Caffe2_PROTO_HEADERS Caffe2_PROTO_PY ${Caffe2_PROTOBUF_FILES})

Expand Down
Loading

0 comments on commit b9e7b35

Please sign in to comment.