vcpkg/ports/libtorch/portfile.cmake

184 lines
7.1 KiB
CMake
Raw Normal View History

[libtorch] create a new port (#17199) * [onnx] feature: foxi * https://github.com/houseroad/foxi * install the project's copyright (MIT) * pytorch requires `foxi_loader` The CMake target will be renamed to `onnxifi_*` for convenience. * [onnx] force onnx/onnx_proto static in Windows Checked the protject's CI logs. It turned out onnx/onnx_proto are ALWAYS static. Specify it in CMakeLists.txt because vcpkg configures `BUILD_SHARED_LIBS=ON` If the triplet requires it. There are no `ONNXIFI_ENABLE_EXT=ON` case. Removed the misused build options in portfile. Add port feature `protobuf-lite` which is in build option. * [onnx] support windows static triplets * remove SHARED for `onnxifi_wrapper` and `onnxifi_dummy` * [onnx] fix wrong LICENSE install * [onnx] remove feature 'foxi' * also remove redundant part in patch files * [libtorch] rework patch files * [libtorch] config fixup ATen, Torch * use `link_libraries` to vcpkg installed folder * future work may use library names without `find_library` * update versions JSON to use `version-semver` * [libtorch] make shared only * Caffe2 is exported when BUILD_SHARED_LIBS * [libtorch] remove headers after install * [libtorch] rewrite patches and feature options * checked osx / linux build * [libtorch] use eigen3 always * Caffe2 eigen_utils.h requires it * [libtorch] error if BLAS feature collision * [libtorch] remove !static * [libtorch] replace vcpkg_find_acquire_program * let's see python3 from find_program supports * Dependency python3 * [libtorch] migrate works from luncliff/vcpkg-registry * Update target version and dependencies * Removed unsupported features * [libtorch] misc fix, update version, baseline * fix merge confict for 'onnx' * [libtorch] install pip packages * typing-extensions, pyyaml * [libtorch] turn off Metal options * [onnx] revert 'onnx' changes * [libtorch] refine patches * [libtorch] link with foxi_loader * removed wrong onnx related source changes * [libtorch] update git-tree * [libtorch] reduce patch size * [libtorch] find numa and activate USE_NUMA * Update ports/libtorch/portfile.cmake Co-authored-by: nicole mazzuca <83086508+strega-nil-ms@users.noreply.github.com> * Update ports/libtorch/portfile.cmake Co-authored-by: nicole mazzuca <83086508+strega-nil-ms@users.noreply.github.com> * Update ports/libtorch/portfile.cmake Co-authored-by: nicole mazzuca <83086508+strega-nil-ms@users.noreply.github.com> * [libtorch] fix mistype and update version JSON * Add double quotes * version * Fix support expression * version * [libtorch] update cpuinfo usage * https://github.com/microsoft/vcpkg/pull/23944 * update version * [tensorpipe] fix linux install * find_package(Tensorpipe) may fail because of case mismatch * [tensorpipe] update versions JSON * [libtorch] fix feature failures * [libtorch] remove CUDA feature * [libtorch] giveup 'fbgemm' feature * [libtorch] use mpi, openmpi in Linux * [libtorch] fix glog link error * [tensorpipe] bump port version * see https://github.com/microsoft/vcpkg/pull/23569 * [libtorch] fix patch list * [libtorch] use official libuv config * see https://github.com/microsoft/vcpkg/pull/24745 * Update ports/libtorch/portfile.cmake Co-authored-by: Jack·Boos·Yu <47264268+JackBoosY@users.noreply.github.com> * Update ports/libtorch/portfile.cmake Co-authored-by: Jack·Boos·Yu <47264268+JackBoosY@users.noreply.github.com> * update versions JSON * revert unnecessary 'nnpack' changes * Update ports/libtorch/portfile.cmake Co-authored-by: Adam Johnson <AdamJohnso@gmail.com> * [libtorch] use vcpkg-get-python-packages * [libtorch] provide path of python3 * Update ports/libtorch/portfile.cmake Co-authored-by: Billy O'Neal <bion@microsoft.com> * Fix version database. * [libtorch] use openmpi in linux/osx * [libtorch] update to v1.12.1 * [libtorch] find_program(python3, python) * [libtorch] provide PYTHON_EXECUTABLE directly * [xnnpack] update to 2022-02-17 * [xnnpack] use C11, C++11 * [libtorch] more patches, DISABLE_PARALLEL_CONFIGURE * [libtorch] allow static torch_cpu build * Revert "[libtorch] allow static torch_cpu build" This reverts commit 5fd4ef0bbe4f56d5c027494c7c571a4f13b37b25. * [libtorch] find_package(BLAS) * [libtorch] simplify Python3, NumPy option use * [libtorch] fix install in Windows * [libtorch] exclude torch_global_deps in Windows * [libtorch] platform of nnpack feature * [libtorch] fix MPI option in Windows * [libtorch] fixing LNK1161 * [libtorch] fix some mistypes * [libtorch] define NOMINMAX for c10 * [libtorch] disable vulkan feature in Windows * ci.baseline.txt: allow libtorch failure * fails with Visual Studio 2022 17.4.2 * requires 17.4.3+ * Enable testing port on Windows * [caffe2] redirect to libtorch * update baseline Co-authored-by: JackBoosY <yuzaiyang@beyondsoft.com> Co-authored-by: nicole mazzuca <83086508+strega-nil-ms@users.noreply.github.com> Co-authored-by: Billy Robert O'Neal <bion@microsoft.com> Co-authored-by: Jack·Boos·Yu <47264268+JackBoosY@users.noreply.github.com> Co-authored-by: Adam Johnson <AdamJohnso@gmail.com> Co-authored-by: Victor Romero <romerosanchezv@gmail.com>
2023-01-19 03:06:34 +08:00
vcpkg_check_linkage(ONLY_DYNAMIC_LIBRARY)
vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO pytorch/pytorch
REF v1.12.1
SHA512 afeb551904ebd9b5901ae623a98eadbb3045115247cedf8006a940742cfad04e5ce24cfaf363336a9ed88d7ce6a4ac53dbb6a5c690aef6efdf20477c3a22c7ca
HEAD_REF master
PATCHES
pytorch-pr-85958.patch # https://github.com/pytorch/pytorch/pull/85958
fix-cmake.patch
fix-fbgemm-include.patch
fix-c10-glog.patch
use-flatbuffers2.patch # check with codegen-flatc-mobile_bytecode
fix-windows.patch # https://github.com/pytorch/pytorch/issues/87957
)
file(REMOVE_RECURSE "${SOURCE_PATH}/caffe2/core/macros.h") # We must use generated header files
# Editing ${SOURCE_PATH}/cmake/Dependencies.cmake makes HORRIBLE readability...
file(COPY "${CMAKE_CURRENT_LIST_DIR}/vcpkg-dependencies.cmake" DESTINATION "${SOURCE_PATH}/cmake")
find_program(FLATC NAMES flatc PATHS "${CURRENT_HOST_INSTALLED_DIR}/tools/flatbuffers" REQUIRED NO_DEFAULT_PATH NO_CMAKE_PATH)
message(STATUS "Using flatc: ${FLATC}")
vcpkg_execute_required_process(
COMMAND ${FLATC} --cpp --gen-object-api --gen-mutable mobile_bytecode.fbs
LOGNAME codegen-flatc-mobile_bytecode
WORKING_DIRECTORY "${SOURCE_PATH}/torch/csrc/jit/serialization"
)
find_program(PROTOC NAMES protoc PATHS "${CURRENT_HOST_INSTALLED_DIR}/tools/protobuf" REQUIRED NO_DEFAULT_PATH NO_CMAKE_PATH)
message(STATUS "Using protoc: ${PROTOC}")
x_vcpkg_get_python_packages(
PYTHON_VERSION 3
PACKAGES typing-extensions pyyaml numpy
OUT_PYTHON_VAR PYTHON3
)
message(STATUS "Using Python3: ${PYTHON3}")
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
tbb AT_PARALLEL_NATIVE_TBB
openmp USE_OPENMP
openmp AT_PARALLEL_OPENMP
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()
list(APPEND FEATURE_OPTIONS -DUSE_GLOO=${VCPKG_TARGET_IS_LINUX})
endif()
# BLAS: MKL, OpenBLAS, or Accelerate
# The feature will be disabled if "generic" BLAS is not found
if(VCPKG_TARGET_IS_OSX OR VCPKG_TARGET_IS_IOS)
list(APPEND BLAS_OPTIONS -DBLAS=Accelerate -DUSE_BLAS=ON)
elseif(VCPKG_TARGET_IS_WINDOWS)
list(APPEND BLAS_OPTIONS -DBLAS=OpenBLAS -DUSE_BLAS=ON)
elseif(VCPKG_TARGET_IS_LINUX)
list(APPEND BLAS_OPTIONS -DBLAS=generic -DUSE_BLAS=ON)
endif()
if("tbb" IN_LIST FEATURES)
list(APPEND FEATURE_OPTIONS -DMKLDNN_CPU_RUNTIME=TBB)
endif()
if(VCPKG_TARGET_IS_ANDROID OR VCPKG_TARGET_IS_IOS)
list(APPEND FEATURE_OPTIONS -DINTERN_BUILD_MOBILE=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}"
DISABLE_PARALLEL_CONFIGURE
OPTIONS
${FEATURE_OPTIONS}
-DProtobuf_PROTOC_EXECUTABLE:FILEPATH=${PROTOC}
-DCAFFE2_CUSTOM_PROTOC_EXECUTABLE:FILEPATH=${PROTOC}
-DPYTHON_EXECUTABLE:FILEPATH=${PYTHON3}
-DPython3_EXECUTABLE:FILEPATH=${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_NUMPY=OFF
-DUSE_METAL=OFF
-DUSE_PYTORCH_METAL=OFF
-DUSE_PYTORCH_METAL_EXPORT=OFF
-DUSE_GFLAGS=ON
-DUSE_GLOG=ON
-DUSE_LMDB=ON
-DUSE_ROCKSDB=OFF
-DUSE_OBSERVERS=OFF
-DUSE_PYTORCH_QNNPACK=OFF
-DUSE_KINETO=OFF
-DUSE_ROCM=OFF
-DUSE_DEPLOY=OFF
-DUSE_FFTW=OFF
-DUSE_NUMA=OFF
-DUSE_MPI=${VCPKG_TARGET_IS_LINUX}
-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=OFF
-DCAFFE2_USE_MKLDNN=OFF
-DAT_MKL_ENABLED=OFF
-DAT_MKLDNN_ENABLED=OFF
MAYBE_UNUSED_VARIABLES
USE_NUMA
USE_SYSTEM_BIND11
USE_VULKAN_WRAPPER
MKLDNN_CPU_RUNTIME
)
vcpkg_cmake_build(TARGET __aten_op_header_gen LOGFILE_BASE build-header_gen) # explicit codegen is required
vcpkg_cmake_build(TARGET torch_cpu LOGFILE_BASE build-torch_cpu)
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"
"${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"
)
file(INSTALL "${SOURCE_PATH}/LICENSE" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME "copyright")