Skip to content

Commit 120e3c3

Browse files
committed
ADD ishmem support
1 parent f72a2ac commit 120e3c3

File tree

6 files changed

+836
-0
lines changed

6 files changed

+836
-0
lines changed

CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,16 @@ if(USE_XCCL)
5656
caffe2_update_option(USE_C10D_XCCL OFF)
5757
update_caffe2_macros_file()
5858
endif()
59+
if(USE_ISHMEM)
60+
include(${TORCH_XPU_OPS_ROOT}/cmake/ISHMEM.cmake)
61+
if(NOT PYTORCH_FOUND_ISHMEM)
62+
message(WARNING "ISHMEM not found, disabling ISHMEM support")
63+
caffe2_update_option(USE_ISHMEM OFF)
64+
update_caffe2_macros_file()
65+
else()
66+
message(STATUS "ISHMEM support enabled")
67+
endif()
68+
endif()
5969
endif()
6070

6171
set(USE_SYCLTLA ON)

cmake/ISHMEM.cmake

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
if(NOT __ISHMEM_INCLUDED)
2+
set(__ISHMEM_INCLUDED TRUE)
3+
4+
# ISHMEM_ROOT, ISHMEM_LIBRARY_DIR, ISHMEM_INCLUDE_DIR are handled by FindISHMEM.cmake.
5+
find_package(ISHMEM REQUIRED)
6+
if(NOT ISHMEM_FOUND)
7+
set(PYTORCH_FOUND_ISHMEM FALSE)
8+
message(WARNING "${ISHMEM_NOT_FOUND_MESSAGE}")
9+
return()
10+
endif()
11+
12+
set(PYTORCH_FOUND_ISHMEM TRUE)
13+
add_library(torch::ishmem INTERFACE IMPORTED)
14+
set_property(
15+
TARGET torch::ishmem PROPERTY INTERFACE_INCLUDE_DIRECTORIES
16+
${ISHMEM_INCLUDE_DIR})
17+
set_property(
18+
TARGET torch::ishmem PROPERTY INTERFACE_LINK_LIBRARIES
19+
${ISHMEM_LIBRARY})
20+
21+
message(STATUS "Found Intel SHMEM: ${ISHMEM_ROOT}")
22+
message(STATUS " ISHMEM include dir: ${ISHMEM_INCLUDE_DIR}")
23+
message(STATUS " ISHMEM library: ${ISHMEM_LIBRARY}")
24+
endif()

cmake/Modules/FindISHMEM.cmake

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# This will define the following variables:
2+
# ISHMEM_FOUND : True if the system has the ISHMEM library.
3+
# ISHMEM_INCLUDE_DIR : Include directories needed to use ISHMEM.
4+
# ISHMEM_LIBRARY_DIR : The path to the ISHMEM library.
5+
# ISHMEM_LIBRARY : ISHMEM library fullname.
6+
7+
include(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake)
8+
9+
if(NOT CMAKE_SYSTEM_NAME MATCHES "Linux")
10+
set(ISHMEM_FOUND False)
11+
set(ISHMEM_NOT_FOUND_MESSAGE "Intel SHMEM library is only supported on Linux!")
12+
return()
13+
endif()
14+
15+
set(ISHMEM_ROOT $ENV{ISHMEM_ROOT})
16+
17+
if(NOT ISHMEM_ROOT)
18+
set(ISHMEM_FOUND False)
19+
set(ISHMEM_NOT_FOUND_MESSAGE "ISHMEM_ROOT environment variable not set. Please set it to your ISHMEM installation directory.")
20+
return()
21+
endif()
22+
23+
# Find include path from binary.
24+
find_path(
25+
ISHMEM_INCLUDE_DIR
26+
NAMES ishmem.h
27+
HINTS ${ISHMEM_ROOT}/include
28+
NO_DEFAULT_PATH
29+
)
30+
31+
# Find library directory from binary.
32+
find_path(
33+
ISHMEM_LIBRARY_DIR
34+
NAMES libishmem.a
35+
HINTS ${ISHMEM_ROOT}/lib
36+
NO_DEFAULT_PATH
37+
)
38+
39+
# Find ISHMEM library fullname (static library).
40+
find_library(
41+
ISHMEM_LIBRARY
42+
NAMES ishmem
43+
HINTS ${ISHMEM_LIBRARY_DIR}
44+
NO_DEFAULT_PATH
45+
)
46+
47+
if((NOT ISHMEM_INCLUDE_DIR) OR (NOT ISHMEM_LIBRARY_DIR) OR (NOT ISHMEM_LIBRARY))
48+
set(ISHMEM_FOUND False)
49+
set(ISHMEM_NOT_FOUND_MESSAGE "Intel SHMEM library not found! Please set ISHMEM_ROOT environment variable.")
50+
return()
51+
endif()
52+
53+
SET(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH}
54+
"${ISHMEM_INCLUDE_DIR}")
55+
SET(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH}
56+
"${ISHMEM_LIBRARY_DIR}")
57+
58+
find_package_handle_standard_args(
59+
ISHMEM
60+
FOUND_VAR ISHMEM_FOUND
61+
REQUIRED_VARS ISHMEM_INCLUDE_DIR ISHMEM_LIBRARY_DIR ISHMEM_LIBRARY
62+
REASON_FAILURE_MESSAGE "${ISHMEM_NOT_FOUND_MESSAGE}"
63+
)
64+
65+
mark_as_advanced(ISHMEM_INCLUDE_DIR ISHMEM_LIBRARY_DIR ISHMEM_LIBRARY)

src/BuildOnLinux.cmake

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ macro(setup_common_libraries)
1717
target_compile_definitions(torch_xpu_ops PRIVATE USE_C10D_XCCL)
1818
target_link_libraries(torch_xpu_ops PUBLIC torch::xccl)
1919
target_link_libraries(torch_xpu_ops PUBLIC fmt::fmt-header-only)
20+
if(USE_ISHMEM AND PYTORCH_FOUND_ISHMEM)
21+
target_link_libraries(torch_xpu_ops PUBLIC torch::ishmem)
22+
endif()
2023
endif()
2124

2225
if(USE_SYCLTLA)
@@ -50,6 +53,9 @@ else()
5053
target_compile_definitions(torch_xpu_ops PRIVATE USE_C10D_XCCL)
5154
target_link_libraries(torch_xpu_ops PUBLIC torch::xccl)
5255
target_link_libraries(torch_xpu_ops PUBLIC fmt::fmt-header-only)
56+
if(USE_ISHMEM AND PYTORCH_FOUND_ISHMEM)
57+
target_link_libraries(torch_xpu_ops PUBLIC torch::ishmem)
58+
endif()
5359
endif()
5460

5561
if(USE_SYCLTLA)

0 commit comments

Comments
 (0)