-
Notifications
You must be signed in to change notification settings - Fork 9
/
CMakeLists.txt
108 lines (88 loc) · 3.72 KB
/
CMakeLists.txt
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
cmake_minimum_required(VERSION 3.13)
project(MegRay)
cmake_policy(SET CMP0077 NEW)
enable_language(CXX)
include(CMakeDependentOption)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
option(MEGRAY_WITH_NCCL "Enable NCCL Backend" ON)
option(MEGRAY_WITH_UCX "Enable UCX Backend (Not recommend)" OFF)
option(MEGRAY_WITH_SHM "Enable SHM Backend" ON)
option(MEGRAY_WITH_TEST "Enable test for MegRay." OFF)
option(MEGRAY_BUILD_NCCL_WITH_EXTERNAL_SCRIPT "Build nccl with external script" ON)
set(MEGRAY_LOG_LEVEL 2 CACHE STRING "MegRay log level")
set(MEGRAY_CUDA_ARCHITECTURES "" CACHE STRING "MegRay CUDA Architectures")
set(MEGRAY_CUDA_GENCODE "" CACHE STRING "Overwrite -gencode specifications for CUDA")
# if RCCL_PATH is specified, force open MEGRAY_WITH_RCCL
cmake_dependent_option(MEGRAY_WITH_RCCL "Build with rccl" OFF "NOT DEFINED RCCL_PATH;NOT DEFINED ENV{RCCL_PATH}" ON)
if(MEGRAY_WITH_NCCL OR MEGRAY_WITH_UCX OR MEGRAY_WITH_SHM)
set(MEGRAY_WITH_CUDA ON)
else()
set(MEGRAY_WITH_CUDA OFF)
endif()
set(MEGRAY_WITH_HIP ${MEGRAY_WITH_RCCL})
configure_file("${PROJECT_SOURCE_DIR}/include/megray/config.h.in" "${PROJECT_BINARY_DIR}/include/megray/config.h")
if(${MEGRAY_WITH_CUDA} AND ${MEGRAY_WITH_HIP})
message(FATAL_ERROR "Coexistence of CUDA and HIP is not supported yet")
endif()
if(${MEGRAY_WITH_CUDA})
find_package(CUDA)
enable_language(CUDA)
get_filename_component(CUDA_HOME ${CMAKE_CUDA_COMPILER} DIRECTORY)
get_filename_component(CUDA_HOME ${CUDA_HOME} DIRECTORY)
if ("${MEGRAY_CUDA_ARCHITECTURES}" STREQUAL "" AND "${MEGRAY_CUDA_GENCODE}" STREQUAL "")
if(${CMAKE_CUDA_COMPILER_VERSION} VERSION_GREATER_EQUAL "11.1.0")
set(MEGRAY_CUDA_ARCHITECTURES_DEFAULT 61-real 70-real 75-real 80-real 86)
elseif(${CMAKE_CUDA_COMPILER_VERSION} VERSION_GREATER_EQUAL "11.0.0")
set(MEGRAY_CUDA_ARCHITECTURES_DEFAULT 61-real 70-real 75-real 80)
elseif(${CMAKE_CUDA_COMPILER_VERSION} VERSION_GREATER_EQUAL "10.0.0")
set(MEGRAY_CUDA_ARCHITECTURES_DEFAULT 52-real 60-real 61-real 70-real 75)
elseif(${CMAKE_CUDA_COMPILER_VERSION} VERSION_GREATER_EQUAL "9.0.0")
set(MEGRAY_CUDA_ARCHITECTURES_DEFAULT 52-real 60-real 61-real 70)
else()
set(MEGRAY_CUDA_ARCHITECTURES_DEFAULT 35-real 52-real 60-real 61)
endif()
set(MEGRAY_CUDA_ARCHITECTURES ${MEGRAY_CUDA_ARCHITECTURES_DEFAULT} CACHE STRING "" FORCE)
else()
set(MEGRAY_CUDA_ARCHITECTURES OFF CACHE STRING "" FORCE)
endif()
endif()
if(${MEGRAY_WITH_HIP})
if(NOT DEFINED HIP_PATH)
set(DEFAULT_HIP_PATH "/opt/rocm/hip")
if (DEFINED $ENV{HIP_PATH})
set(DEFAULT_HIP_PATH $ENV{HIP_PATH})
endif()
set(HIP_PATH ${DEFAULT_HIP_PATH} CACHE STRING "")
endif()
list(APPEND CMAKE_PREFIX_PATH
${HIP_PATH}/../
${HIP_PATH}
${HIP_PATH}/../hcc)
find_package(HIP REQUIRED)
execute_process(
COMMAND ${HIP_HIPCONFIG_EXECUTABLE} "--cpp_config"
OUTPUT_VARIABLE HIP_COMPILE_OPTIONS
)
execute_process(
COMMAND ${HIP_HIPCONFIG_EXECUTABLE} "--compiler"
OUTPUT_VARIABLE HIP_COMPILER
)
separate_arguments(HIP_COMPILE_OPTIONS)
if(${HIP_COMPILER} STREQUAL "hcc")
set(HIP_LIBRARY hip_hcc)
elseif(${HIP_COMPILER} STREQUAL "clang")
set(HIP_LIBRARY amdhip64)
else()
message(FATAL_ERROR "Unknown HIP compiler ${HIP_COMPILER}")
endif()
endif()
add_subdirectory(src)
if(${MEGRAY_WITH_TEST})
enable_testing()
include(GoogleTest)
add_subdirectory(test)
endif()