forked from bitsandbytes-foundation/bitsandbytes
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
78 lines (63 loc) · 2.19 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
cmake_minimum_required(VERSION 3.26.0)
# Set cuda12x supported archs only for now
# This has to be set before project()
set(CMAKE_CUDA_ARCHITECTURES "75;80;86;89;90")
project(bitsandbytes LANGUAGES CXX CUDA)
find_package(CUDAToolkit REQUIRED)
# Set global flags
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CUDA_STANDARD 14)
add_compile_definitions(BUILD_CUDA)
if(WIN32)
# Mute warnings
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -diag-suppress=177")
# Export all symbols
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
endif()
# Weird MSVC hacks
if(MSVC)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /NODEFAULTLIB:msvcprtd /NODEFAULTLIB:MSVCRTD /NODEFAULTLIB:LIBCMT")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /arch:AVX2")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /arch:AVX2")
endif()
# pthread does not exist on Windows
if(WIN32)
include(ExternalProject)
ExternalProject_Add(pthread-win32
GIT_REPOSITORY https://github.com/GerHobbelt/pthread-win32
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${EXTERNAL_INSTALL_LOCATION}
)
include_directories(${EXTERNAL_INSTALL_LOCATION}/include)
link_directories(${EXTERNAL_INSTALL_LOCATION}/lib)
endif()
# Add csrc files
add_library(bitsandbytes SHARED
csrc/ops.cu
csrc/kernels.cu
csrc/common.cpp
csrc/cpu_ops.cpp
csrc/pythonInterface.cpp)
target_include_directories(bitsandbytes PUBLIC
${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}
${CMAKE_CURRENT_SOURCE_DIR}/csrc
${CMAKE_CURRENT_SOURCE_DIR}/include
${CUDA_TOOLKIT_ROOT_DIR}/include)
# Pass options to NVCC
target_compile_options(bitsandbytes PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:
--use_fast_math
-Xptxas=-v
-dc
>)
set_target_properties(
bitsandbytes
PROPERTIES
CUDA_SEPARABLE_COMPILATION ON)
if(WIN32)
# pthread does not exist on Windows
add_dependencies(bitsandbytes pthread-win32)
target_link_libraries(bitsandbytes CUDA::cudart CUDA::cublas CUDA::cublasLt CUDA::cusparse pthreadVC3)
else()
target_link_libraries(bitsandbytes CUDA::cudart CUDA::cublas CUDA::cublasLt CUDA::cusparse)
endif()
# Set the output name of the CUDA library
set_target_properties(bitsandbytes PROPERTIES OUTPUT_NAME "bitsandbytes_cuda120")