From c1b1823f9bec0c24b2b903ef3bce7dafc869ea0a Mon Sep 17 00:00:00 2001 From: PARK DongHa Date: Sun, 24 Nov 2024 16:03:36 +0900 Subject: [PATCH] [libkineto] Create a new port with the latest commit (#303) * [libkineto] create a new port * https://github.com/pytorch/kineto/commit/7a2a167b7233e3a0294c2ebb94c458cccfed7f42 * patch for linux build * [libkineto] use more later commit * https://github.com/facebookincubator/dynolog/commit/7570766213484a926908c884888cfb701577a9cb * https://github.com/pytorch/kineto/commit/596126cba98181ce4a88e06aa1d602b6afd966dd --- ports/libkineto/fix-cmake.patch | 37 ++++++++++++++++++++++++++ ports/libkineto/fix-sources.patch | 31 ++++++++++++++++++++++ ports/libkineto/portfile.cmake | 44 +++++++++++++++++++++++++++++++ ports/libkineto/vcpkg.json | 19 +++++++++++++ versions/baseline.json | 4 +++ versions/l-/libkineto.json | 9 +++++++ 6 files changed, 144 insertions(+) create mode 100644 ports/libkineto/fix-cmake.patch create mode 100644 ports/libkineto/fix-sources.patch create mode 100644 ports/libkineto/portfile.cmake create mode 100644 ports/libkineto/vcpkg.json create mode 100644 versions/l-/libkineto.json diff --git a/ports/libkineto/fix-cmake.patch b/ports/libkineto/fix-cmake.patch new file mode 100644 index 00000000..f62b67be --- /dev/null +++ b/ports/libkineto/fix-cmake.patch @@ -0,0 +1,37 @@ +diff --git a/libkineto/CMakeLists.txt b/libkineto/CMakeLists.txt +index 140ee68..bc4d540 100644 +--- a/libkineto/CMakeLists.txt ++++ b/libkineto/CMakeLists.txt +@@ -52,6 +52,13 @@ if (NOT ROCM_SOURCE_DIR) + message(INFO " ROCM_SOURCE_DIR = ${ROCM_SOURCE_DIR}") + endif() + ++if(NOT LIBKINETO_NOCUPTI) ++ find_package(CUDAToolkit REQUIRED) ++ math(EXPR CUDA_VERSION "${CUDAToolkit_VERSION_MAJOR}000 + ${CUDAToolkit_VERSION_MINOR}0" OUTPUT_FORMAT DECIMAL) ++ add_compile_definitions(CUDA_VERSION=${CUDA_VERSION}) ++ get_target_property(CUPTI_INCLUDE_DIR CUDA::cupti INTERFACE_INCLUDE_DIRECTORIES) ++ get_target_property(CUDA_cupti_LIBRARY CUDA::cupti IMPORTED_LOCATION) ++endif() + if (KINETO_BUILD_TESTS) + enable_testing() + if (NOT CUDA_SOURCE_DIR) +@@ -193,7 +200,8 @@ endif() + target_compile_options(kineto_base PRIVATE "${KINETO_COMPILE_OPTIONS}") + target_compile_options(kineto_api PRIVATE "${KINETO_COMPILE_OPTIONS}") + +-if(NOT TARGET fmt) ++find_package(fmt CONFIG REQUIRED) ++if(FALSE) + if(NOT FMT_SOURCE_DIR) + set(FMT_SOURCE_DIR "${LIBKINETO_THIRDPARTY_DIR}/fmt" + CACHE STRING "fmt source directory from submodules") +@@ -211,7 +219,7 @@ if(NOT TARGET fmt) + set(BUILD_SHARED_LIBS ${TEMP_BUILD_SHARED_LIBS} CACHE BOOL "Build shared libs" FORCE) + endif() + +-set(FMT_INCLUDE_DIR "${FMT_SOURCE_DIR}/include") ++find_path(FMT_INCLUDE_DIR NAMES "fmt/format.h" REQUIRED) + message(STATUS "Kineto: FMT_SOURCE_DIR = ${FMT_SOURCE_DIR}") + message(STATUS "Kineto: FMT_INCLUDE_DIR = ${FMT_INCLUDE_DIR}") + if (NOT CUPTI_INCLUDE_DIR) diff --git a/ports/libkineto/fix-sources.patch b/ports/libkineto/fix-sources.patch new file mode 100644 index 00000000..f9deea3b --- /dev/null +++ b/ports/libkineto/fix-sources.patch @@ -0,0 +1,31 @@ +diff --git a/libkineto/src/CuptiCallbackApi.cpp b/libkineto/src/CuptiCallbackApi.cpp +index 9c8e0f4..e7e6226 100644 +--- a/libkineto/src/CuptiCallbackApi.cpp ++++ b/libkineto/src/CuptiCallbackApi.cpp +@@ -100,10 +100,12 @@ void CuptiCallbackApi::__callback_switchboard( + if (cbInfo->callbackSite == CUPTI_API_EXIT) { + LOG(INFO) << " Calling cuptiFinalize in exit callsite"; + // Teardown CUPTI calling cuptiFinalize() ++#ifdef HAS_CUPTI + CUPTI_CALL(cuptiUnsubscribe(subscriber_)); + CUPTI_CALL(cuptiFinalize()); + initSuccess_ = false; + subscriber_ = nullptr; ++#endif + CuptiActivityApi::singleton().teardownCupti_ = 0; + CuptiActivityApi::singleton().finalizeCond_.notify_all(); + return; +diff --git a/libkineto/src/Logger.h b/libkineto/src/Logger.h +index 3b9caaf..5b33b87 100644 +--- a/libkineto/src/Logger.h ++++ b/libkineto/src/Logger.h +@@ -47,6 +47,9 @@ + // unset a predefined ERROR (windows) + #undef ERROR + #endif // _MSC_VER ++#ifdef __linux__ ++using libkineto::ERROR; ++#endif + + namespace KINETO_NAMESPACE { + diff --git a/ports/libkineto/portfile.cmake b/ports/libkineto/portfile.cmake new file mode 100644 index 00000000..ea122aaa --- /dev/null +++ b/ports/libkineto/portfile.cmake @@ -0,0 +1,44 @@ +vcpkg_check_linkage(ONLY_STATIC_LIBRARY) + +vcpkg_from_github( + OUT_SOURCE_PATH SOURCE_PATH + REPO pytorch/kineto + REF 596126cba98181ce4a88e06aa1d602b6afd966dd + SHA512 5f7916a914e78afba56d47c6589eccf7303a7bdf9a55fcbbeef8733f49e554bce00a4829fb50813736913433a35cdedcccd942c79b1ebb9cae6c76693aae6648 + HEAD_REF main + PATCHES + fix-cmake.patch + fix-sources.patch +) + +vcpkg_from_github( + OUT_SOURCE_PATH DYNOLOG_SOURCE_PATH + REPO facebookincubator/dynolog + REF 7570766213484a926908c884888cfb701577a9cb # 2024-11-12 + SHA512 548b51276dfc924ab513406810b90a19de7e0557bfc185cc6e1e285dbaefa685fb8664524c0a04b5802f87911e68e30db675cb1d6bbecc269b441c5972b9dea2 + HEAD_REF main +) +file(REMOVE_RECURSE "${SOURCE_PATH}/libkineto/third_party/dynolog") +file(RENAME "${DYNOLOG_SOURCE_PATH}" "${SOURCE_PATH}/libkineto/third_party/dynolog") + +vcpkg_find_acquire_program(PYTHON3) +message(STATUS "Using Python3: ${PYTHON3}") + +vcpkg_cmake_configure( + SOURCE_PATH "${SOURCE_PATH}/libkineto" + OPTIONS + -DPYTHON_EXECUTABLE:FILEPATH=${PYTHON3} + -DKINETO_BUILD_TESTS=OFF + -DLIBKINETO_NOCUPTI=ON # todo: support CUDA feature + -DLIBKINETO_NOROCTRACER=ON + -DLIBKINETO_NOXPUPTI=ON +) +vcpkg_cmake_install() +vcpkg_cmake_config_fixup(PACKAGE_NAME kinetoLibrary CONFIG_PATH "share/cmake/kineto") + +file(REMOVE_RECURSE + "${CURRENT_PACKAGES_DIR}/debug/include" + "${CURRENT_PACKAGES_DIR}/debug/share" +) + +vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE") diff --git a/ports/libkineto/vcpkg.json b/ports/libkineto/vcpkg.json new file mode 100644 index 00000000..6478c797 --- /dev/null +++ b/ports/libkineto/vcpkg.json @@ -0,0 +1,19 @@ +{ + "name": "libkineto", + "version-date": "2024-11-22", + "description": "A CPU+GPU Profiling library that provides access to timeline traces and hardware performance counters", + "homepage": "https://github.com/pytorch/kineto", + "license": "BSD-3-Clause", + "dependencies": [ + "fmt", + "glog", + { + "name": "vcpkg-cmake", + "host": true + }, + { + "name": "vcpkg-cmake-config", + "host": true + } + ] +} diff --git a/versions/baseline.json b/versions/baseline.json index b0a8e30d..82e5594a 100644 --- a/versions/baseline.json +++ b/versions/baseline.json @@ -84,6 +84,10 @@ "baseline": "5.10.1", "port-version": 0 }, + "libkineto": { + "baseline": "2024-11-22", + "port-version": 0 + }, "liblzma": { "baseline": "5.6.2", "port-version": 0 diff --git a/versions/l-/libkineto.json b/versions/l-/libkineto.json new file mode 100644 index 00000000..4a722f8a --- /dev/null +++ b/versions/l-/libkineto.json @@ -0,0 +1,9 @@ +{ + "versions": [ + { + "git-tree": "b058e6125b7c3e64ccd0b45e726f668b7f39d002", + "version-date": "2024-11-22", + "port-version": 0 + } + ] +}