Skip to content
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

Compile using C++17 when using PyTorch 2.1 #3998

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ if(HAVE_GLOO AND ((DEFINED Tensorflow_CXX11 AND NOT Tensorflow_CXX11) OR (DEFINE
endif()

# Gloo for c++17 TF
if(HAVE_GLOO AND (DEFINED Tensorflow_CXX17 AND Tensorflow_CXX17))
if(HAVE_GLOO AND ((DEFINED Tensorflow_CXX17 AND Tensorflow_CXX17) OR (DEFINED Pytorch_CXX17 AND Pytorch_CXX17)))
file(COPY ${PROJECT_SOURCE_DIR}/third_party/gloo/ DESTINATION ${PROJECT_SOURCE_DIR}/third_party/compatible17_gloo)
file(READ ${PROJECT_SOURCE_DIR}/third_party/compatible17_gloo/gloo/CMakeLists.txt GLOO_CMAKE)
string(REPLACE "gloo " "compatible17_gloo " GLOO_CMAKE "${GLOO_CMAKE}")
Expand All @@ -385,7 +385,7 @@ if(HAVE_GLOO AND (DEFINED Tensorflow_CXX17 AND Tensorflow_CXX17))
string(PREPEND GLOO_CMAKE "set(CMAKE_CXX_STANDARD 17)\n")
file(WRITE ${PROJECT_SOURCE_DIR}/third_party/compatible17_gloo/CMakeLists.txt "${GLOO_CMAKE}")
add_subdirectory(third_party/compatible17_gloo)
if (Tensorflow_CXX11)
if (Tensorflow_CXX11 OR Pytorch_CXX11)
target_compile_definitions(compatible17_gloo PRIVATE _GLIBCXX_USE_CXX11_ABI=1)
else()
target_compile_definitions(compatible17_gloo PRIVATE _GLIBCXX_USE_CXX11_ABI=0)
Expand Down
18 changes: 14 additions & 4 deletions horovod/torch/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ if(NOT PYTORCH_FOUND)
return()
endif()

if(Pytorch_VERSION VERSION_GREATER_EQUAL "2.1")
set(CMAKE_CXX_STANDARD 17)
set(Pytorch_CXX17 TRUE)
elseif(Pytorch_VERSION VERSION_GREATER_EQUAL "1.5")
set(CMAKE_CXX_STANDARD 14)
set(Pytorch_CXX17 FALSE)
else()
set(Pytorch_CXX17 FALSE)
endif()

# Append version number into metadata
file(APPEND "${CMAKE_LIBRARY_OUTPUT_DIRECTORY_ROOT}/metadata.json" "\"pytorch\": \"${Pytorch_VERSION}\",\n")

Expand All @@ -39,7 +49,9 @@ execute_process(COMMAND ${PY_EXE} -c "from distutils.sysconfig import get_python
include_directories(SYSTEM ${PYTHON_INCLUDE_PATH})
set(CMAKE_CXX_FLAGS "${Pytorch_COMPILE_FLAGS} ${CMAKE_CXX_FLAGS}")
if(HAVE_GLOO)
if (Pytorch_CXX11)
if (Pytorch_CXX17)
list(APPEND PYTORCH_LINKER_LIBS compatible17_gloo)
elseif (Pytorch_CXX11)
list(APPEND PYTORCH_LINKER_LIBS gloo)
else()
list(APPEND PYTORCH_LINKER_LIBS compatible_gloo)
Expand All @@ -63,9 +75,7 @@ list(APPEND PYTORCH_LINKER_LIBS ${Pytorch_LIBRARIES})
parse_version(${Pytorch_VERSION} VERSION_DEC)
add_definitions(-DPYTORCH_VERSION=${VERSION_DEC} -DTORCH_API_INCLUDE_EXTENSION_H=1)
set(Pytorch_CXX11 ${Pytorch_CXX11} PARENT_SCOPE)
if(NOT Pytorch_VERSION VERSION_LESS "1.5.0")
set(CMAKE_CXX_STANDARD 14)
endif()
set(Pytorch_CXX17 ${Pytorch_CXX17} PARENT_SCOPE)

# PyTorch SOURCES
# Later versions of PyTorch that use ROCm's hipify step will rename files.
Expand Down