Skip to content

Fixing build when CUDA enabled torch is installed #1814

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,16 @@ endif()
option(BUILD_TORCHTEXT_PYTHON_EXTENSION "Build Python extension" OFF)

set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${CMAKE_CURRENT_SOURCE_DIR}/cmake")
set(TORCH_INSTALL_PREFIX "${CMAKE_PREFIX_PATH}/../.." CACHE STRING "Install path for torch")

find_package(Torch REQUIRED)
find_library(TORCH_C10_LIBRARY c10 PATHS "${TORCH_INSTALL_PREFIX}/lib")
find_library(TORCH_LIBRARY torch PATHS "${TORCH_INSTALL_PREFIX}/lib")
find_library(TORCH_CPU_LIBRARY torch_cpu PATHS "${TORCH_INSTALL_PREFIX}/lib")

if(MSVC)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()


# TORCH_CXX_FLAGS contains the same -D_GLIBCXX_USE_CXX11_ABI value as PyTorch
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall ${TORCH_CXX_FLAGS}")

Expand Down
1 change: 1 addition & 0 deletions tools/setup_helpers/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def build_extension(self, ext):
f"-DCMAKE_INSTALL_PREFIX={extdir}",
"-DCMAKE_VERBOSE_MAKEFILE=ON",
f"-DPython_INCLUDE_DIR={distutils.sysconfig.get_python_inc()}",
f"-DTORCH_INSTALL_PREFIX:STRING={os.path.dirname(torch.__file__)}",
"-DBUILD_TORCHTEXT_PYTHON_EXTENSION:BOOL=ON",
"-DRE2_BUILD_TESTING:BOOL=OFF",
"-DBUILD_TESTING:BOOL=OFF",
Expand Down
8 changes: 7 additions & 1 deletion torchtext/csrc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,15 @@ set(
$<TARGET_PROPERTY:re2,INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:double-conversion,INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:utf8proc,INCLUDE_DIRECTORIES>
${TORCH_INSTALL_PREFIX}/include
${TORCH_INSTALL_PREFIX}/include/torch/csrc/api/include
)

set(
LIBTORCHTEXT_LINK_LIBRARIES
torch
${TORCH_C10_LIBRARY}
${TORCH_LIBRARY}
${TORCH_CPU_LIBRARY}
re2
double-conversion
sentencepiece
Expand Down Expand Up @@ -118,6 +122,8 @@ if (BUILD_TORCHTEXT_PYTHON_EXTENSION)
$<TARGET_PROPERTY:re2,INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:double-conversion,INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:utf8proc,INCLUDE_DIRECTORIES>
${TORCH_INSTALL_PREFIX}/include
${TORCH_INSTALL_PREFIX}/include/torch/csrc/api/include
)

set(
Expand Down