Repository navigation
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
199 lines (178 loc) · 8.22 KB
/
Copy pathCMakeLists.txt
File metadata and controls
199 lines (178 loc) · 8.22 KB
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
cmake_minimum_required(VERSION 3.19) # 3.19+ for string(JSON ...), used to read backbones.json
project(boso CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
option(BOSO_BUILD_DEMO "Build the boso_demo example executable" ON)
set(BOSO_ALPAKA_BACKEND "cpu" CACHE STRING "Alpaka backend: cpu, cuda, hip")
set_property(CACHE BOSO_ALPAKA_BACKEND PROPERTY STRINGS cpu cuda hip)
set(BOSO_BACKBONES_JSON "${CMAKE_CURRENT_SOURCE_DIR}/tutorials/backbones.json" CACHE FILEPATH
"JSON file listing SOFIE-generated backbone Sessions to build a boso_<name> binary for")
string(TOLOWER "${BOSO_ALPAKA_BACKEND}" _boso_backend)
include(FetchContent)
# --- alpaka --------------------------------------------------------------
find_package(alpaka QUIET)
if (NOT alpaka_FOUND)
message(STATUS "boso: alpaka not found via find_package(); fetching it")
FetchContent_Declare(
alpaka
GIT_REPOSITORY https://github.com/alpaka-group/alpaka
GIT_TAG 2fa91a34ed11b2076e474c5507d920e85cf9b79d
)
FetchContent_MakeAvailable(alpaka)
else()
message(STATUS "boso: using system alpaka (${alpaka_DIR})")
endif()
# --- sofieBLAS -------------------------------------------------------------
# Header-only; look for a sibling checkout first (this repo is normally
# cloned next to SOFIE and sofieBLAS), then fall
# back to FetchContent, matching SOFIE/test/CMakeLists.txt's own fallback.
find_path(
SOFIEBLAS_INCLUDE_DIR
NAMES sofieBLAS/sofieBLAS.hpp
PATHS
"${CMAKE_CURRENT_SOURCE_DIR}/../sofieBLAS/include"
"${CMAKE_CURRENT_SOURCE_DIR}/../../sofieBLAS/include"
NO_DEFAULT_PATH
)
if (NOT SOFIEBLAS_INCLUDE_DIR)
find_path(SOFIEBLAS_INCLUDE_DIR NAMES sofieBLAS/sofieBLAS.hpp)
endif()
if (SOFIEBLAS_INCLUDE_DIR)
message(STATUS "boso: using sofieBLAS at ${SOFIEBLAS_INCLUDE_DIR}")
add_library(sofieBLAS INTERFACE)
target_include_directories(sofieBLAS INTERFACE "${SOFIEBLAS_INCLUDE_DIR}")
else()
message(STATUS "boso: sofieBLAS not found next to this checkout; fetching it")
FetchContent_Declare(
sofieBLAS
GIT_REPOSITORY https://github.com/ML4EP/sofieBLAS
GIT_TAG dev
)
FetchContent_MakeAvailable(sofieBLAS)
if (NOT TARGET sofieBLAS)
add_library(sofieBLAS INTERFACE)
target_include_directories(sofieBLAS INTERFACE "${sofieblas_SOURCE_DIR}/include")
endif()
endif()
# --- cuBLASLt / hipBLASLt --------------------------------------------------
set(BOSO_HAVE_CUBLASLT OFF)
set(BOSO_HAVE_HIPBLASLT OFF)
if (_boso_backend STREQUAL "cuda")
enable_language(CUDA)
find_package(CUDAToolkit REQUIRED)
if (TARGET CUDA::cublasLt)
set(BOSO_HAVE_CUBLASLT ON)
message(STATUS "boso: cuBLASLt found (CUDA::cublasLt)")
else()
message(WARNING
"boso: cuBLASLt was not found on this system. The build will fall "
"back to sofieBLAS's native (non-Lt) BLAS backend for GEMM on GPU. "
"Install a CUDA Toolkit that ships cuBLASLt (>=10.1) for the "
"Lt-accelerated backend.")
endif()
elseif (_boso_backend STREQUAL "hip")
enable_language(HIP)
find_package(hipblaslt QUIET)
if (hipblaslt_FOUND)
set(BOSO_HAVE_HIPBLASLT ON)
message(STATUS "boso: hipBLASLt found")
else()
message(WARNING
"boso: hipBLASLt was not found on this system. The build will fall "
"back to sofieBLAS's native (non-Lt) BLAS backend for GEMM on GPU. "
"Install hipBLASLt (part of recent ROCm releases) for the "
"Lt-accelerated backend.")
endif()
endif()
############################################################################
# boso core library
#
# Template implementations live in src/boso/**/*.tpp (included at the
# bottom of their corresponding header via `#include "boso/...tpp"`).
# Non-template implementations (Container, JobConfig) are compiled here as
# ordinary C++ sources and must never be compiled with the GPU compiler, so
# their language is pinned to CXX explicitly.
############################################################################
set(_boso_cxx_sources
src/Container.cpp
src/JobConfig.cpp
src/boso/encoded/StreamingEncodedSink.cpp
src/boso/encoded/StreamingEncodedSource.cpp
)
set_source_files_properties(${_boso_cxx_sources} PROPERTIES LANGUAGE CXX)
add_library(boso STATIC ${_boso_cxx_sources})
target_include_directories(boso PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/inc>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
$<INSTALL_INTERFACE:include>
)
target_link_libraries(boso PUBLIC alpaka::alpaka sofieBLAS)
target_compile_features(boso PUBLIC cxx_std_20)
if (BOSO_HAVE_CUBLASLT)
target_link_libraries(boso PUBLIC CUDA::cublasLt)
target_compile_definitions(boso PUBLIC BOSO_HAVE_CUBLASLT=1)
endif()
if (BOSO_HAVE_HIPBLASLT)
target_link_libraries(boso PUBLIC hipblaslt::hipblaslt)
target_compile_definitions(boso PUBLIC BOSO_HAVE_HIPBLASLT=1)
endif()
function(boso_apply_backend target)
if (_boso_backend STREQUAL "cpu")
target_compile_definitions(${target} PRIVATE ALPAKA_ACC_CPU_B_SEQ_T_SEQ_ENABLED)
elseif (_boso_backend STREQUAL "cuda")
set_source_files_properties($<TARGET_PROPERTY:${target},SOURCES> PROPERTIES LANGUAGE CUDA)
target_compile_definitions(${target} PRIVATE ALPAKA_ACC_GPU_CUDA_ENABLED)
elseif (_boso_backend STREQUAL "hip")
set_source_files_properties($<TARGET_PROPERTY:${target},SOURCES> PROPERTIES LANGUAGE HIP)
target_compile_definitions(${target} PRIVATE ALPAKA_ACC_GPU_HIP_ENABLED)
else()
message(FATAL_ERROR "boso: unsupported BOSO_ALPAKA_BACKEND=${BOSO_ALPAKA_BACKEND}")
endif()
endfunction()
if (BOSO_BUILD_DEMO)
add_executable(boso_demo tutorials/boso_demo.cpp)
target_link_libraries(boso_demo PRIVATE boso)
target_include_directories(boso_demo PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/tutorials")
boso_apply_backend(boso_demo)
endif()
############################################################################
# One binary per backbones.json entry.
#
# Each entry names a SOFIE-generated Session header/class; CMake stamps out
# src/boso_tool.cpp.in for it and builds a standalone boso_<name>
# executable that can only compress/decompress data for that one backbone
# (see Container.hpp and boso_tool.cpp.in for why that's enforced at
# runtime, not just by convention).
############################################################################
if (NOT EXISTS "${BOSO_BACKBONES_JSON}")
message(FATAL_ERROR "boso: BOSO_BACKBONES_JSON '${BOSO_BACKBONES_JSON}' does not exist")
endif()
file(READ "${BOSO_BACKBONES_JSON}" _boso_backbones_json)
string(JSON _boso_backbone_count LENGTH "${_boso_backbones_json}" "backbones")
if (_boso_backbone_count EQUAL 0)
message(WARNING "boso: '${BOSO_BACKBONES_JSON}' lists no backbones; no boso_<name> binaries will be built")
else()
math(EXPR _boso_last_idx "${_boso_backbone_count} - 1")
foreach(_boso_idx RANGE ${_boso_last_idx})
string(JSON BOSO_BACKBONE_NAME GET "${_boso_backbones_json}" "backbones" ${_boso_idx} "name")
string(JSON BOSO_BACKBONE_HEADER GET "${_boso_backbones_json}" "backbones" ${_boso_idx} "header")
string(JSON BOSO_BACKBONE_SESSION GET "${_boso_backbones_json}" "backbones" ${_boso_idx} "session")
string(JSON BOSO_BACKBONE_VOCAB_SIZE GET "${_boso_backbones_json}" "backbones" ${_boso_idx} "vocab_size")
string(JSON BOSO_BACKBONE_DMODEL GET "${_boso_backbones_json}" "backbones" ${_boso_idx} "d_model")
string(JSON _boso_include_dir GET "${_boso_backbones_json}" "backbones" ${_boso_idx} "include_dir")
cmake_path(IS_ABSOLUTE _boso_include_dir _boso_include_dir_is_abs)
if (NOT _boso_include_dir_is_abs)
set(_boso_include_dir "${CMAKE_CURRENT_SOURCE_DIR}/${_boso_include_dir}")
endif()
message(STATUS "boso: configuring backbone '${BOSO_BACKBONE_NAME}' (header=${BOSO_BACKBONE_HEADER}, include_dir=${_boso_include_dir})")
set(_boso_generated "${CMAKE_CURRENT_BINARY_DIR}/generated/boso_tool_${BOSO_BACKBONE_NAME}.cpp")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/src/boso_tool.cpp.in" "${_boso_generated}" @ONLY)
set(_boso_target "boso_${BOSO_BACKBONE_NAME}")
add_executable(${_boso_target} "${_boso_generated}")
target_link_libraries(${_boso_target} PRIVATE boso)
target_include_directories(${_boso_target} PRIVATE "${_boso_include_dir}")
boso_apply_backend(${_boso_target})
endforeach()
endif()
install(DIRECTORY inc/ DESTINATION include)
install(TARGETS boso EXPORT boso-targets)