From 8bfe3fd4756d04afeddb0fe54dd66c2189298b78 Mon Sep 17 00:00:00 2001 From: luncliff Date: Thu, 24 Oct 2024 17:59:38 +0900 Subject: [PATCH] [libkineto] trying KINETO=off --- ports/libtorch/fix-cmake.patch | 39 ++++++++++++++++++++++++++++++++ ports/libtorch/fix-sources.patch | 29 ++++++++++++++++++++++++ ports/libtorch/portfile.cmake | 9 +++++++- 3 files changed, 76 insertions(+), 1 deletion(-) diff --git a/ports/libtorch/fix-cmake.patch b/ports/libtorch/fix-cmake.patch index 08819512..78dc82b1 100644 --- a/ports/libtorch/fix-cmake.patch +++ b/ports/libtorch/fix-cmake.patch @@ -339,3 +339,42 @@ index 257c0bd..4788bcf 100644 if(NOT MSVC) set(CMAKE_C_FLAGS_DEBUG ${OLD_CMAKE_C_FLAGS_DEBUG}) +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 8d3253c..7502685 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -781,7 +781,7 @@ if(NOT CMAKE_BUILD_TYPE) + endif() + + # The below means we are cross compiling for arm64 or x86_64 on MacOSX +-if(NOT IOS ++if(BUILD_CUSTOM_PROTOBUF AND NOT IOS + AND CMAKE_SYSTEM_NAME STREQUAL "Darwin" + AND CMAKE_OSX_ARCHITECTURES MATCHES "^(x86_64|arm64)$") + set(CROSS_COMPILING_MACOSX TRUE) +diff --git a/caffe2/CMakeLists.txt b/caffe2/CMakeLists.txt +index b5aaeba..d55ffe7 100644 +--- a/caffe2/CMakeLists.txt ++++ b/caffe2/CMakeLists.txt +@@ -88,7 +88,7 @@ endif() + # addressed yet. + + if(NOT MSVC AND USE_XNNPACK) +- if(NOT TARGET fxdiv) ++ if(NOT TARGET fxdiv AND NOT USE_SYSTEM_FXDIV) + set(FXDIV_BUILD_TESTS OFF CACHE BOOL "") + set(FXDIV_BUILD_BENCHMARKS OFF CACHE BOOL "") + add_subdirectory( +@@ -399,6 +399,12 @@ list(APPEND LITE_PROFILER_SRCS "") + if(USE_LITE_INTERPRETER_PROFILER) + append_filelist("libtorch_edge_profiler_sources " LITE_PROFILER_SRCS) + endif() ++if(NOT USE_KINETO) ++ list(REMOVE_ITEM LITE_PROFILER_SRCS ++ "${TORCH_SRC_DIR}/csrc/profiler/kineto_shim.cpp" ++ "${TORCH_SRC_DIR}/csrc/autograd/profiler_kineto.cpp" ++ ) ++endif() + + # Switch between the full jit interpreter and lite interpreter + if(BUILD_LITE_INTERPRETER) diff --git a/ports/libtorch/fix-sources.patch b/ports/libtorch/fix-sources.patch index 3fc83bb1..716c1e3e 100644 --- a/ports/libtorch/fix-sources.patch +++ b/ports/libtorch/fix-sources.patch @@ -60,3 +60,32 @@ index 9e8a995..2c54558 100644 #include #include #include +diff --git a/c10/util/Logging.cpp b/c10/util/Logging.cpp +index b328d25..ab58966 100644 +--- a/c10/util/Logging.cpp ++++ b/c10/util/Logging.cpp +@@ -257,23 +257,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 { + namespace { + + void initGoogleLogging(char const* name) { + #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(name); diff --git a/ports/libtorch/portfile.cmake b/ports/libtorch/portfile.cmake index 6d5ad264..184c12ed 100644 --- a/ports/libtorch/portfile.cmake +++ b/ports/libtorch/portfile.cmake @@ -48,6 +48,7 @@ find_path(SITE_PACKAGES_DIR PATHS "${PYTHON_ROOT}/Lib/site-packages" "${PYTHON_ROOT}/lib/python3.11/site-packages" "${PYTHON_ROOT}/lib/python3.12/site-packages" + "${PYTHON_ROOT}/lib/python3.13/site-packages" REQUIRED ) get_filename_component(pybind11_DIR "${SITE_PACKAGES_DIR}/pybind11/share/cmake/pybind11" ABSOLUTE) @@ -104,6 +105,12 @@ else() set(IS_APPLE OFF) endif() +if(VCPKG_TARGET_IS_OSX) + set(KINETO_AVAILABLE OFF) +else() + set(KINETO_AVAILABLE ON) +endif() + string(COMPARE EQUAL "${VCPKG_CRT_LINKAGE}" "static" USE_STATIC_RUNTIME) vcpkg_cmake_configure( @@ -126,7 +133,7 @@ vcpkg_cmake_configure( -DUSE_XNNPACK=ON -DUSE_ITT=OFF -DUSE_OBSERVERS=OFF - -DUSE_KINETO=ON + -DUSE_KINETO=${KINETO_AVAILABLE} -DUSE_LITE_INTERPRETER_PROFILER=OFF -DBUILD_LITE_INTERPRETER=OFF -DUSE_NUMA=${VCPKG_TARGET_IS_LINUX}