vcpkg/ports/libtorch/vcpkg-dependencies.cmake
Park DongHa d8c61f7fbf
[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-18 11:06:34 -08:00

258 lines
8.3 KiB
CMake

# caffe2/core/macros.h.in
set(CAFFE2_USE_GOOGLE_GLOG 1)
set(CAFFE2_USE_LITE_PROTO 0)
# set(CAFFE2_FORCE_FALLBACK_CUDA_MPI 0)
# aten/src/ATen/Config.h.in
set(AT_POCKETFFT_ENABLED 0)
set(AT_MKL_ENABLED 0)
set(AT_FFTW_ENABLED 0)
set(AT_PARALLEL_NATIVE 1)
if(USE_OPENMP OR USE_TBB)
set(AT_PARALLEL_NATIVE 0)
endif()
find_program(Python3_EXECUTABLE NAMES python3 python REQUIRED)
find_program(PYTHON_EXECUTABLE NAMES python3 python REQUIRED)
find_package(Python3 REQUIRED COMPONENTS Interpreter)
if(BUILD_PYTHON)
find_package(Python3 REQUIRED COMPONENTS Development NumPy)
list(APPEND Caffe2_DEPENDENCY_LIBS Python3::Python Python3::NumPy)
find_package(pybind11 CONFIG REQUIRED)
list(APPEND Caffe2_DEPENDENCY_LIBS pybind11::pybind11)
endif()
find_path(FP16_INCLUDE_DIRS "fp16.h" REQUIRED)
find_path(PSIMD_INCLUDE_DIRS "psimd.h" REQUIRED)
find_path(FXDIV_INCLUDE_DIRS "fxdiv.h" REQUIRED)
find_library(FOXI_LOADER_LIBPATH NAMES foxi_loader REQUIRED)
list(APPEND Caffe2_DEPENDENCY_LIBS ${FOXI_LOADER_LIBPATH})
find_package(Threads REQUIRED) # Threads::Threads
find_package(gemmlowp CONFIG REQUIRED) # gemmlowp::gemmlowp
find_package(gflags CONFIG REQUIRED) # gflags::gflags
find_package(glog CONFIG REQUIRED) # glog::glog
find_package(cpuinfo CONFIG REQUIRED) # cpuinfo::clog cpuinfo::cpuinfo
find_package(unofficial-pthreadpool CONFIG REQUIRED) # unofficial::pthreadpool
list(APPEND Caffe2_DEPENDENCY_LIBS
gemmlowp::gemmlowp gflags::gflags glog::glog
cpuinfo::clog cpuinfo::cpuinfo unofficial::pthreadpool
)
link_directories(
$<$<CONFIG:Debug>:${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/debug/lib>
$<$<CONFIG:Release>:${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib>
)
set(USE_PTHREADPOOL 1)
set(USE_INTERNAL_PTHREADPOOL_IMPL 0)
add_compile_definitions(USE_PTHREADPOOL)
find_package(fmt CONFIG REQUIRED) # fmt::fmt-header-only
list(APPEND Caffe2_DEPENDENCY_LIBS fmt::fmt-header-only)
find_package(Eigen3 CONFIG REQUIRED) # Eigen3::Eigen
include_directories(SYSTEM ${EIGEN3_INCLUDE_DIR})
list(APPEND Caffe2_DEPENDENCY_LIBS Eigen3::Eigen)
set(CAFFE2_USE_EIGEN_FOR_BLAS 1) # see caff2/core/macros.h.in
if(BLAS STREQUAL "Accelerate")
set(WITH_BLAS "accelerate")
find_package(BLAS REQUIRED) # cmake/Modules/FindBLAS.cmake
find_package(LAPACK REQUIRED) # cmake/Modules/FindLAPACK.cmake
set(USE_LAPACK 1)
list(APPEND Caffe2_PRIVATE_DEPENDENCY_LIBS ${LAPACK_LIBRARIES})
elseif(BLAS STREQUAL "Open")
set(WITH_BLAS "open")
find_package(BLAS)
if(BLAS_FOUND)
set(USE_BLAS 1)
list(APPEND Caffe2_PRIVATE_DEPENDENCY_LIBS ${BLAS_LIBRARIES})
else()
set(USE_BLAS 0) # if we couldn't find the BLAS, disable the feature
endif()
set(USE_LAPACK 0)
elseif(BLAS STREQUAL "MKL")
if(USE_TBB)
set(MKL_THREADING "TBB")
else()
set(MKL_THREADING "SEQ")
endif()
find_package(MKL REQUIRED)
include(${CMAKE_CURRENT_LIST_DIR}/public/mkl.cmake)
include_directories(AFTER SYSTEM ${MKL_INCLUDE_DIR})
list(APPEND Caffe2_PUBLIC_DEPENDENCY_LIBS caffe2::mkl)
set(WITH_BLAS "mkl")
find_package(BLAS REQUIRED) # cmake/Modules/FindBLAS.cmake
else()
set(USE_BLAS 0)
set(WITH_BLAS "generic")
find_package(BLAS)
if(BLAS_FOUND)
set(USE_BLAS 1)
list(APPEND Caffe2_PRIVATE_DEPENDENCY_LIBS ${BLAS_LIBRARIES})
endif()
endif()
if(USE_MKLDNN)
find_package(MKLDNN REQUIRED) # BLAS::BLAS
include(cmake/public/mkldnn.cmake)
include_directories(AFTER SYSTEM ${MKLDNN_INCLUDE_DIR})
list(APPEND Caffe2_PUBLIC_DEPENDENCY_LIBS caffe2::mkldnn)
endif()
if(USE_TBB)
find_package(TBB CONFIG REQUIRED) # TBB::tbb
list(APPEND Caffe2_DEPENDENCY_LIBS TBB::tbb)
endif()
if(USE_NNPACK)
find_library(NNPACK_LIB NAMES nnpack REQUIRED)
list(APPEND Caffe2_DEPENDENCY_LIBS ${NNPACK_LIB})
string(APPEND CMAKE_CXX_FLAGS " -DUSE_NNPACK")
endif()
if(USE_FBGEMM)
find_package(asmjit CONFIG REQUIRED) # asmjit::asmjit (required by fbgemm)
find_package(fbgemmLibrary CONFIG REQUIRED) # fbgemm
list(APPEND Caffe2_DEPENDENCY_LIBS asmjit::asmjit fbgemm)
if(USE_CUDA)
# todo: fbgemm-gpu
endif()
endif()
if(USE_LMDB)
find_package(LMDB) # from cmake/Modules/FindLMDB.cmake
if(LMDB_FOUND)
list(APPEND Caffe2_DEPENDENCY_LIBS ${LMDB_LIBRARIES})
else()
find_package(lmdb CONFIG REQUIRED) # lmdb
list(APPEND Caffe2_DEPENDENCY_LIBS lmdb)
endif()
endif()
if(USE_LEVELDB)
find_package(Snappy CONFIG REQUIRED) # Snappy::snappy
list(APPEND Caffe2_DEPENDENCY_LIBS Snappy::snappy)
find_package(LevelDB) # from cmake/Modules/FindLevelDB.cmake
if(LevelDB_FOUND)
list(APPEND Caffe2_DEPENDENCY_LIBS ${LevelDB_LIBRARIES})
else()
find_package(leveldb CONFIG REQUIRED) # leveldb::leveldb
list(APPEND Caffe2_DEPENDENCY_LIBS leveldb::leveldb)
endif()
endif()
if(USE_QNNPACK)
find_library(QNNPACK_LIB NAME qnnpack REQUIRED)
list(APPEND Caffe2_DEPENDENCY_LIBS ${QNNPACK_LIB})
endif()
if(USE_XNNPACK)
find_library(XNNPACK_LIBRARY NAMES xnnpack XNNPACK REQUIRED) # xnnpack
list(APPEND Caffe2_DEPENDENCY_LIBS ${XNNPACK_LIBRARY})
endif()
if(USE_ZSTD)
find_package(zstd CONFIG REQUIRED) # zstd::libzstd_static
list(APPEND Caffe2_DEPENDENCY_LIBS zstd::libzstd_static)
endif()
if(USE_SYSTEM_ONNX)
find_package(ONNX CONFIG REQUIRED) # onnx onnx_proto onnxifi_loader
find_package(ONNXOptimizer CONFIG REQUIRED) # onnx_optimizer
list(APPEND Caffe2_DEPENDENCY_LIBS onnx onnx_proto onnx_optimizer)
if(ONNX_ML)
add_compile_definitions(ONNX_ML=1)
endif()
endif()
if(USE_CUDA)
set(CMAKE_CUDA_STANDARD 14)
find_package(CUDA 10.1 REQUIRED) # https://cmake.org/cmake/help/latest/module/FindCUDA.html
find_package(CUDNN 8.0 REQUIRED) # CuDNN::CuDNN
cuda_select_nvcc_arch_flags(ARCH_FLAGS 6.0 6.2 7.5)
list(APPEND CUDA_NVCC_FLAGS
${ARCH_FLAGS} # check TORCH_NVCC_FLAGS in this project
-D__CUDA_NO_HALF_OPERATORS__ # see https://github.com/torch/cutorch/issues/797
)
set(CAFFE2_USE_CUDA 1)
set(CAFFE2_USE_CUDNN 1)
set(CAFFE2_USE_NVRTC 0)
set(CAFFE2_USE_TENSORRT 0)
include(cmake/public/cuda.cmake)
list(APPEND Caffe2_DEPENDENCY_LIBS
CuDNN::CuDNN
)
list(APPEND Caffe2_PUBLIC_CUDA_DEPENDENCY_LIBS
caffe2::cufft caffe2::curand caffe2::cublas
caffe2::cudnn-public
# caffe2::cuda caffe2::nvrtc # for CAFFE2_USE_NVRTC
# caffe2::tensorrt # for CAFFE2_USE_TENSORRT
)
endif()
if(USE_NUMA) # Linux package 'libnuma-dev'
find_package(Numa REQUIRED)
include_directories(SYSTEM ${Numa_INCLUDE_DIR})
list(APPEND Caffe2_DEPENDENCY_LIBS ${Numa_LIBRARIES})
endif()
if(USE_GLOO)
find_package(Gloo CONFIG REQUIRED)
list(APPEND Caffe2_DEPENDENCY_LIBS gloo)
endif()
if(USE_VULKAN)
find_package(Vulkan REQUIRED)
list(APPEND Caffe2_DEPENDENCY_LIBS Vulkan::Vulkan)
endif()
if(USE_TENSORPIPE)
find_package(libuv CONFIG REQUIRED)
find_package(Tensorpipe CONFIG REQUIRED) # tensorpipe
list(APPEND Caffe2_DEPENDENCY_LIBS uv_a tensorpipe)
endif()
if(USE_MPI)
find_package(MPI REQUIRED) # APT package: libopenmpi-dev
if(NOT MPI_CXX_FOUND)
message(FATAL_ERROR "Failed to find MPI_CXX")
endif()
include_directories(SYSTEM ${MPI_CXX_INCLUDE_PATH})
list(APPEND Caffe2_DEPENDENCY_LIBS ${MPI_CXX_LIBRARIES})
list(APPEND CMAKE_EXE_LINKER_FLAGS ${MPI_CXX_LINK_FLAGS})
find_program(OMPI_INFO NAMES ompi_info HINTS ${MPI_CXX_LIBRARIES}/../bin)
if(OMPI_INFO)
execute_process(COMMAND ${OMPI_INFO} OUTPUT_VARIABLE _output)
if(_output MATCHES "smcuda")
message(STATUS "Found OpenMPI with CUDA support built.")
else()
message(WARNING "OpenMPI found, but it is not built with CUDA support.")
set(CAFFE2_FORCE_FALLBACK_CUDA_MPI 1)
endif()
endif()
endif()
if(USE_OPENCV)
find_package(OpenCV CONFIG REQUIRED COMPONENTS core highgui imgproc imgcodecs videoio video)
include_directories(SYSTEM ${OpenCV_INCLUDE_DIRS})
list(APPEND Caffe2_DEPENDENCY_LIBS ${OpenCV_LIBS})
if(MSVC AND USE_CUDA)
list(APPEND Caffe2_CUDA_DEPENDENCY_LIBS ${OpenCV_LIBS})
endif()
endif()
if(USE_OPENCL)
find_package(OpenCL REQUIRED)
include_directories(SYSTEM ${OpenCL_INCLUDE_DIRS})
include_directories(${CMAKE_CURRENT_LIST_DIR}/../caffe2/contrib/opencl)
list(APPEND Caffe2_DEPENDENCY_LIBS OpenCL::OpenCL)
endif()