-
Notifications
You must be signed in to change notification settings - Fork 234
/
Copy pathlegion.cmake
161 lines (152 loc) · 8.2 KB
/
legion.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
if(FF_USE_EXTERNAL_LEGION)
if(NOT "${LEGION_ROOT}" STREQUAL "")
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} ${LEGION_ROOT}/share/Legion/cmake)
endif()
find_package(Legion REQUIRED)
get_target_property(LEGION_INCLUDE_DIRS Legion::RealmRuntime INTERFACE_INCLUDE_DIRECTORIES)
string(REGEX REPLACE "/include" "" LEGION_ROOT_TMP ${LEGION_INCLUDE_DIRS})
if("${LEGION_ROOT}" STREQUAL "")
set(LEGION_ROOT ${LEGION_ROOT_TMP})
else()
if(NOT "${LEGION_ROOT}" STREQUAL ${LEGION_ROOT_TMP})
message( FATAL_ERROR "LEGION_ROOT is not set correctly ${LEGION_ROOT} ${LEGION_ROOT_TMP}")
endif()
endif()
message(STATUS "Use external Legion cmake found: ${LEGION_ROOT_TMP}")
message(STATUS "Use external Legion: ${LEGION_ROOT}")
set(LEGION_LIBRARY Legion::Legion)
else()
# Check availability of precompiled Legion library
set(LEGION_URL "")
if((FF_USE_PREBUILT_LEGION OR FF_USE_ALL_PREBUILT_LIBRARIES) AND CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "x86_64" AND
FF_USE_PYTHON AND NOT "${FF_LEGION_NETWORKS}" STREQUAL "gasnet" AND FF_MAX_DIM EQUAL 5)
# For now, reusing pre-compiled Legion library only works when the Python library on the target machine
# is stored at the path `/opt/conda/lib/libpython3.10.so`. Here, we check if this is the case.
find_package(PythonInterp)
find_package(PythonLibs)
if(PYTHON_LIBRARIES STREQUAL "/opt/conda/lib/libpython3.10.so")
if(LINUX_VERSION MATCHES "20.04")
if (FF_GPU_BACKEND STREQUAL "cuda")
if (CUDA_VERSION VERSION_EQUAL "11.0")
set(LEGION_URL "https://github.com/flexflow/flexflow-third-party/releases/latest/download/legion_ubuntu-20.04_11.0.3.tar.gz")
elseif(CUDA_VERSION VERSION_EQUAL "11.1")
set(LEGION_URL "https://github.com/flexflow/flexflow-third-party/releases/latest/download/legion_ubuntu-20.04_11.1.1.tar.gz")
elseif(CUDA_VERSION VERSION_EQUAL "11.2")
set(LEGION_URL "https://github.com/flexflow/flexflow-third-party/releases/latest/download/legion_ubuntu-20.04_11.2.2.tar.gz")
elseif(CUDA_VERSION VERSION_EQUAL "11.3")
set(LEGION_URL "https://github.com/flexflow/flexflow-third-party/releases/latest/download/legion_ubuntu-20.04_11.3.1.tar.gz")
elseif(CUDA_VERSION VERSION_EQUAL "11.4")
set(LEGION_URL "https://github.com/flexflow/flexflow-third-party/releases/latest/download/legion_ubuntu-20.04_11.4.3.tar.gz")
elseif(CUDA_VERSION VERSION_EQUAL "11.5")
set(LEGION_URL "https://github.com/flexflow/flexflow-third-party/releases/latest/download/legion_ubuntu-20.04_11.5.2.tar.gz")
elseif(CUDA_VERSION VERSION_EQUAL "11.6")
set(LEGION_URL "https://github.com/flexflow/flexflow-third-party/releases/latest/download/legion_ubuntu-20.04_11.6.2.tar.gz")
elseif(CUDA_VERSION VERSION_EQUAL "11.7")
set(LEGION_URL "https://github.com/flexflow/flexflow-third-party/releases/latest/download/legion_ubuntu-20.04_11.7.0.tar.gz")
endif()
elseif(FF_GPU_BACKEND STREQUAL "hip_rocm")
set(LEGION_URL "https://github.com/flexflow/flexflow-third-party/releases/latest/download/legion_ubuntu-20.04_hip_rocm.tar.gz")
endif()
elseif(LINUX_VERSION MATCHES "18.04")
if (FF_GPU_BACKEND STREQUAL "cuda")
if (CUDA_VERSION VERSION_EQUAL "10.1")
set(LEGION_URL "https://github.com/flexflow/flexflow-third-party/releases/latest/download/legion_ubuntu-18.04_10.1.243.tar.gz")
elseif (CUDA_VERSION VERSION_EQUAL "10.2")
set(LEGION_URL "https://github.com/flexflow/flexflow-third-party/releases/latest/download/legion_ubuntu-18.04_10.2.89.tar.gz")
elseif (CUDA_VERSION VERSION_EQUAL "11.0")
set(LEGION_URL "https://github.com/flexflow/flexflow-third-party/releases/latest/download/legion_ubuntu-18.04_11.0.3.tar.gz")
elseif(CUDA_VERSION VERSION_EQUAL "11.1")
set(LEGION_URL "https://github.com/flexflow/flexflow-third-party/releases/latest/download/legion_ubuntu-18.04_11.1.1.tar.gz")
elseif(CUDA_VERSION VERSION_EQUAL "11.2")
set(LEGION_URL "https://github.com/flexflow/flexflow-third-party/releases/latest/download/legion_ubuntu-18.04_11.2.2.tar.gz")
elseif(CUDA_VERSION VERSION_EQUAL "11.3")
set(LEGION_URL "https://github.com/flexflow/flexflow-third-party/releases/latest/download/legion_ubuntu-18.04_11.3.1.tar.gz")
elseif(CUDA_VERSION VERSION_EQUAL "11.4")
set(LEGION_URL "https://github.com/flexflow/flexflow-third-party/releases/latest/download/legion_ubuntu-18.04_11.4.3.tar.gz")
elseif(CUDA_VERSION VERSION_EQUAL "11.5")
set(LEGION_URL "https://github.com/flexflow/flexflow-third-party/releases/latest/download/legion_ubuntu-18.04_11.5.2.tar.gz")
elseif(CUDA_VERSION VERSION_EQUAL "11.6")
set(LEGION_URL "https://github.com/flexflow/flexflow-third-party/releases/latest/download/legion_ubuntu-18.04_11.6.2.tar.gz")
elseif(CUDA_VERSION VERSION_EQUAL "11.7")
set(LEGION_URL "https://github.com/flexflow/flexflow-third-party/releases/latest/download/legion_ubuntu-18.04_11.7.0.tar.gz")
endif()
endif()
endif()
endif()
endif()
if(LEGION_URL)
# Download and import pre-compiled Legion library
message(STATUS "Using pre-compiled Legion library")
message(STATUS "LEGION_URL: ${LEGION_URL}")
set(LEGION_NAME legion)
set(LEGION_LIBRARY legion)
set(REALM_LIBRARY realm)
include(FetchContent)
FetchContent_Declare(${LEGION_NAME}
URL ${LEGION_URL}
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
)
FetchContent_GetProperties(${LEGION_NAME})
if(NOT ${LEGION_NAME}_POPULATED)
FetchContent_Populate(${LEGION_NAME})
endif()
set(LEGION_FOLDER_PATH ${${LEGION_NAME}_SOURCE_DIR}/export/${LEGION_NAME})
SET(LEGION_INCLUDE_DIR ${LEGION_FOLDER_PATH}/include)
SET(LEGION_DEF_DIR ${LEGION_INCLUDE_DIR})
SET(LEGION_BIN_DIR ${LEGION_FOLDER_PATH}/bin/)
SET(LEGION_LIB_DIR ${LEGION_FOLDER_PATH}/lib)
SET(LEGION_SHARE_DIR ${LEGION_FOLDER_PATH}/share/)
message(STATUS "Legion library path: ${LEGION_FOLDER_PATH}")
add_library(${LEGION_LIBRARY} SHARED IMPORTED)
add_library(${REALM_LIBRARY} SHARED IMPORTED)
set_target_properties(${LEGION_LIBRARY} PROPERTIES IMPORTED_LOCATION ${LEGION_LIB_DIR}/liblegion${LIBEXT})
set_target_properties(${REALM_LIBRARY} PROPERTIES IMPORTED_LOCATION ${LEGION_LIB_DIR}/librealm${LIBEXT})
list(APPEND FLEXFLOW_INCLUDE_DIRS
${LEGION_INCLUDE_DIR}
${LEGION_INCLUDE_DIR}/hip_cuda_compat
${LEGION_INCLUDE_DIR}/legion
${LEGION_INCLUDE_DIR}/mappers
${LEGION_INCLUDE_DIR}/mathtypes
${LEGION_INCLUDE_DIR}/realm
)
install(DIRECTORY ${LEGION_SHARE_DIR} DESTINATION share)
install(DIRECTORY ${LEGION_BIN_DIR} DESTINATION bin)
install(DIRECTORY ${LEGION_LIB_DIR}/ DESTINATION lib)
else()
# Build Legion from source
message(STATUS "Building Legion from source")
if(FF_USE_PYTHON)
set(Legion_USE_Python ON CACHE BOOL "enable Legion_USE_Python")
endif()
if("${FF_LEGION_NETWORKS}" STREQUAL "gasnet")
set(Legion_EMBED_GASNet ON CACHE BOOL "Use embed GASNet")
set(Legion_EMBED_GASNet_VERSION "GASNet-2022.3.0" CACHE STRING "GASNet version")
set(Legion_NETWORKS "gasnetex" CACHE STRING "GASNet conduit")
set(GASNet_CONDUIT ${FF_GASNET_CONDUIT})
endif()
message(STATUS "GASNET ROOT: $ENV{GASNet_ROOT_DIR}")
set(Legion_MAX_DIM ${FF_MAX_DIM} CACHE STRING "Maximum number of dimensions")
if ((FF_LEGION_NETWORKS STREQUAL "gasnet" AND FF_GASNET_CONDUIT STREQUAL "ucx") OR FF_LEGION_NETWORKS STREQUAL "ucx")
include(ucx)
else()
message(STATUS "FF_GASNET_CONDUIT: ${FF_GASNET_CONDUIT}")
endif()
if (FF_GPU_BACKEND STREQUAL "cuda")
set(Legion_USE_CUDA ON CACHE BOOL "enable Legion_USE_CUDA" FORCE)
set(Legion_CUDA_ARCH ${FF_CUDA_ARCH} CACHE STRING "Legion CUDA ARCH" FORCE)
elseif (FF_GPU_BACKEND STREQUAL "hip_cuda" OR FF_GPU_BACKEND STREQUAL "hip_rocm")
set(Legion_USE_HIP ON CACHE BOOL "enable Legion_USE_HIP" FORCE)
if (FF_GPU_BACKEND STREQUAL "hip_cuda")
set(Legion_HIP_TARGET "CUDA" CACHE STRING "Legion_HIP_TARGET CUDA" FORCE)
elseif(FF_GPU_BACKEND STREQUAL "hip_rocm")
set(Legion_HIP_TARGET "ROCM" CACHE STRING "Legion HIP_TARGET ROCM" FORCE)
endif()
endif()
add_subdirectory(deps/legion)
set(LEGION_LIBRARY Legion)
set(LEGION_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/deps/legion/runtime)
set(LEGION_DEF_DIR ${CMAKE_BINARY_DIR}/deps/legion/runtime)
endif()
endif()
alias_library(legion "${LEGION_LIBRARY}")