Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

CMakeLists.txt 6.7 KB

You have to be logged in to leave a comment. Sign In
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
  1. cmake_minimum_required (VERSION 3.3)
  2. project(ggml VERSION 0.1.0)
  3. set(CMAKE_EXPORT_COMPILE_COMMANDS "on")
  4. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
  5. set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
  6. set(CMAKE_POSITION_INDEPENDENT_CODE ON)
  7. if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
  8. set(GGML_STANDALONE ON)
  9. include(cmake/GitVars.cmake)
  10. include(cmake/BuildTypes.cmake)
  11. else()
  12. set(GGML_STANDALONE OFF)
  13. endif()
  14. # options
  15. option(GGML_ALL_WARNINGS "ggml: enable all compiler warnings" ON)
  16. option(GGML_ALL_WARNINGS_3RD_PARTY "ggml: enable all compiler warnings in 3rd party libs" OFF)
  17. option(GGML_SANITIZE_THREAD "ggml: enable thread sanitizer" OFF)
  18. option(GGML_SANITIZE_ADDRESS "ggml: enable address sanitizer" OFF)
  19. option(GGML_SANITIZE_UNDEFINED "ggml: enable undefined sanitizer" OFF)
  20. option(GGML_BUILD_TESTS "ggml: build tests" ${GGML_STANDALONE})
  21. option(GGML_BUILD_EXAMPLES "ggml: build examples" ${GGML_STANDALONE})
  22. option(GGML_TEST_COVERAGE "ggml: enable test coverage" OFF)
  23. option(GGML_PERF "ggml: enable perf timings" OFF)
  24. option(GGML_NO_ACCELERATE "ggml: disable Accelerate framework" OFF)
  25. option(GGML_OPENBLAS "ggml: use OpenBLAS" OFF)
  26. option(GGML_CLBLAST "ggml: use clBLAST" OFF)
  27. option(GGML_CUBLAS "ggml: use cuBLAS" OFF)
  28. option(GGML_METAL "ggml: use Metal" OFF)
  29. # sanitizers
  30. if (GGML_SANITIZE_THREAD)
  31. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=thread")
  32. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread")
  33. endif()
  34. if (GGML_SANITIZE_ADDRESS)
  35. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fno-omit-frame-pointer")
  36. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer")
  37. endif()
  38. if (GGML_SANITIZE_UNDEFINED)
  39. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=undefined")
  40. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined")
  41. endif()
  42. # instruction set specific
  43. option(GGML_AVX "ggml: enable AVX" ON)
  44. option(GGML_AVX2 "ggml: enable AVX2" ON)
  45. option(GGML_AVX512 "ggml: enable AVX512" OFF)
  46. option(GGML_AVX512_VBMI "ggml: enable AVX512-VBMI" OFF)
  47. option(GGML_AVX512_VNNI "ggml: enable AVX512-VNNI" OFF)
  48. option(GGML_FMA "ggml: enable FMA" ON)
  49. # in MSVC F16C is implied with AVX2/AVX512
  50. if (NOT MSVC)
  51. option(GGML_F16C "ggml: enable F16C" ON)
  52. endif()
  53. #set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffast-math")
  54. #set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=native")
  55. #set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mcpu=native")
  56. # warning flags
  57. if (GGML_ALL_WARNINGS)
  58. if (NOT MSVC)
  59. set(c_flags -Wall -Wpedantic -Wformat=2 -Wno-unused -Wstrict-prototypes)
  60. set(cxx_flags -Wall -Wpedantic -Wformat=2)
  61. else()
  62. # todo : windows
  63. endif()
  64. add_compile_options(
  65. "$<$<COMPILE_LANGUAGE:C>:${c_flags}>"
  66. "$<$<COMPILE_LANGUAGE:CXX>:${cxx_flags}>"
  67. )
  68. endif()
  69. if (NOT MSVC)
  70. add_compile_options(
  71. "$<$<COMPILE_LANGUAGE:C>:-Werror=vla>"
  72. "$<$<COMPILE_LANGUAGE:CXX>:-Werror=vla>"
  73. "$<$<COMPILE_LANGUAGE:CUDA>:-Xcompiler;-Werror=vla>"
  74. )
  75. endif()
  76. #
  77. # POSIX conformance
  78. #
  79. # clock_gettime came in POSIX.1b (1993)
  80. # CLOCK_MONOTONIC came in POSIX.1-2001 / SUSv3 as optional
  81. # posix_memalign came in POSIX.1-2001 / SUSv3
  82. # M_PI is an XSI extension since POSIX.1-2001 / SUSv3, came in XPG1 (1985)
  83. add_compile_definitions(_XOPEN_SOURCE=600)
  84. # Somehow in OpenBSD whenever POSIX conformance is specified
  85. # some string functions rely on locale_t availability,
  86. # which was introduced in POSIX.1-2008, forcing us to go higher
  87. if (CMAKE_SYSTEM_NAME MATCHES "OpenBSD")
  88. remove_definitions(-D_XOPEN_SOURCE=600)
  89. add_compile_definitions(_XOPEN_SOURCE=700)
  90. endif()
  91. # Data types, macros and functions related to controlling CPU affinity
  92. # are available on Linux through GNU extensions in libc
  93. if (CMAKE_SYSTEM_NAME MATCHES "Linux")
  94. add_compile_definitions(_GNU_SOURCE)
  95. endif()
  96. # RLIMIT_MEMLOCK came in BSD, is not specified in POSIX.1,
  97. # and on macOS its availability depends on enabling Darwin extensions
  98. # similarly on DragonFly, enabling BSD extensions is necessary
  99. if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
  100. add_compile_definitions(_DARWIN_C_SOURCE)
  101. endif()
  102. if (CMAKE_SYSTEM_NAME MATCHES "DragonFly")
  103. add_compile_definitions(_DARWIN_C_SOURCE)
  104. endif()
  105. # alloca is a non-standard interface that is not visible on BSDs when
  106. # POSIX conformance is specified, but not all of them provide a clean way
  107. # to enable it in such cases
  108. if (CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
  109. add_compile_definitions(__BSD_VISIBLE)
  110. endif()
  111. if (CMAKE_SYSTEM_NAME MATCHES "NetBSD")
  112. add_compile_definitions(_NETBSD_SOURCE)
  113. endif()
  114. if (CMAKE_SYSTEM_NAME MATCHES "OpenBSD")
  115. add_compile_definitions(_BSD_SOURCE)
  116. endif()
  117. if (WHISPER_PERF)
  118. set(WHISPER_EXTRA_FLAGS ${WHISPER_EXTRA_FLAGS} -DGGML_PERF)
  119. endif()
  120. # dependencies
  121. set(CMAKE_C_STANDARD 11)
  122. set(CMAKE_CXX_STANDARD 14)
  123. find_package(Threads REQUIRED)
  124. # main
  125. file(GLOB KALDI_NATIVE_FBANK_SOURCES
  126. "${CMAKE_CURRENT_SOURCE_DIR}/examples/kaldi-native-fbank/csrc/*"
  127. )
  128. add_library(kaldi-native-fbank STATIC ${KALDI_NATIVE_FBANK_SOURCES})
  129. target_include_directories(kaldi-native-fbank PUBLIC
  130. ${CMAKE_CURRENT_SOURCE_DIR}/examples/kaldi-native-fbank/csrc
  131. )
  132. if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
  133. set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE)
  134. set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "RelWithDebInfo")
  135. endif ()
  136. if (GGML_BUILD_TESTS)
  137. if (GGML_TEST_COVERAGE)
  138. if (CMAKE_C_COMPILER_ID MATCHES "Clang")
  139. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-instr-generate -fcoverage-mapping")
  140. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-instr-generate -fcoverage-mapping")
  141. else()
  142. message(WARNING "Test coverage is only supported for Clang")
  143. endif()
  144. endif()
  145. endif()
  146. add_subdirectory(src)
  147. if (GGML_BUILD_TESTS)
  148. enable_testing()
  149. add_subdirectory(tests)
  150. endif ()
  151. if (GGML_BUILD_EXAMPLES)
  152. add_subdirectory(examples)
  153. endif ()
  154. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/ggml.pc.in
  155. ${CMAKE_CURRENT_BINARY_DIR}/ggml.pc
  156. @ONLY)
  157. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/ggml.pc
  158. DESTINATION share/pkgconfig)
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...