Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions ports/libtorch/fix-disable-xnnpack.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
--- a/cmake/Dependencies.cmake
+++ b/cmake/Dependencies.cmake
@@ -610,5 +610,5 @@ if(USE_XNNPACK AND NOT USE_SYSTEM_XNNPACK)
include_directories(SYSTEM ${XNNPACK_INCLUDE_DIR})
list(APPEND Caffe2_DEPENDENCY_LIBS XNNPACK microkernels-prod)
-elseif(NOT TARGET XNNPACK AND USE_SYSTEM_XNNPACK)
+elseif(USE_XNNPACK AND NOT TARGET XNNPACK AND USE_SYSTEM_XNNPACK)
add_library(XNNPACK SHARED IMPORTED)
add_library(microkernels-prod SHARED IMPORTED)
11 changes: 11 additions & 0 deletions ports/libtorch/fix-fbgemm-arch-check.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -913,7 +913,7 @@ include(ExternalProject)

# ---[ Dependencies ---[ FBGEMM doesn't work on x86 32bit and
# CMAKE_SYSTEM_PROCESSOR thinks its 64bit
-if(USE_FBGEMM AND NOT CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|aarch64)$")
+if(USE_FBGEMM AND NOT CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|AMD64|aarch64|ARM64)$")
message(WARNING
"x86_64 or aarch64 required for FBGEMM. "
"Not compiling with FBGEMM. "
30 changes: 30 additions & 0 deletions ports/libtorch/fix-glog.patch
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,33 @@
}
} // namespace c10

--- a/c10/util/Exception.cpp
+++ b/c10/util/Exception.cpp
@@ -9,18 +9,6 @@
#include <string>
#include <utility>

-// Google glog's api does not have an external function that allows one to check
-// if glog is initialized or not. It does have an internal function - so we are
-// declaring it here. This is a hack but has been used by a bunch of others too
-// (e.g. Torch, common/init). See also Logging.cpp in this directory.
-#ifdef C10_USE_GLOG
-namespace google {
-namespace glog_internal_namespace_ {
-bool IsGoogleLoggingInitialized();
-} // namespace glog_internal_namespace_
-} // namespace google
-#endif
-
namespace c10 {

Error::Error(std::string msg, Backtrace backtrace, const void* caller)
@@ -265,7 +253,7 @@
// During static initialization (before InitGoogleLogging), glog's global
// flags may not be constructed yet. Accessing them causes SIOF crashes
// (T253115013, D96553733). Fall back to stderr in that case.
- if (!::google::glog_internal_namespace_::IsGoogleLoggingInitialized()) {
+ if (!::google::IsGoogleLoggingInitialized()) {
std::cerr << warning.source_location().file << ':'
<< warning.source_location().line
<< ": Warning: " << warning.msg() << " (function "
19 changes: 19 additions & 0 deletions ports/libtorch/fix-headeronly-glob.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--- a/torch/headeronly/CMakeLists.txt
+++ b/torch/headeronly/CMakeLists.txt
@@ -19,13 +19,15 @@ configure_file(
${CMAKE_BINARY_DIR}/torch/headeronly/macros/cmake_macros.h)

file(GLOB HEADERONLY_HEADERS CONFIGURE_DEPENDS
- *.h
core/**/*.h
cpu/**/*.h
macros/*.h
util/*.h
)

+set_source_files_properties(version.h PROPERTIES GENERATED TRUE)
+list(APPEND HEADERONLY_HEADERS ${CMAKE_CURRENT_LIST_DIR}/version.h)
+
add_library(headeronly INTERFACE ${HEADERONLY_HEADERS})

install(FILES ${CMAKE_BINARY_DIR}/torch/headeronly/macros/cmake_macros.h
22 changes: 22 additions & 0 deletions ports/libtorch/fix-python-package-data.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1466,13 +1466,17 @@
# inductor templates, and symlink-replacement copies. Previously handled
# by setup.py; now consolidated here for both scikit-build-core and
# setuptools builds.
-include(cmake/FileMirroring.cmake)
+if(BUILD_PYTHON)
+ include(cmake/FileMirroring.cmake)
+endif()

# Package data: install non-Python data files (type stubs, templates,
# headers, etc.) into the torch package. Previously declared via
# setup.py package_data; now consolidated here for both scikit-build-core
# and setuptools builds.
-include(cmake/PackageData.cmake)
+if(BUILD_PYTHON)
+ include(cmake/PackageData.cmake)
+endif()

include(cmake/PostBuildSteps.cmake)

10 changes: 10 additions & 0 deletions ports/libtorch/fix-system-concurrentqueue.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--- a/cmake/Dependencies.cmake
+++ b/cmake/Dependencies.cmake
@@ -1774,3 +1774,5 @@
# Include moodycamel
-add_library(moodycamel INTERFACE IMPORTED)
-include_directories(moodycamel SYSTEM INTERFACE ${PROJECT_SOURCE_DIR}/third_party/concurrentqueue)
+find_package(concurrentqueue CONFIG REQUIRED)
+add_library(moodycamel ALIAS concurrentqueue::concurrentqueue)
+get_target_property(moodycamel_INCLUDE_DIRS concurrentqueue::concurrentqueue INTERFACE_INCLUDE_DIRECTORIES)
+include_directories(SYSTEM ${moodycamel_INCLUDE_DIRS})
19 changes: 7 additions & 12 deletions ports/libtorch/fix-system-fmt.patch
Original file line number Diff line number Diff line change
@@ -1,28 +1,23 @@
diff --git a/cmake/Dependencies.cmake b/cmake/Dependencies.cmake
index 2baa187..65f9e01 100644
--- a/cmake/Dependencies.cmake
+++ b/cmake/Dependencies.cmake
@@ -1597,22 +1597,24 @@
# Install `fmtlib` header.
@@ -1633,6 +1633,7 @@ endif()
# This was the default behavior before version 12.0.0.
# Since PyTorch C API depends on it, make it available for projects that
# depend on PyTorch.
+if(FALSE)
set(FMT_INSTALL ON)
set(TEMP_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS})
set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared libs" FORCE)
add_subdirectory(${PROJECT_SOURCE_DIR}/third_party/fmt)

# Disable compiler feature checks for `fmt`.
#
# CMake compiles a little program to check compiler features. Some of our build
# configurations (notably the mobile build analyzer) will populate
# CMAKE_CXX_FLAGS in ways that break feature checks. Since we already know
# `fmt` is compatible with a superset of the compilers that PyTorch is, it
# shouldn't be too bad to just disable the checks.
set_target_properties(fmt-header-only PROPERTIES INTERFACE_COMPILE_FEATURES "")
@@ -1658,8 +1659,9 @@ target_compile_definitions(fmt PUBLIC "FMT_NO_UNIQUE_ADDRESS=${_fmt_no_unique_ad
target_compile_definitions(fmt-header-only INTERFACE "FMT_NO_UNIQUE_ADDRESS=${_fmt_no_unique_address}")
unset(_fmt_no_unique_address)

+endif()
+find_package(fmt REQUIRED)
list(APPEND Caffe2_DEPENDENCY_LIBS fmt::fmt-header-only)
-set(BUILD_SHARED_LIBS ${TEMP_BUILD_SHARED_LIBS} CACHE BOOL "Build shared libs" FORCE)

# ---[ Kineto
# edge profiler depends on KinetoProfiler but it only does cpu
12 changes: 0 additions & 12 deletions ports/libtorch/fix-system-xnnpack.patch

This file was deleted.

97 changes: 56 additions & 41 deletions ports/libtorch/fix-windows-install-dirs.patch
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
diff --git a/c10/CMakeLists.txt b/c10/CMakeLists.txt
index bd138d2..8e63fe8 100644
--- a/c10/CMakeLists.txt
+++ b/c10/CMakeLists.txt
@@ -161,7 +161,10 @@
@@ -162,7 +162,10 @@ if(NOT BUILD_LIBTORCHLESS)
# Note: for now, we will put all export path into one single Caffe2Targets group
# to deal with the cmake deployment need. Inside the Caffe2Targets set, the
# individual libraries like libc10.so and libcaffe2.so are still self-contained.
Expand All @@ -12,9 +14,11 @@
endif()

install(DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
diff --git a/c10/cuda/CMakeLists.txt b/c10/cuda/CMakeLists.txt
index a337614..425287e 100644
--- a/c10/cuda/CMakeLists.txt
+++ b/c10/cuda/CMakeLists.txt
@@ -86,7 +86,10 @@
@@ -86,7 +86,10 @@ if(NOT BUILD_LIBTORCHLESS)
# Note: for now, we will put all export path into one single Caffe2Targets group
# to deal with the cmake deployment need. Inside the Caffe2Targets set, the
# individual libraries like libc10.so and libcaffe2.so are still self-contained.
Expand All @@ -26,9 +30,11 @@

endif()

diff --git a/c10/hip/CMakeLists.txt b/c10/hip/CMakeLists.txt
index 0f86f03..64e0bb3 100644
--- a/c10/hip/CMakeLists.txt
+++ b/c10/hip/CMakeLists.txt
@@ -56,7 +56,10 @@
@@ -52,7 +52,10 @@ if(NOT BUILD_LIBTORCHLESS)
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../..>
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}>
$<INSTALL_INTERFACE:include>)
Expand All @@ -40,9 +46,11 @@
set(C10_HIP_LIB c10_hip)
endif()

diff --git a/c10/xpu/CMakeLists.txt b/c10/xpu/CMakeLists.txt
index 349b209..b1ba10e 100644
--- a/c10/xpu/CMakeLists.txt
+++ b/c10/xpu/CMakeLists.txt
@@ -49,7 +49,10 @@
@@ -49,7 +49,10 @@ if(NOT BUILD_LIBTORCHLESS)
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}>
$<INSTALL_INTERFACE:include>
)
Expand All @@ -54,9 +62,11 @@
set(C10_XPU_LIB c10_xpu)
add_subdirectory(test)
endif()
diff --git a/caffe2/CMakeLists.txt b/caffe2/CMakeLists.txt
index e4a0454..2901fc4 100644
--- a/caffe2/CMakeLists.txt
+++ b/caffe2/CMakeLists.txt
@@ -573,7 +573,10 @@
@@ -561,7 +561,10 @@ if(USE_CUDA)
endif()

target_link_libraries(caffe2_nvrtc PRIVATE caffe2::nvrtc ${DELAY_LOAD_FLAGS})
Expand All @@ -68,7 +78,7 @@
if(USE_NCCL)
list(APPEND Caffe2_GPU_SRCS
${TORCH_SRC_DIR}/csrc/cuda/nccl.cpp)
@@ -656,7 +659,10 @@
@@ -645,7 +648,10 @@ if(USE_ROCM)
target_link_libraries(caffe2_nvrtc hip::amdhip64 hiprtc::hiprtc)
target_include_directories(caffe2_nvrtc PRIVATE ${CMAKE_BINARY_DIR})
target_compile_definitions(caffe2_nvrtc PRIVATE USE_ROCM __HIP_PLATFORM_AMD__)
Expand All @@ -80,7 +90,7 @@
endif()

if(NOT NO_API AND NOT BUILD_LITE_INTERPRETER)
@@ -1067,7 +1073,10 @@
@@ -1065,7 +1071,10 @@ elseif(USE_CUDA)
target_compile_definitions(torch_cuda PUBLIC USE_NVSHMEM)
target_compile_definitions(torch_nvshmem PUBLIC USE_NVSHMEM)
target_link_libraries(torch_cuda PRIVATE torch_nvshmem)
Expand All @@ -92,7 +102,7 @@
else()
message(STATUS "NVSHMEM not found, not building with NVSHMEM support.")
endif()
@@ -1130,7 +1139,10 @@
@@ -1128,7 +1137,10 @@ elseif(USE_CUDA)
CUDA::culibos ${CMAKE_DL_LIBS})
endif()
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/../aten/src/ATen/native/cuda/LinearAlgebraStubs.cpp PROPERTIES COMPILE_FLAGS "-DBUILD_LAZY_CUDA_LINALG")
Expand All @@ -104,20 +114,20 @@
endif()

if(USE_PRECOMPILED_HEADERS)
@@ -1528,8 +1540,10 @@
target_link_libraries(torch_rocshmem PRIVATE roc::rocshmem)
target_link_libraries(torch_hip PRIVATE torch_rocshmem)
@@ -1520,8 +1532,10 @@ if(USE_ROCM)
target_link_libraries(torch_rocshmem PRIVATE roc::rocshmem)
target_link_libraries(torch_hip PRIVATE torch_rocshmem)

- install(TARGETS torch_rocshmem EXPORT Caffe2Targets DESTINATION
- "${TORCH_INSTALL_LIB_DIR}")
+ install(TARGETS torch_rocshmem EXPORT Caffe2Targets
+ RUNTIME DESTINATION "${TORCH_INSTALL_BIN_DIR}"
+ LIBRARY DESTINATION "${TORCH_INSTALL_LIB_DIR}"
+ ARCHIVE DESTINATION "${TORCH_INSTALL_LIB_DIR}")
elseif(rocshmem_FOUND)
message(STATUS
"rocSHMEM found but skipped: PYTORCH_ROCM_ARCH has no entry in "
@@ -1676,17 +1690,32 @@
- install(TARGETS torch_rocshmem EXPORT Caffe2Targets DESTINATION
- "${TORCH_INSTALL_LIB_DIR}")
+ install(TARGETS torch_rocshmem EXPORT Caffe2Targets
+ RUNTIME DESTINATION "${TORCH_INSTALL_BIN_DIR}"
+ LIBRARY DESTINATION "${TORCH_INSTALL_LIB_DIR}"
+ ARCHIVE DESTINATION "${TORCH_INSTALL_LIB_DIR}")
else()
message(STATUS
"rocSHMEM found but skipped: PYTORCH_ROCM_ARCH has no entry in "
@@ -1673,17 +1687,32 @@ endif()

caffe2_interface_library(torch torch_library)

Expand Down Expand Up @@ -155,7 +165,7 @@

target_link_libraries(torch PUBLIC torch_cpu_library)

@@ -1829,7 +1858,10 @@
@@ -1826,7 +1855,10 @@ if(BUILD_SHARED_LIBS)
target_link_libraries(torch_global_deps torch::nvtoolsext)
endif()
endif()
Expand All @@ -167,23 +177,11 @@
endif()

# ---[ Caffe2 HIP sources.
--- a/torch/CMakeLists.txt
+++ b/torch/CMakeLists.txt
@@ -459,7 +459,10 @@
set_target_properties(torch_python PROPERTIES LINK_FLAGS ${TORCH_PYTHON_LINK_FLAGS})
endif()

-install(TARGETS torch_python DESTINATION "${TORCH_INSTALL_LIB_DIR}")
+install(TARGETS torch_python
+ RUNTIME DESTINATION "${TORCH_INSTALL_BIN_DIR}"
+ LIBRARY DESTINATION "${TORCH_INSTALL_LIB_DIR}"
+ ARCHIVE DESTINATION "${TORCH_INSTALL_LIB_DIR}")

# Generate torch/version.py from the appropriate CMake cache variables.
if(${CMAKE_BUILD_TYPE} STREQUAL "Debug")
diff --git a/test/cpp/c10d/CMakeLists.txt b/test/cpp/c10d/CMakeLists.txt
index aa98db5..616bba8 100644
--- a/test/cpp/c10d/CMakeLists.txt
+++ b/test/cpp/c10d/CMakeLists.txt
@@ -79,7 +79,10 @@
@@ -80,7 +80,10 @@ if(USE_CUDA)
LINK_LIBRARIES torch_cpu c10d_cuda_test gtest_main __caffe2_nccl INSTALL_TEST ${INSTALL_TEST})
target_compile_definitions(NCCLDevCommManagerTest PRIVATE USE_CUDA USE_NCCL)
if(INSTALL_TEST)
Expand All @@ -195,7 +193,7 @@
endif()
endif()
if(USE_UCC AND USE_C10D_UCC)
@@ -91,7 +94,10 @@
@@ -92,7 +95,10 @@ if(USE_CUDA)
ProcessGroupUCCTest.cpp
LINK_LIBRARIES torch_cpu c10d_cuda_test gtest_main __caffe2_ucc INSTALL_TEST ${INSTALL_TEST})
if(INSTALL_TEST)
Expand All @@ -207,7 +205,7 @@
endif()
endif()
elseif(USE_ROCM)
@@ -107,7 +113,10 @@
@@ -108,7 +114,10 @@ elseif(USE_ROCM)
hip/ProcessGroupNCCLErrorsTest.cpp
LINK_LIBRARIES torch_cpu c10d_hip_test gtest_main __caffe2_nccl INSTALL_TEST ${INSTALL_TEST})
if(INSTALL_TEST)
Expand All @@ -219,7 +217,7 @@
endif()
endif()
if(USE_UCC AND USE_C10D_UCC)
@@ -115,7 +124,10 @@
@@ -116,7 +125,10 @@ elseif(USE_ROCM)
hip/ProcessGroupUCCTest.cpp
LINK_LIBRARIES torch_cpu c10d_hip_test gtest_main __caffe2_ucc INSTALL_TEST ${INSTALL_TEST})
if(INSTALL_TEST)
Expand All @@ -231,9 +229,11 @@
endif()
endif()
else()
diff --git a/test/cpp/jit/CMakeLists.txt b/test/cpp/jit/CMakeLists.txt
index 552f8cf..2299940 100644
--- a/test/cpp/jit/CMakeLists.txt
+++ b/test/cpp/jit/CMakeLists.txt
@@ -32,9 +32,18 @@
@@ -32,9 +32,18 @@ endif()
target_link_libraries(backend_with_compiler torch)

if(INSTALL_TEST)
Expand All @@ -255,4 +255,19 @@
endif()

# Build the cpp gtest binary containing the cpp-only tests.
diff --git a/torch/CMakeLists.txt b/torch/CMakeLists.txt
index 23aa88d..2381304 100644
--- a/torch/CMakeLists.txt
+++ b/torch/CMakeLists.txt
@@ -439,7 +439,10 @@ if(NOT TORCH_PYTHON_LINK_FLAGS STREQUAL "")
set_target_properties(torch_python PROPERTIES LINK_FLAGS "${TORCH_PYTHON_LINK_FLAGS}")
endif()

-install(TARGETS torch_python DESTINATION "${TORCH_INSTALL_LIB_DIR}")
+install(TARGETS torch_python
+ RUNTIME DESTINATION "${TORCH_INSTALL_BIN_DIR}"
+ LIBRARY DESTINATION "${TORCH_INSTALL_LIB_DIR}"
+ ARCHIVE DESTINATION "${TORCH_INSTALL_LIB_DIR}")

# Build the torch._C Python extension module from the thin stub that
# forwards to torch_python. This was historically built by setuptools;
Loading
Loading