mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-07 12:21:27 +01:00
* Re-apply PyTorch pthreadpool changes Summary: This re-applies D21232894 (b9d3869df3) and D22162524, plus updates jni_deps in a few places to avoid breaking host JNI tests. Test Plan: `buck test @//fbandroid/mode/server //fbandroid/instrumentation_tests/com/facebook/caffe2:host-test` Reviewed By: xcheng16 Differential Revision: D22199952 fbshipit-source-id: df13eef39c01738637ae8cf7f581d6ccc88d37d5 * Enable XNNPACK ops on iOS and macOS. Test Plan: buck run aibench:run_bench -- -b aibench/specifications/models/pytorch/pytext/pytext_mobile_inference.json --platform ios --framework pytorch --remote --devices D221 (9788a74da8)AP-12.0.1 Reviewed By: xta0 Differential Revision: D21886736 fbshipit-source-id: ac482619dc1b41a110a3c4c79cc0339e5555edeb * Respect user set thread count. (#40707) Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/40707 Test Plan: Imported from OSS Differential Revision: D22318197 Pulled By: AshkanAliabadi fbshipit-source-id: f11b7302a6e91d11d750df100d2a3d8d96b5d1db * Fix and reenable threaded QNNPACK linear (#40587) Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/40587 Previously, this was causing divide-by-zero only in the multithreaded empty-batch case, while calculating tiling parameters for the threads. In my opinion, the bug here is using a value that is allowed to be zero (batch size) for an argument that should not be zero (tile size), so I fixed the bug by bailing out right before the call to pthreadpool_compute_4d_tiled. Test Plan: TestQuantizedOps.test_empty_batch Differential Revision: D22264414 Pulled By: dreiss fbshipit-source-id: 9446d5231ff65ef19003686f3989e62f04cf18c9 * Fix batch size zero for QNNPACK linear_dynamic (#40588) Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/40588 Two bugs were preventing this from working. One was a divide by zero when multithreading was enabled, fixed similarly to the fix for static quantized linear in the previous commit. The other was computation of min and max to determine qparams. FBGEMM uses [0,0] for [min,max] of empty input, do the same. Test Plan: Added a unit test. Differential Revision: D22264415 Pulled By: dreiss fbshipit-source-id: 6ca9cf48107dd998ef4834e5540279a8826bc754 Co-authored-by: David Reiss <dreiss@fb.com>
136 lines
4.6 KiB
CMake
136 lines
4.6 KiB
CMake
# FindTorch
|
|
# -------
|
|
#
|
|
# Finds the Torch library
|
|
#
|
|
# This will define the following variables:
|
|
#
|
|
# TORCH_FOUND -- True if the system has the Torch library
|
|
# TORCH_INCLUDE_DIRS -- The include directories for torch
|
|
# TORCH_LIBRARIES -- Libraries to link against
|
|
# TORCH_CXX_FLAGS -- Additional (required) compiler flags
|
|
#
|
|
# and the following imported targets:
|
|
#
|
|
# torch
|
|
|
|
include(FindPackageHandleStandardArgs)
|
|
|
|
if(DEFINED ENV{TORCH_INSTALL_PREFIX})
|
|
set(TORCH_INSTALL_PREFIX $ENV{TORCH_INSTALL_PREFIX})
|
|
else()
|
|
# Assume we are in <install-prefix>/share/cmake/Torch/TorchConfig.cmake
|
|
get_filename_component(CMAKE_CURRENT_LIST_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
|
|
get_filename_component(TORCH_INSTALL_PREFIX "${CMAKE_CURRENT_LIST_DIR}/../../../" ABSOLUTE)
|
|
endif()
|
|
|
|
# Include directories.
|
|
if(EXISTS "${TORCH_INSTALL_PREFIX}/include")
|
|
set(TORCH_INCLUDE_DIRS
|
|
${TORCH_INSTALL_PREFIX}/include
|
|
${TORCH_INSTALL_PREFIX}/include/torch/csrc/api/include)
|
|
else()
|
|
set(TORCH_INCLUDE_DIRS
|
|
${TORCH_INSTALL_PREFIX}/include
|
|
${TORCH_INSTALL_PREFIX}/include/torch/csrc/api/include)
|
|
endif()
|
|
|
|
# Library dependencies.
|
|
if(@BUILD_SHARED_LIBS@)
|
|
find_package(Caffe2 REQUIRED PATHS ${CMAKE_CURRENT_LIST_DIR}/../Caffe2)
|
|
set(TORCH_LIBRARIES torch ${Caffe2_MAIN_LIBS})
|
|
else()
|
|
add_library(torch STATIC IMPORTED) # set imported_location at the bottom
|
|
set(TORCH_LIBRARIES torch)
|
|
endif()
|
|
|
|
find_library(C10_LIBRARY c10 PATHS "${TORCH_INSTALL_PREFIX}/lib")
|
|
list(APPEND TORCH_LIBRARIES ${C10_LIBRARY})
|
|
|
|
# We need manually add dependent libraries when they are not linked into the
|
|
# shared library.
|
|
# TODO: this list might be incomplete.
|
|
if(NOT @BUILD_SHARED_LIBS@)
|
|
find_library(TORCH_CPU_LIBRARY torch_cpu PATHS "${TORCH_INSTALL_PREFIX}/lib")
|
|
list(APPEND TORCH_LIBRARIES ${TORCH_CPU_LIBRARY})
|
|
|
|
if(@USE_NNPACK@)
|
|
find_library(NNPACK_LIBRARY nnpack PATHS "${TORCH_INSTALL_PREFIX}/lib")
|
|
list(APPEND TORCH_LIBRARIES ${NNPACK_LIBRARY})
|
|
endif()
|
|
|
|
if(@USE_PYTORCH_QNNPACK@)
|
|
find_library(PYTORCH_QNNPACK_LIBRARY pytorch_qnnpack PATHS "${TORCH_INSTALL_PREFIX}/lib")
|
|
list(APPEND TORCH_LIBRARIES ${PYTORCH_QNNPACK_LIBRARY})
|
|
endif()
|
|
|
|
if(@USE_XNNPACK@)
|
|
find_library(XNNPACK_LIBRARY XNNPACK PATHS "${TORCH_INSTALL_PREFIX}/lib")
|
|
list(APPEND TORCH_LIBRARIES ${XNNPACK_LIBRARY})
|
|
endif()
|
|
|
|
if(NOT @USE_INTERNAL_PTHREADPOOL_IMPL@)
|
|
find_library(PTHREADPOOL_LIBRARY pthreadpool PATHS "${TORCH_INSTALL_PREFIX}/lib")
|
|
list(APPEND TORCH_LIBRARIES ${PTHREADPOOL_LIBRARY})
|
|
endif()
|
|
|
|
if(@INTERN_USE_EIGEN_BLAS@)
|
|
find_library(EIGEN_BLAS_LIBRARY eigen_blas PATHS "${TORCH_INSTALL_PREFIX}/lib")
|
|
list(APPEND TORCH_LIBRARIES ${EIGEN_BLAS_LIBRARY})
|
|
endif()
|
|
|
|
find_library(CPUINFO_LIBRARY cpuinfo PATHS "${TORCH_INSTALL_PREFIX}/lib")
|
|
list(APPEND TORCH_LIBRARIES ${CPUINFO_LIBRARY})
|
|
|
|
find_library(CLOG_LIBRARY clog PATHS "${TORCH_INSTALL_PREFIX}/lib")
|
|
list(APPEND TORCH_LIBRARIES ${CLOG_LIBRARY})
|
|
endif()
|
|
|
|
if(@USE_CUDA@)
|
|
if(MSVC)
|
|
set(NVTOOLEXT_HOME "C:/Program Files/NVIDIA Corporation/NvToolsExt")
|
|
if($ENV{NVTOOLEXT_HOME})
|
|
set(NVTOOLEXT_HOME $ENV{NVTOOLEXT_HOME})
|
|
endif()
|
|
set(TORCH_CUDA_LIBRARIES
|
|
${NVTOOLEXT_HOME}/lib/x64/nvToolsExt64_1.lib
|
|
${CUDA_LIBRARIES})
|
|
list(APPEND TORCH_INCLUDE_DIRS ${NVTOOLEXT_HOME}/include)
|
|
find_library(CAFFE2_NVRTC_LIBRARY caffe2_nvrtc PATHS "${TORCH_INSTALL_PREFIX}/lib")
|
|
list(APPEND TORCH_CUDA_LIBRARIES ${CAFFE2_NVRTC_LIBRARY})
|
|
elseif(APPLE)
|
|
set(TORCH_CUDA_LIBRARIES
|
|
${CUDA_TOOLKIT_ROOT_DIR}/lib/libcudart.dylib
|
|
${CUDA_TOOLKIT_ROOT_DIR}/lib/libnvrtc.dylib
|
|
${CUDA_TOOLKIT_ROOT_DIR}/lib/libnvToolsExt.dylib
|
|
${CUDA_LIBRARIES})
|
|
else()
|
|
find_library(LIBNVTOOLSEXT libnvToolsExt.so PATHS ${CUDA_TOOLKIT_ROOT_DIR}/lib64/)
|
|
set(TORCH_CUDA_LIBRARIES
|
|
${CUDA_CUDA_LIB}
|
|
${CUDA_NVRTC_LIB}
|
|
${LIBNVTOOLSEXT}
|
|
${CUDA_LIBRARIES})
|
|
endif()
|
|
find_library(C10_CUDA_LIBRARY c10_cuda PATHS "${TORCH_INSTALL_PREFIX}/lib")
|
|
list(APPEND TORCH_CUDA_LIBRARIES ${C10_CUDA_LIBRARY})
|
|
list(APPEND TORCH_LIBRARIES ${TORCH_CUDA_LIBRARIES})
|
|
endif()
|
|
|
|
# When we build libtorch with the old GCC ABI, dependent libraries must too.
|
|
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
|
|
set(TORCH_CXX_FLAGS "-D_GLIBCXX_USE_CXX11_ABI=@GLIBCXX_USE_CXX11_ABI@")
|
|
endif()
|
|
|
|
find_library(TORCH_LIBRARY torch PATHS "${TORCH_INSTALL_PREFIX}/lib")
|
|
set_target_properties(torch PROPERTIES
|
|
IMPORTED_LOCATION "${TORCH_LIBRARY}"
|
|
INTERFACE_INCLUDE_DIRECTORIES "${TORCH_INCLUDE_DIRS}"
|
|
CXX_STANDARD 14
|
|
)
|
|
if(TORCH_CXX_FLAGS)
|
|
set_property(TARGET torch PROPERTY INTERFACE_COMPILE_OPTIONS "${TORCH_CXX_FLAGS}")
|
|
endif()
|
|
|
|
find_package_handle_standard_args(Torch DEFAULT_MSG TORCH_LIBRARY TORCH_INCLUDE_DIRS)
|