-
Notifications
You must be signed in to change notification settings - Fork 6.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[libtorch] create a new port #17199
[libtorch] create a new port #17199
Changes from 65 commits
8ee205b
d42ca2f
5114b48
28cec17
f8ec3f5
18d4965
2a77308
1c19e75
287b524
335282e
44ae8f7
62cd69e
b1807fb
5d00ceb
ecbc08f
34ec43f
8fd7788
d3b2cd9
835dc6b
94560c3
06f0a02
45944fc
2c18c57
31595af
929dfc4
080d3e5
1fb5799
d44c15e
d7b3957
0ab2fe8
b9c4a07
16b5612
86290b8
ac8687c
a447925
7954279
65c5545
9703ca3
a04ecfd
7156a29
a9a2b2c
4424ca4
f9a4d3d
478af24
f11119d
b1763bf
bc7c98d
4afebf9
619e481
c9d9bcf
93b2d4f
dd41633
e198064
9686405
64d400f
c66f133
c6ed667
0c9cc66
aa94e7e
d8a19cf
df88c0d
dd7c22d
1339a1b
64495c3
3317aed
707d441
4947704
04aeefc
4c50475
b0e0d81
260d530
08637fc
b97c1c5
26dda6a
4085d19
5fd4ef0
a9dbd78
94bd147
0e63c13
b8c212e
981d24d
3f43bba
17cd326
88bb895
9598f03
46e381d
62c5081
6566732
027b927
a3e9e13
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
diff --git a/CMakeLists.txt b/CMakeLists.txt | ||
index 0c11507..b47ebae 100644 | ||
--- a/CMakeLists.txt | ||
+++ b/CMakeLists.txt | ||
@@ -619,7 +619,7 @@ if(NOT CMAKE_BUILD_TYPE) | ||
endif() | ||
|
||
# The below means we are cross compiling for arm64 or x86_64 on MacOSX | ||
-if(NOT IOS AND CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND CMAKE_OSX_ARCHITECTURES MATCHES "^(x86_64|arm64)$") | ||
+if(false) | ||
set(CROSS_COMPILING_MACOSX TRUE) | ||
# We need to compile a universal protoc to not fail protobuf build | ||
# We set CMAKE_TRY_COMPILE_TARGET_TYPE to STATIC_LIBRARY (vs executable) to succeed the cmake compiler check for cross-compiling | ||
@@ -637,6 +637,13 @@ if(NOT IOS AND CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND CMAKE_OSX_ARCHITECTURES M | ||
set(PROTOBUF_PROTOC_EXECUTABLE "${PROJECT_SOURCE_DIR}/build_host_protoc/bin/protoc") | ||
set(CAFFE2_CUSTOM_PROTOC_EXECUTABLE "${PROJECT_SOURCE_DIR}/build_host_protoc/bin/protoc") | ||
endif() | ||
+find_package(protobuf CONFIG REQUIRED) | ||
+find_program(PROTOBUF_PROTOC_EXECUTABLE | ||
+ NAMES protoc | ||
+ PATHS ${_VCPKG_INSTALLED_DIR}/${VCPKG_HOST_TRIPLET}/tools | ||
+) | ||
+set(CAFFE2_CUSTOM_PROTOC_EXECUTABLE ${PROTOBUF_PROTOC_EXECUTABLE}) | ||
+include(cmake/ProtoBuf.cmake) | ||
|
||
# ---[ Misc checks to cope with various compiler modes | ||
include(cmake/MiscCheck.cmake) | ||
@@ -650,7 +657,7 @@ if(USE_FBGEMM AND ((CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" AND CMAKE_SIZEOF_VO | ||
set(USE_FBGEMM OFF) | ||
endif() | ||
|
||
-include(cmake/Dependencies.cmake) | ||
+include(cmake/vcpkg-dependencies.cmake) # we will import vcpkg ports instead of CAFFE2_THIRD_PARTY_ROOT | ||
|
||
if(USE_FBGEMM) | ||
string(APPEND CMAKE_CXX_FLAGS " -DUSE_FBGEMM") | ||
diff --git a/aten/src/ATen/native/quantized/cpu/qnnpack/CMakeLists.txt b/aten/src/ATen/native/quantized/cpu/qnnpack/CMakeLists.txt | ||
index 3901f73..4954c3e 100644 | ||
--- a/aten/src/ATen/native/quantized/cpu/qnnpack/CMakeLists.txt | ||
+++ b/aten/src/ATen/native/quantized/cpu/qnnpack/CMakeLists.txt | ||
@@ -380,6 +380,7 @@ else() | ||
target_link_libraries(pytorch_qnnpack PUBLIC pthreadpool) | ||
endif() | ||
|
||
+if(false) # use packages of vcpkg. see L433 | ||
# ---[ Configure FXdiv | ||
if(NOT TARGET fxdiv AND NOT USE_SYSTEM_FXDIV) | ||
set(FXDIV_BUILD_TESTS OFF CACHE BOOL "") | ||
@@ -428,6 +429,14 @@ elseif(NOT TARGET fp16 AND USE_SYSTEM_FP16) | ||
set_target_properties(fp16 PROPERTIES LINKER_LANGUAGE C) | ||
endif() | ||
target_link_libraries(pytorch_qnnpack PRIVATE fp16) | ||
+endif() | ||
+target_link_libraries(pytorch_qnnpack PRIVATE | ||
+ cpuinfo::clog cpuinfo::cpuinfo | ||
+ unofficial::pthreadpool | ||
+) | ||
+target_include_directories(pytorch_qnnpack PRIVATE | ||
+ ${FP16_INCLUDE_DIRS} ${PSIMD_INCLUDE_DIRS} ${FXDIV_INCLUDE_DIRS} | ||
+) | ||
|
||
install(TARGETS pytorch_qnnpack | ||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||
diff --git a/caffe2/CMakeLists.txt b/caffe2/CMakeLists.txt | ||
index 26210cb..5f4618e 100644 | ||
--- a/caffe2/CMakeLists.txt | ||
+++ b/caffe2/CMakeLists.txt | ||
@@ -106,7 +106,7 @@ endif() | ||
# Note: the folders that are being commented out have not been properly | ||
# addressed yet. | ||
|
||
-if(NOT MSVC AND USE_XNNPACK) | ||
+if(false) | ||
if(NOT TARGET fxdiv) | ||
set(FXDIV_BUILD_TESTS OFF CACHE BOOL "") | ||
set(FXDIV_BUILD_BENCHMARKS OFF CACHE BOOL "") | ||
@@ -798,6 +798,9 @@ if(HAVE_SOVERSION) | ||
endif() | ||
torch_compile_options(torch_cpu) # see cmake/public/utils.cmake | ||
|
||
+find_package(Eigen3 CONFIG REQUIRED) | ||
+target_link_libraries(torch_cpu PRIVATE Eigen3::Eigen) # for caffe2 operators | ||
+ | ||
if(USE_PRECOMPILED_HEADERS) | ||
target_precompile_headers(torch_cpu PRIVATE | ||
"$<$<COMPILE_LANGUAGE:CXX>:ATen/ATen.h>") | ||
@@ -990,7 +993,7 @@ if(USE_CUDA OR USE_ROCM) | ||
target_include_directories(${TORCHLIB_FLAVOR} PRIVATE "${CMAKE_BINARY_DIR}/include") | ||
endif() | ||
|
||
-if(NOT MSVC AND USE_XNNPACK) | ||
+if(false) | ||
TARGET_LINK_LIBRARIES(torch_cpu PRIVATE fxdiv) | ||
endif() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
diff --git a/aten/src/ATen/native/quantized/cpu/qembeddingbag_prepack.cpp b/aten/src/ATen/native/quantized/cpu/qembeddingbag_prepack.cpp | ||
index 614e274..b59a4d4 100644 | ||
--- a/aten/src/ATen/native/quantized/cpu/qembeddingbag_prepack.cpp | ||
+++ b/aten/src/ATen/native/quantized/cpu/qembeddingbag_prepack.cpp | ||
@@ -8,7 +8,9 @@ | ||
#include <torch/library.h> | ||
|
||
#include <c10/util/irange.h> | ||
- | ||
+#if defined(USE_FBGEMM) | ||
+#include <fbgemm/QuantUtils.h> | ||
+#endif | ||
torch::class_<EmbeddingPackedParamsBase> register_embedding_params(); | ||
|
||
/* |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
vcpkg_check_linkage(ONLY_DYNAMIC_LIBRARY) | ||
|
||
vcpkg_from_github( | ||
OUT_SOURCE_PATH SOURCE_PATH | ||
REPO pytorch/pytorch | ||
REF v1.10.0 | ||
SHA512 92b70e6170a7f173c4a9cb29f6cec6dfa598587aa9cf6a620ec861b95da6ea555cbc7285914c0dab6cfc8af320fad4999be4a788acc1f15140664a67ad9dc35d | ||
HEAD_REF master | ||
PATCHES | ||
fix-cmake.patch | ||
fix-sources.patch | ||
use-glog-header.patch | ||
) | ||
file(REMOVE_RECURSE "${SOURCE_PATH}/caffe2/core/macros.h") # We must use generated header files | ||
|
||
vcpkg_find_acquire_program(PYTHON3) | ||
|
||
x_vcpkg_get_python_packages( | ||
PYTHON_VERSION 3 | ||
PYTHON_EXECUTABLE "${PYTHON3}" | ||
PACKAGES typing-extensions pyyaml | ||
OUT_PYTHON_VAR PYTHON3 | ||
) | ||
# Make the configure step use same Python executable | ||
get_filename_component(PYTHON_DIR "${PYTHON3}" PATH) | ||
vcpkg_add_to_path(PREPEND "${PYTHON_DIR}") | ||
|
||
# Editing ${SOURCE_PATH}/cmake/Dependencies.cmake makes HORRIBLE readability... | ||
file(COPY "${CMAKE_CURRENT_LIST_DIR}/vcpkg-dependencies.cmake" DESTINATION "${SOURCE_PATH}/cmake") | ||
|
||
vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS | ||
FEATURES | ||
dist USE_DISTRIBUTED # MPI, Gloo, TensorPipe | ||
zstd USE_ZSTD | ||
fftw3 USE_FFTW | ||
fftw3 AT_FFTW_ENABLED | ||
fbgemm USE_FBGEMM | ||
opencv USE_OPENCV | ||
tbb USE_TBB | ||
leveldb USE_LEVELDB | ||
opencl USE_OPENCL | ||
cuda USE_CUDA | ||
cuda USE_CUDNN | ||
cuda USE_NCCL | ||
cuda USE_SYSTEM_NCCL | ||
cuda USE_NVRTC | ||
cuda AT_CUDA_ENABLED | ||
cuda AT_CUDNN_ENABLED | ||
vulkan USE_VULKAN | ||
vulkan USE_VULKAN_WRAPPER | ||
vulkan USE_VULKAN_SHADERC_RUNTIME | ||
vulkan USE_VULKAN_RELAXED_PRECISION | ||
nnpack USE_NNPACK # todo: check use of `DISABLE_NNPACK_AND_FAMILY` | ||
nnpack AT_NNPACK_ENABLED | ||
xnnpack USE_XNNPACK | ||
xnnpack USE_SYSTEM_XNNPACK | ||
qnnpack USE_QNNPACK # todo: check use of `USE_PYTORCH_QNNPACK` | ||
) | ||
|
||
if(CMAKE_CXX_COMPILER_ID MATCHES GNU) | ||
list(APPEND FEATURE_OPTIONS -DUSE_NATIVE_ARCH=ON) | ||
endif() | ||
if("dist" IN_LIST FEATURES) | ||
if(VCPKG_TARGET_IS_LINUX OR VCPKG_TARGET_IS_OSX) | ||
list(APPEND FEATURE_OPTIONS -DUSE_TENSORPIPE=ON) | ||
endif() | ||
if(VCPKG_TARGET_IS_WINDOWS OR VCPKG_TARGET_IS_OSX) | ||
list(APPEND FEATURE_OPTIONS -DUSE_LIBUV=ON) | ||
endif() | ||
endif() | ||
|
||
if(VCPKG_TARGET_IS_LINUX) | ||
# Linux package `libnuma-dev` | ||
find_library(Numa_LIBPATH NAMES numa PATHS "/usr/lib" "/usr/lib/x86_64-linux-gnu") | ||
if(Numa_LIBPATH) | ||
message(STATUS "Detected numa: ${Numa_LIBPATH}") | ||
list(APPEND FEATURE_OPTIONS -DUSE_NUMA=ON) | ||
else() | ||
message(STATUS "To enable USE_NUMA build option, install 'libnuma-dev' package") | ||
list(APPEND FEATURE_OPTIONS -DUSE_NUMA=OFF) | ||
luncliff marked this conversation as resolved.
Show resolved
Hide resolved
|
||
endif() | ||
else() | ||
list(APPEND FEATURE_OPTIONS -DUSE_NUMA=OFF) | ||
endif() | ||
|
||
if(VCPKG_TARGET_IS_OSX) | ||
list(APPEND FEATURE_OPTIONS -DBLAS=Accelerate) # Accelerate.framework will be used for Apple platforms | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I need to ask folks about BLAS. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BLAS(Basic Linear Algebra Subprograms). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The problem in my experience is that everyone has different ideas for what the defaults should be, and we get PRs changing the default to what people want, and we don't understand ourselves why one would pick one or another and don't have a clear documented policy on which one we use.
I left this comment as a note to myself to follow up with the team and figure out where we left the BLAS situation There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Blas vendor should be forced via the blas meta port (see #24327) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ras0219-msft @dan-shaw @JavierMatosD @markle11m @AugP @valeriaconde and I discussed this today and have the following notes on BLAS: If possible, this should gain a dependency on the port We observe that there is special handling for some implementations like Eigen which may make that impossible, since Eigen isn't actually a BLAS implementation; we should explicitly document the relationship here and how/why the "normal way" to get BLAS isn't used. We also observe that
which suggests maybe BLAS isn't used at all? |
||
else() | ||
list(APPEND FEATURE_OPTIONS -DBLAS=Eigen) | ||
endif() | ||
|
||
if("tbb" IN_LIST FEATURES) | ||
list(APPEND FEATURE_OPTIONS | ||
-DMKLDNN_CPU_RUNTIME=TBB | ||
) | ||
endif() | ||
|
||
if(VCPKG_TARGET_IS_ANDROID) | ||
list(APPEND FEATURE_OPTIONS | ||
-DINTERN_BUILD_MOBILE=ON | ||
-DBUILD_JNI=ON | ||
-DUSE_NNAPI=ON | ||
) | ||
else() | ||
list(APPEND FEATURE_OPTIONS -DINTERN_BUILD_MOBILE=OFF) | ||
endif() | ||
|
||
string(COMPARE EQUAL "${VCPKG_CRT_LINKAGE}" "static" USE_STATIC_RUNTIME) | ||
|
||
vcpkg_cmake_configure( | ||
SOURCE_PATH "${SOURCE_PATH}" | ||
OPTIONS | ||
${FEATURE_OPTIONS} | ||
-DPython3_EXECUTABLE="${PYTHON3}" | ||
-DCAFFE2_USE_MSVC_STATIC_RUNTIME=${USE_STATIC_RUNTIME} | ||
-DBUILD_CUSTOM_PROTOBUF=OFF -DUSE_LITE_PROTO=OFF | ||
-DBUILD_TEST=OFF -DATEN_NO_TEST=ON | ||
-DUSE_SYSTEM_LIBS=ON | ||
-DBUILD_PYTHON=OFF | ||
-DUSE_GLOO=${VCPKG_TARGET_IS_LINUX} | ||
-DUSE_MPI=${VCPKG_TARGET_IS_LINUX} # Linux package `libopenmpi-dev` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to have this installed in our VMs? Need to confirm what happens if this package is missing. (If missing it needs to fail to build not silently do nothing to preserve build-path-independence) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The internal log is too complicated. I think we can There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let me check it's There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
-DUSE_METAL=OFF | ||
-DUSE_PYTORCH_METAL=OFF | ||
-DUSE_PYTORCH_METAL_EXPORT=OFF | ||
-DUSE_BLAS=ON # Eigen, MKL, or Accelerate | ||
-DUSE_GFLAGS=ON | ||
-DUSE_GLOG=ON | ||
-DUSE_LMDB=ON | ||
-DUSE_ROCKSDB=OFF | ||
-DUSE_OPENMP=OFF | ||
-DUSE_OBSERVERS=OFF | ||
-DUSE_PYTORCH_QNNPACK=OFF | ||
-DUSE_KINETO=OFF | ||
-DUSE_ROCM=OFF | ||
-DUSE_DEPLOY=OFF | ||
-DUSE_BREAKPAD=OFF | ||
-DUSE_FFTW=OFF | ||
-DCAFFE2_USE_EIGEN_FOR_BLAS=ON | ||
# BLAS=MKL not supported | ||
-DUSE_MKLDNN=OFF | ||
-DUSE_MKLDNN_CBLAS=OFF | ||
-DCAFFE2_USE_MKL=OFF | ||
-DCAFFE2_USE_MKLDNN=OFF | ||
-DAT_MKL_ENABLED=OFF | ||
-DAT_MKLDNN_ENABLED=OFF | ||
OPTIONS_RELEASE | ||
-DBUILD_LIBTORCH_CPU_WITH_DEBUG=ON | ||
MAYBE_UNUSED_VARIABLES | ||
USE_NUMA | ||
USE_SYSTEM_BIND11 | ||
USE_VULKAN_WRAPPER | ||
MKLDNN_CPU_RUNTIME | ||
) | ||
vcpkg_cmake_build(TARGET __aten_op_header_gen) # explicit codegen is required | ||
vcpkg_cmake_install() | ||
vcpkg_copy_pdbs() | ||
|
||
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include" | ||
"${CURRENT_PACKAGES_DIR}/debug/share" | ||
"${CURRENT_PACKAGES_DIR}/share" | ||
"${CURRENT_PACKAGES_DIR}/include/c10/test/core/impl" | ||
"${CURRENT_PACKAGES_DIR}/include/c10/hip" | ||
"${CURRENT_PACKAGES_DIR}/include/c10/benchmark" | ||
"${CURRENT_PACKAGES_DIR}/include/c10/test" | ||
"${CURRENT_PACKAGES_DIR}/include/c10/cuda" | ||
"${CURRENT_PACKAGES_DIR}/include/c10d/quantization" | ||
"${CURRENT_PACKAGES_DIR}/include/caffe2/ideep/operators/quantization" | ||
"${CURRENT_PACKAGES_DIR}/include/caffe2/python" | ||
"${CURRENT_PACKAGES_DIR}/include/caffe2/share/contrib/depthwise" | ||
"${CURRENT_PACKAGES_DIR}/include/caffe2/share/contrib/nnpack" | ||
"${CURRENT_PACKAGES_DIR}/include/caffe2/mobile" | ||
"${CURRENT_PACKAGES_DIR}/include/caffe2/experiments/python" | ||
"${CURRENT_PACKAGES_DIR}/include/caffe2/test" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this mean it got vendored and we need to fix it to use the port? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, it isn't quite "vendored", it is that the projects are one in the same. According to upstream:
This either needs to (1) use the caffe2 from that port, or (2) caffe2 needs to be marked "deprecated" in favor of this one? |
||
"${CURRENT_PACKAGES_DIR}/include/caffe2/utils/hip" | ||
"${CURRENT_PACKAGES_DIR}/include/caffe2/opt/nql/tests" | ||
"${CURRENT_PACKAGES_DIR}/include/caffe2/contrib" | ||
"${CURRENT_PACKAGES_DIR}/include/caffe2/core/nomnigraph/Representations" | ||
"${CURRENT_PACKAGES_DIR}/include/torch/csrc" | ||
JackBoosY marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
file(INSTALL "${SOURCE_PATH}/LICENSE" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME "copyright") |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
diff --git a/c10/util/Logging.cpp b/c10/util/Logging.cpp | ||
index bf7bd98..2cedc9a 100644 | ||
--- a/c10/util/Logging.cpp | ||
+++ b/c10/util/Logging.cpp | ||
@@ -4,6 +4,7 @@ | ||
#ifdef FBCODE_CAFFE2 | ||
#include <folly/synchronization/SanitizeThread.h> | ||
#endif | ||
+#include <glog/logging.h> | ||
|
||
#include <algorithm> | ||
#include <cstdlib> | ||
@@ -187,23 +188,13 @@ C10_DEFINE_int( | ||
google::GLOG_WARNING, | ||
"The minimum log level that caffe2 will output."); | ||
|
||
-// 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). | ||
-namespace google { | ||
-namespace glog_internal_namespace_ { | ||
-bool IsGoogleLoggingInitialized(); | ||
-} // namespace glog_internal_namespace_ | ||
-} // namespace google | ||
- | ||
namespace c10 { | ||
bool InitCaffeLogging(int* argc, char** argv) { | ||
if (*argc == 0) | ||
return true; | ||
#if !defined(_MSC_VER) | ||
// This trick can only be used on UNIX platforms | ||
- if (!::google::glog_internal_namespace_::IsGoogleLoggingInitialized()) | ||
+ if (!::google::IsGoogleLoggingInitialized()) | ||
#endif | ||
{ | ||
::google::InitGoogleLogging(argv[0]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Neumann-A suggests in Discord to hook this up to the port
numactl
.