diff --git a/ports/libtorch/fix-cmake.patch b/ports/libtorch/fix-cmake.patch index 2257feb6..3f22aba3 100644 --- a/ports/libtorch/fix-cmake.patch +++ b/ports/libtorch/fix-cmake.patch @@ -26,7 +26,7 @@ index 0087dd9..257c0bd 100644 endif() list(APPEND ATen_CPU_DEPENDENCY_LIBS sleef) diff --git a/aten/src/ATen/native/quantized/cpu/qnnpack/CMakeLists.txt b/aten/src/ATen/native/quantized/cpu/qnnpack/CMakeLists.txt -index fd6b7ff..12007a5 100644 +index fd6b7ff..ba6b7a3 100644 --- a/aten/src/ATen/native/quantized/cpu/qnnpack/CMakeLists.txt +++ b/aten/src/ATen/native/quantized/cpu/qnnpack/CMakeLists.txt @@ -337,13 +337,8 @@ target_link_libraries(pytorch_qnnpack PUBLIC clog) @@ -45,6 +45,25 @@ index fd6b7ff..12007a5 100644 elseif(NOT TARGET cpuinfo) set(CPUINFO_BUILD_TOOLS OFF CACHE BOOL "") set(CPUINFO_BUILD_UNIT_TESTS OFF CACHE BOOL "") +@@ -364,14 +359,11 @@ if(NOT TARGET pthreadpool AND NOT USE_SYSTEM_PTHREADPOOL) + "${CONFU_DEPENDENCIES_BINARY_DIR}/pthreadpool") + elseif(NOT TARGET pthreadpool AND USE_SYSTEM_PTHREADPOOL) + add_library(pthreadpool SHARED IMPORTED) +- find_library(PTHREADPOOL_LIBRARY pthreadpool) +- if(NOT PTHREADPOOL_LIBRARY) +- message(FATAL_ERROR "Cannot find pthreadpool") +- endif() +- message("-- Found pthreadpool: ${PTHREADPOOL_LIBRARY}") +- set_target_properties(pthreadpool PROPERTIES +- IMPORTED_LOCATION "${PTHREADPOOL_LIBRARY}") ++ find_library(PTHREADPOOL_LIBRARY pthreadpool REQUIRED) ++ set_target_properties(pthreadpool PROPERTIES IMPORTED_LOCATION "${PTHREADPOOL_LIBRARY}") + add_library(pthreadpool_interface INTERFACE) ++ find_path(PTHREADPOOL_INCLUDE_DIR "pthreadpool.h" REQUIRED) ++ set_target_properties(pthreadpool_interface PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${PTHREADPOOL_INCLUDE_DIR}") + endif() + if(PYTORCH_QNNPACK_CUSTOM_THREADPOOL) + # Depend on pthreadpool interface, but not on implementation. diff --git a/caffe2/CMakeLists.txt b/caffe2/CMakeLists.txt index 89c31fa..c08ab68 100644 --- a/caffe2/CMakeLists.txt @@ -74,26 +93,35 @@ index 89c31fa..c08ab68 100644 install(TARGETS torch_global_deps DESTINATION "${TORCH_INSTALL_LIB_DIR}") endif() diff --git a/cmake/Dependencies.cmake b/cmake/Dependencies.cmake -index c4661e3..9d50b55 100644 +index c4661e3..6e51b7d 100644 --- a/cmake/Dependencies.cmake +++ b/cmake/Dependencies.cmake -@@ -370,13 +370,8 @@ if(INTERN_BUILD_MOBILE OR NOT DISABLE_NNPACK_AND_FAMILY) - +@@ -371,12 +371,9 @@ if(INTERN_BUILD_MOBILE OR NOT DISABLE_NNPACK_AND_FAMILY) if(NOT TARGET pthreadpool) if(USE_SYSTEM_PTHREADPOOL) -- add_library(pthreadpool SHARED IMPORTED) + add_library(pthreadpool SHARED IMPORTED) - find_library(PTHREADPOOL_LIBRARY pthreadpool) - set_property(TARGET pthreadpool PROPERTY IMPORTED_LOCATION "${PTHREADPOOL_LIBRARY}") - if(NOT PTHREADPOOL_LIBRARY) - message(FATAL_ERROR "Cannot find pthreadpool") - endif() - message("-- Found pthreadpool: ${PTHREADPOOL_LIBRARY}") -+ find_package(unofficial-pthreadpool CONFIG REQUIRED) -+ add_library(pthreadpool ALIAS unofficial::pthreadpool) ++ find_library(PTHREADPOOL_LIBRARY pthreadpool REQUIRED) ++ set_target_properties(pthreadpool PROPERTIES IMPORTED_LOCATION "${PTHREADPOOL_LIBRARY}") ++ message(STATUS "Found pthreadpool: ${PTHREADPOOL_LIBRARY}") elseif(NOT USE_INTERNAL_PTHREADPOOL_IMPL) if(NOT DEFINED PTHREADPOOL_SOURCE_DIR) set(CAFFE2_THIRD_PARTY_ROOT "${PROJECT_SOURCE_DIR}/third_party") -@@ -407,13 +402,8 @@ if(NOT CMAKE_SYSTEM_PROCESSOR MATCHES "^(s390x|ppc64le)$") +@@ -396,7 +393,7 @@ if(INTERN_BUILD_MOBILE OR NOT DISABLE_NNPACK_AND_FAMILY) + if(USE_INTERNAL_PTHREADPOOL_IMPL) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_INTERNAL_PTHREADPOOL_IMPL") + else() +- list(APPEND Caffe2_DEPENDENCY_LIBS pthreadpool) ++ list(APPEND Caffe2_DEPENDENCY_LIBS "${PTHREADPOOL_LIBRARY}") + endif() + endif() + else() +@@ -407,13 +404,8 @@ if(NOT CMAKE_SYSTEM_PROCESSOR MATCHES "^(s390x|ppc64le)$") # ---[ Caffe2 uses cpuinfo library in the thread pool # ---[ But it doesn't support s390x/powerpc and thus not used on s390x/powerpc if(NOT TARGET cpuinfo AND USE_SYSTEM_CPUINFO) @@ -109,7 +137,7 @@ index c4661e3..9d50b55 100644 elseif(NOT TARGET cpuinfo) if(NOT DEFINED CPUINFO_SOURCE_DIR) set(CPUINFO_SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/../third_party/cpuinfo" CACHE STRING "cpuinfo source directory") -@@ -569,8 +559,8 @@ elseif(NOT TARGET XNNPACK AND USE_SYSTEM_XNNPACK) +@@ -569,8 +561,8 @@ elseif(NOT TARGET XNNPACK AND USE_SYSTEM_XNNPACK) if(NOT XNNPACK_LIBRARY) message(FATAL_ERROR "Cannot find XNNPACK") endif() @@ -120,7 +148,7 @@ index c4661e3..9d50b55 100644 endif() # ---[ Vulkan deps -@@ -812,8 +802,9 @@ if(NOT TARGET fp16 AND NOT USE_SYSTEM_FP16) +@@ -812,8 +804,9 @@ if(NOT TARGET fp16 AND NOT USE_SYSTEM_FP16) "${FP16_SOURCE_DIR}" "${CONFU_DEPENDENCIES_BINARY_DIR}/FP16") elseif(NOT TARGET fp16 AND USE_SYSTEM_FP16) @@ -132,7 +160,7 @@ index c4661e3..9d50b55 100644 endif() list(APPEND Caffe2_DEPENDENCY_LIBS fp16) -@@ -996,7 +987,7 @@ if(USE_CUDNN) +@@ -996,7 +989,7 @@ if(USE_CUDNN) if(CUDNN_VERSION VERSION_LESS 8.5) message(FATAL_ERROR "PyTorch needs CuDNN-8.5 or above, but found ${CUDNN_VERSION}. Builds are still possible with `USE_CUDNN=0`") endif() @@ -141,7 +169,7 @@ index c4661e3..9d50b55 100644 target_include_directories(torch::cudnn INTERFACE ${CUDNN_FRONTEND_INCLUDE_DIR}) endif() -@@ -1207,7 +1198,7 @@ if(USE_GLOO) +@@ -1207,7 +1200,7 @@ if(USE_GLOO) if(NOT GLOO_LIBRARY) message(FATAL_ERROR "Cannot find gloo") endif() @@ -150,7 +178,7 @@ index c4661e3..9d50b55 100644 set_target_properties(gloo PROPERTIES IMPORTED_LOCATION ${GLOO_LIBRARY}) endif() # Here is a little bit hacky. We have to put PROJECT_BINARY_DIR in front -@@ -1288,7 +1279,7 @@ if(CAFFE2_CMAKE_BUILDING_WITH_MAIN_REPO AND NOT INTERN_DISABLE_ONNX) +@@ -1288,7 +1281,7 @@ if(CAFFE2_CMAKE_BUILDING_WITH_MAIN_REPO AND NOT INTERN_DISABLE_ONNX) set_target_properties(onnx_proto PROPERTIES CXX_STANDARD 17) endif() endif() @@ -159,7 +187,7 @@ index c4661e3..9d50b55 100644 add_definitions(-DONNX_NAMESPACE=${ONNX_NAMESPACE}) if(NOT USE_SYSTEM_ONNX) -@@ -1306,23 +1297,17 @@ if(CAFFE2_CMAKE_BUILDING_WITH_MAIN_REPO AND NOT INTERN_DISABLE_ONNX) +@@ -1306,23 +1299,17 @@ if(CAFFE2_CMAKE_BUILDING_WITH_MAIN_REPO AND NOT INTERN_DISABLE_ONNX) target_compile_options(onnx PRIVATE -Wno-deprecated-declarations) endif() else() @@ -192,7 +220,7 @@ index c4661e3..9d50b55 100644 # Recover the build shared libs option. set(BUILD_SHARED_LIBS ${TEMP_BUILD_SHARED_LIBS}) endif() -@@ -1530,7 +1515,7 @@ endif() +@@ -1530,7 +1517,7 @@ endif() # set(TEMP_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS}) set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared libs" FORCE) @@ -201,7 +229,7 @@ index c4661e3..9d50b55 100644 # Disable compiler feature checks for `fmt`. # -@@ -1539,7 +1524,7 @@ add_subdirectory(${PROJECT_SOURCE_DIR}/third_party/fmt) +@@ -1539,7 +1526,7 @@ add_subdirectory(${PROJECT_SOURCE_DIR}/third_party/fmt) # 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. @@ -210,26 +238,27 @@ index c4661e3..9d50b55 100644 list(APPEND Caffe2_DEPENDENCY_LIBS fmt::fmt-header-only) set(BUILD_SHARED_LIBS ${TEMP_BUILD_SHARED_LIBS} CACHE BOOL "Build shared libs" FORCE) -@@ -1681,5 +1666,4 @@ endif() +@@ -1681,5 +1668,5 @@ endif() include(${CMAKE_CURRENT_LIST_DIR}/FlatBuffers.cmake) # Include cpp-httplib -add_library(httplib INTERFACE IMPORTED) -target_include_directories(httplib SYSTEM INTERFACE ${PROJECT_SOURCE_DIR}/third_party/cpp-httplib) +find_package(httplib CONFIG REQUIRED) # httplib::httplib ++add_library(httplib ALIAS httplib::httplib) diff --git a/cmake/public/cuda.cmake b/cmake/public/cuda.cmake -index b37036d..b988e1c 100644 +index b37036d..281b4ec 100644 --- a/cmake/public/cuda.cmake +++ b/cmake/public/cuda.cmake -@@ -66,7 +66,7 @@ if(NOT CMAKE_CUDA_COMPILER_VERSION VERSION_EQUAL CUDAToolkit_VERSION) - "V${CUDAToolkit_VERSION} in '${CUDAToolkit_INCLUDE_DIRS}'") +@@ -67,7 +67,7 @@ if(NOT CMAKE_CUDA_COMPILER_VERSION VERSION_EQUAL CUDAToolkit_VERSION) endif() --if(NOT TARGET CUDA::nvToolsExt) -+if(FALSE) - message(FATAL_ERROR "Failed to find nvToolsExt") + if(NOT TARGET CUDA::nvToolsExt) +- message(FATAL_ERROR "Failed to find nvToolsExt") ++ message(WARNING "Failed to find nvToolsExt") endif() + message(STATUS "Caffe2: CUDA detected: " ${CUDA_VERSION}) @@ -183,10 +183,10 @@ else() endif() @@ -246,17 +275,16 @@ index b37036d..b988e1c 100644 # cublas add_library(caffe2::cublas INTERFACE IMPORTED) diff --git a/torch/CMakeLists.txt b/torch/CMakeLists.txt -index 10a44af..3232f93 100644 +index 10a44af..5460ce7 100644 --- a/torch/CMakeLists.txt +++ b/torch/CMakeLists.txt -@@ -133,8 +133,9 @@ if(USE_CUDA) - list(APPEND TORCH_PYTHON_LINK_LIBRARIES torch::cudnn) +@@ -134,7 +134,9 @@ if(USE_CUDA) list(APPEND TORCH_PYTHON_COMPILE_DEFINITIONS USE_CUDNN) endif() -- + - list(APPEND TORCH_PYTHON_LINK_LIBRARIES torch::nvtoolsext) + if(TARGET torch::nvtoolsext) -+ list(APPEND TORCH_PYTHON_LINK_LIBRARIES torch::nvtoolsext) ++ list(APPEND TORCH_PYTHON_LINK_LIBRARIES torch::nvtoolsext) # may not installed... + endif() endif() diff --git a/ports/libtorch/portfile.cmake b/ports/libtorch/portfile.cmake index c8987209..bf6ef8a4 100644 --- a/ports/libtorch/portfile.cmake +++ b/ports/libtorch/portfile.cmake @@ -55,15 +55,10 @@ get_filename_component(pybind11_DIR "${SITE_PACKAGES_DIR}/pybind11/share/cmake/p vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS FEATURES dist USE_DISTRIBUTED # MPI, Gloo, TensorPipe - zstd USE_ZSTD fbgemm USE_FBGEMM - opencv USE_OPENCV # These are alternatives ! - # tbb USE_TBB - # tbb AT_PARALLEL_NATIVE_TBB # AT_PARALLEL_ are alternatives # openmp USE_OPENMP # openmp AT_PARALLEL_OPENMP # AT_PARALLEL_ are alternatives - leveldb USE_LEVELDB opencl USE_OPENCL cuda USE_CUDA cuda USE_CUDNN @@ -74,15 +69,14 @@ vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS cuda AT_CUDNN_ENABLED cuda USE_MAGMA vulkan USE_VULKAN - #vulkan USE_VULKAN_SHADERC_RUNTIME vulkan USE_VULKAN_RELAXED_PRECISION rocm USE_ROCM # This is an alternative to cuda not a feature! (Not in vcpkg.json!) -> disabled llvm USE_LLVM mpi USE_MPI nnpack USE_NNPACK # todo: check use of `DISABLE_NNPACK_AND_FAMILY` nnpack AT_NNPACK_ENABLED - qnnpack USE_QNNPACK # todo: check use of `USE_PYTORCH_QNNPACK` -# No feature in vcpkg yet so disabled. -> Requires numpy build by vcpkg itself + qnnpack USE_PYTORCH_QNNPACK + # No feature in vcpkg yet so disabled. -> Requires numpy build by vcpkg itself python BUILD_PYTHON python USE_NUMPY ) @@ -91,16 +85,16 @@ 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) + if(VCPKG_TARGET_IS_OSX) list(APPEND FEATURE_OPTIONS -DUSE_LIBUV=ON) endif() list(APPEND FEATURE_OPTIONS -DUSE_GLOO=${VCPKG_TARGET_IS_LINUX}) endif() if(VCPKG_TARGET_IS_ANDROID OR VCPKG_TARGET_IS_IOS) - list(APPEND FEATURE_OPTIONS -DINTERN_BUILD_MOBILE=ON) + set(IS_MOBILE ON) else() - list(APPEND FEATURE_OPTIONS -DINTERN_BUILD_MOBILE=OFF) + set(IS_MOBILE OFF) endif() if(VCPKG_TARGET_IS_OSX OR VCPKG_TARGET_IS_IOS) @@ -114,61 +108,37 @@ string(COMPARE EQUAL "${VCPKG_CRT_LINKAGE}" "static" USE_STATIC_RUNTIME) vcpkg_cmake_configure( SOURCE_PATH "${SOURCE_PATH}" DISABLE_PARALLEL_CONFIGURE - # WINDOWS_USE_MSBUILD OPTIONS ${FEATURE_OPTIONS} -DProtobuf_PROTOC_EXECUTABLE:FILEPATH=${PROTOC} -DCAFFE2_CUSTOM_PROTOC_EXECUTABLE:FILEPATH=${PROTOC} -DPYTHON_EXECUTABLE:FILEPATH=${PYTHON3} -Dpybind11_DIR:PATH=${pybind11_DIR} - -DCAFFE2_STATIC_LINK_CUDA=ON -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 - -DUSE_METAL=${IS_APPLE} -DUSE_PYTORCH_METAL=${IS_APPLE} -DUSE_PYTORCH_METAL_EXPORT=${IS_APPLE} -DUSE_GFLAGS=ON -DUSE_GLOG=ON - -DUSE_LMDB=ON + -DUSE_XNNPACK=ON -DUSE_ITT=OFF - -DUSE_ROCKSDB=ON -DUSE_OBSERVERS=OFF - -DUSE_PYTORCH_QNNPACK=OFF -DUSE_KINETO=OFF - -DUSE_ROCM=OFF - -DUSE_NUMA=OFF - -DUSE_SYSTEM_ONNX=ON - -DUSE_SYSTEM_FP16=ON - -DUSE_SYSTEM_EIGEN_INSTALL=ON - -DUSE_SYSTEM_CPUINFO=ON - -DUSE_SYSTEM_PTHREADPOOL=ON - -DUSE_SYSTEM_XNNPACK=ON - -DUSE_SYSTEM_PYBIND11=ON - -DUSE_SYSTEM_ZSTD=ON - -DUSE_SYSTEM_GLOO=ON - -DUSE_SYSTEM_NCCL=ON - -DUSE_SYSTEM_LIBS=ON - -DUSE_SYSTEM_FXDIV=ON - -DUSE_SYSTEM_SLEEF=ON + -DUSE_LITE_INTERPRETER_PROFILER=OFF + -DUSE_NUMA=${VCPKG_TARGET_IS_LINUX} + -DUSE_MIMALLOC=${VCPKG_TARGET_IS_WINDOWS} + -DINTERN_BUILD_MOBILE=${IS_MOBILE} -DBUILD_JNI=${VCPKG_TARGET_IS_ANDROID} -DUSE_NNAPI=${VCPKG_TARGET_IS_ANDROID} - ${BLAS_OPTIONS} # BLAS=MKL not supported in this port -DUSE_MKLDNN=OFF -DUSE_MKLDNN_CBLAS=OFF - #-DCAFFE2_USE_MKL=ON - #-DAT_MKL_ENABLED=ON -DAT_MKLDNN_ENABLED=OFF - -DUSE_OPENCL=ON - -DUSE_NUMPY=ON MAYBE_UNUSED_VARIABLES + PYTHON_EXECUTABLE USE_NUMA - USE_SYSTEM_BIND11 - MKLDNN_CPU_RUNTIME ) vcpkg_cmake_install() diff --git a/ports/libtorch/vcpkg.json b/ports/libtorch/vcpkg.json index ad535907..a9199c6f 100644 --- a/ports/libtorch/vcpkg.json +++ b/ports/libtorch/vcpkg.json @@ -26,6 +26,10 @@ "libkineto", "lmdb", "mimalloc", + { + "name": "mimalloc", + "platform": "windows" + }, "onnx", "onnx-optimizer", "opencl", @@ -55,10 +59,8 @@ "default-features": [ { "name": "cuda", - "platform": "windows & !x86" - }, - "opencv", - "zstd" + "platform": "windows & x64" + } ], "features": { "cuda": { @@ -97,13 +99,6 @@ } ] }, - "leveldb": { - "description": "Build with LevelDB", - "dependencies": [ - "leveldb", - "snappy" - ] - }, "llvm": { "description": "Build with LLVM", "dependencies": [ @@ -117,18 +112,12 @@ ] }, "nnpack": { - "description": "Build with NNPack", + "description": "Build with NNPACK", "supports": "linux | osx", "dependencies": [ "nnpack" ] }, - "opencv": { - "description": "Build with OpenCV 3.x", - "dependencies": [ - "opencv" - ] - }, "vulkan": { "description": "Build with Vulkan GPU backend", "dependencies": [ @@ -136,12 +125,6 @@ "vulkan-loader", "vulkan-memory-allocator" ] - }, - "zstd": { - "description": "Build with ZSTD", - "dependencies": [ - "zstd" - ] } } }