forked from UbiquitousLearning/mllm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
678 lines (602 loc) · 25.1 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
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
cmake_minimum_required(VERSION 3.10)
project(mllm)
cmake_policy(SET CMP0074 NEW)
set(CMAKE_CXX_STANDARD 17)
option(ARM "build on ARM" OFF)
if(MSVC)
message(STATUS "Using MSVC as the compiler")
else()
add_compile_options(-Wno-deprecated-declarations)
endif()
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm" OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64")
message(STATUS "ARM detected")
set(ARM ON)
set(ANDROID_PLATFORM android-28)
# add_compile_options(-std=c++17)
endif ()
if (ARM)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/../bin-arm)
add_compile_definitions(__ARM_FEATURE_DOTPROD)
# 检查是否使用的是 GCC 或 Clang 编译器
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=armv8.2-a+dotprod")
endif()
else ()
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/../bin)
endif ()
if (CMAKE_BUILD_TYPE STREQUAL "Release")
option(TEST "test mode" OFF)
else ()
option(TEST "test mode" ON)
endif ()
option(QUANT "quantize tools" ON)
option(APK "Build for Android APK Lib." OFF)
option(FROM_GGUF "convert from gguf" OFF)
option(DEBUG "debug print" OFF)
if(DEBUG)
add_definitions(-DDEBUGPRINT)
endif()
# backend options
option(QNN "Enable QNN" OFF)
if(QNN)
add_definitions(-DUSE_QNN)
endif()
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
cmake_policy(SET CMP0135 NEW)
endif ()
include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
)
# find_program(CLANG_TIDY_EXE NAMES "clang-tidy" REQUIRED)
# set(CMAKE_CXX_CLANG_TIDY "clang-tidy")
option(MLLM_OPENMP "openmp" ON)
option(MLLM_OPENMP_STATIC "openmp static" OFF)
if (CMAKE_HOST_UNIX)
message(STATUS "current platform: Linux ")
# set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -std=c++14 -stdlib=libc++")
elseif (CMAKE_HOST_WIN32)
message(STATUS "current platform: Windows ")
else ()
message(STATUS "current platform: unknown ")
endif ()
if (ARM AND NOT APK)
set(MLLM_OPENMP_STATIC ON)
endif ()
# turn off openmp when build on mac or for mac
if (CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin" AND NOT CMAKE_CROSSCOMPILING)
message(STATUS "mac detected, turn off openmp")
set(MLLM_OPENMP OFF)
set(MLLM_OPENMP_STATIC OFF)
endif ()
aux_source_directory(${PROJECT_SOURCE_DIR}/src DIR_SRC)
aux_source_directory(${PROJECT_SOURCE_DIR}/src/express DIR_SRC_EXP)
aux_source_directory(${PROJECT_SOURCE_DIR}/src/processor DIR_SRC_PROCESSOE)
aux_source_directory(${PROJECT_SOURCE_DIR}/src/memory DIR_SRC_MEM_MANAGER)
aux_source_directory(${PROJECT_SOURCE_DIR}/examples EMP_SRC)
aux_source_directory(${PROJECT_SOURCE_DIR}/test TEST_SRC)
aux_source_directory(${PROJECT_SOURCE_DIR}/third_party/wenet_audio DIR_THIRDPARTY_AUDIO)
include_directories(${PROJECT_SOURCE_DIR}/src)
include_directories(${PROJECT_SOURCE_DIR}/include)
include_directories(${PROJECT_SOURCE_DIR}/third_party)
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/src/backends/cpu)
#add tokenizers
file(GLOB_RECURSE SRC_TOKENIZERS
${PROJECT_SOURCE_DIR}/src/tokenizers/*.cpp
${PROJECT_SOURCE_DIR}/src/tokenizers/*.hpp
)
# if compile to x86_64
if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "^(x86_64|i686|AMD64)$")
message(STATUS "x86_64 detected")
add_compile_options(-mf16c)
add_compile_options(-mavx2)
elseif (${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm" OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64")
message(STATUS "ARM detected")
add_definitions(-DARM)
if (APK)
message(STATUS "Build for Android APK Lib.")
add_definitions("-DANDROID_API")
endif ()
endif ()
if (QUANT)
include_directories(${PROJECT_SOURCE_DIR}/src/quantizer)
file(GLOB_RECURSE MLLM_QUANT
${PROJECT_SOURCE_DIR}/src/backends/cpu/compute/GEMM_AArch64.hpp
${PROJECT_SOURCE_DIR}/src/backends/cpu/compute/GEMM_AArch64.cpp
${PROJECT_SOURCE_DIR}/src/backends/cpu/quantize/*.hpp
${PROJECT_SOURCE_DIR}/src/backends/cpu/quantize/*.cpp
)
file(GLOB_RECURSE MLLM_QUANTIZER
${CMAKE_CURRENT_LIST_DIR}/src/quantizer/*.cpp
${CMAKE_CURRENT_LIST_DIR}/src/quantizer/*.hpp)
list(REMOVE_ITEM MLLM_QUANTIZER ${CMAKE_CURRENT_LIST_DIR}/src/quantizer/main.cpp)
message(STATUS "MLLM_Quant: ${MLLM_QUANT}")
add_executable(
quantize
${PROJECT_SOURCE_DIR}/src/quantizer/main.cpp
${MLLM_QUANT}
${MLLM_QUANTIZER}
# ${DIR_SRC}
${PROJECT_SOURCE_DIR}/src/ParamLoader.cpp
)
if (FROM_GGUF)
add_executable(
from_gguf
${PROJECT_SOURCE_DIR}/tools/gguf_convertor/gguf.cpp
${PROJECT_SOURCE_DIR}/tools/gguf_convertor/gguf.hpp
${MLLM_QUANT}
${MLLM_QUANTIZER}
# ${DIR_SRC}
${PROJECT_SOURCE_DIR}/src/ParamLoader.cpp
)
endif ()
endif ()
if (TEST)
add_definitions(-DTEST)
FetchContent_MakeAvailable(googletest)
enable_testing()
include_directories(${PROJECT_SOURCE_DIR}/test)
# MLLM Tests
file(GLOB_RECURSE MLLM_TEST
${CMAKE_CURRENT_LIST_DIR}/test/*.cpp
${CMAKE_CURRENT_LIST_DIR}/test/*.hpp
)
list(REMOVE_ITEM MLLM_TEST ${CMAKE_CURRENT_LIST_DIR}/test/TestSystemMemoryManager.cpp)
list(REMOVE_ITEM MLLM_TEST ${CMAKE_CURRENT_LIST_DIR}/test/TestMemoryPoolManager.cpp)
# list(REMOVE_ITEM MLLM_TEST ${CMAKE_CURRENT_LIST_DIR}/test/clip_tokenizer_test.cpp)
message(STATUS "MLLM_TEST: ${MLLM_TEST}")
# Add ${DIR_SRC_QUANT} to ${DIR_SRC}
# if ()
add_executable(
MLLM_TEST
${PROJECT_SOURCE_DIR}/test/main.cpp
${MLLM_TEST}
${DIR_SRC_CPU} ${DIR_SRC_MEM_MANAGER} ${DIR_SRC_EXP} ${DIR_SRC} ${MLLM_QUANTIZER} ${SRC_TOKENIZERS}
src/processor/ClipPreProcess.hpp
src/processor/ClipPreProcess.cpp
src/processor/FuyuPreProcess.hpp
src/processor/FuyuPreProcess.cpp
src/processor/PreProcess.hpp
src/processor/PreProcess.cpp
test/processor/ClipPreprocessorTest.cpp
)
target_link_libraries(
MLLM_TEST
GTest::gtest_main
MLLM_CPU
)
add_executable(
memoryPoolTest
${PROJECT_SOURCE_DIR}/test/TestMemoryPoolManager.cpp
${DIR_SRC_MEM_MANAGER} ${PROJECT_SOURCE_DIR}/src/MemoryManager.hpp
)
add_executable(
SystemMemoryTest
${PROJECT_SOURCE_DIR}/test/TestSystemMemoryManager.cpp
${DIR_SRC_MEM_MANAGER} ${PROJECT_SOURCE_DIR}/src/MemoryManager.hpp
)
include(GoogleTest)
# if not cross-compiling
if (NOT ARM)
gtest_discover_tests(MLLM_TEST)
endif ()
endif ()
# cpu executables
if(NOT QNN)
add_executable(main_llama ${PROJECT_SOURCE_DIR}/examples/main_llama.cpp ${DIR_SRC_CPU} ${DIR_SRC_MEM_MANAGER} ${DIR_SRC_EXP} ${DIR_SRC} # ${DIR_SRC_QUANT}
src/tokenizers/Tokenizer.cpp
src/tokenizers/Tokenizer.hpp
src/tokenizers/BPE/Bpe.cpp
src/tokenizers/BPE/Bpe.hpp
)
if (MLLM_OPENMP_STATIC)
target_compile_options(main_llama PRIVATE -fopenmp)
target_link_libraries(main_llama PUBLIC MLLM_CPU -fopenmp -static-openmp)
else ()
target_compile_options(main_llama PRIVATE -fopenmp)
target_link_libraries(main_llama PUBLIC MLLM_CPU -fopenmp)
endif ()
add_executable(main_alpaca ${PROJECT_SOURCE_DIR}/examples/main_alpaca.cpp ${DIR_SRC_CPU} ${DIR_SRC_MEM_MANAGER} ${DIR_SRC_EXP} ${DIR_SRC} # ${DIR_SRC_QUANT}
src/tokenizers/Tokenizer.cpp
src/tokenizers/Tokenizer.hpp
src/tokenizers/BPE/Bpe.cpp
src/tokenizers/BPE/Bpe.hpp
)
if (MLLM_OPENMP_STATIC)
target_compile_options(main_alpaca PRIVATE -fopenmp)
target_link_libraries(main_alpaca PUBLIC MLLM_CPU -fopenmp -static-openmp)
else ()
target_compile_options(main_alpaca PRIVATE -fopenmp)
target_link_libraries(main_alpaca PUBLIC MLLM_CPU -fopenmp)
endif ()
add_executable(main_llava ${PROJECT_SOURCE_DIR}/examples/main_llava.cpp ${DIR_SRC_CPU} ${DIR_SRC_MEM_MANAGER} ${DIR_SRC_EXP} ${DIR_SRC}
src/tokenizers/Tokenizer.cpp
src/tokenizers/BPE/Bpe.cpp
src/processor/PreProcess.cpp
src/processor/ClipPreProcess.cpp
)
if (MLLM_OPENMP_STATIC)
target_compile_options(main_llava PRIVATE -fopenmp)
target_link_libraries(main_llava PUBLIC MLLM_CPU -fopenmp -static-openmp)
else ()
target_compile_options(main_llava PRIVATE -fopenmp)
target_link_libraries(main_llava PUBLIC MLLM_CPU -fopenmp)
endif ()
add_executable(main_tinyllama ${PROJECT_SOURCE_DIR}/examples/main_tinyllama.cpp ${DIR_SRC_CPU} ${DIR_SRC_MEM_MANAGER} ${DIR_SRC_EXP} ${DIR_SRC} # ${DIR_SRC_QUANT}
src/tokenizers/Tokenizer.cpp
src/tokenizers/Tokenizer.hpp
src/tokenizers/BPE/Bpe.cpp
src/tokenizers/BPE/Bpe.hpp
)
if (MLLM_OPENMP_STATIC)
target_compile_options(main_tinyllama PRIVATE -fopenmp)
target_link_libraries(main_tinyllama PUBLIC MLLM_CPU -fopenmp -static-openmp)
else ()
target_compile_options(main_tinyllama PRIVATE -fopenmp)
target_link_libraries(main_tinyllama PUBLIC MLLM_CPU -fopenmp)
endif ()
add_executable(main_fuyu ${PROJECT_SOURCE_DIR}/examples/main_fuyu.cpp ${DIR_SRC_CPU} ${DIR_SRC_MEM_MANAGER} ${DIR_SRC_EXP} ${DIR_SRC}
src/tokenizers/Tokenizer.cpp
src/tokenizers/Tokenizer.hpp
src/tokenizers/Unigram/Unigram.hpp
src/tokenizers/Unigram/Unigram.cpp
src/tokenizers/Unigram/trie.hpp
src/tokenizers/BPE/Bpe.cpp
src/tokenizers/BPE/Bpe.hpp
src/processor/PreProcess.hpp
src/processor/FuyuPreProcess.hpp
src/processor/FuyuPreProcess.cpp
src/processor/PreProcess.cpp
)
if (MLLM_OPENMP_STATIC)
target_compile_options(main_fuyu PRIVATE -fopenmp)
target_link_libraries(main_fuyu PUBLIC MLLM_CPU -fopenmp -static-openmp)
else ()
target_compile_options(main_fuyu PRIVATE -fopenmp)
target_link_libraries(main_fuyu PUBLIC MLLM_CPU -fopenmp)
endif ()
add_executable(main_vit ${PROJECT_SOURCE_DIR}/examples/main_vit.cpp ${DIR_SRC_CPU} ${DIR_SRC_MEM_MANAGER} ${DIR_SRC_EXP} ${DIR_SRC}
src/tokenizers/Tokenizer.cpp
src/tokenizers/Tokenizer.hpp
src/tokenizers/Unigram/Unigram.hpp
src/tokenizers/Unigram/Unigram.cpp
src/tokenizers/Unigram/trie.hpp
src/tokenizers/BPE/Bpe.cpp
src/tokenizers/BPE/Bpe.hpp
src/processor/PreProcess.hpp
src/processor/PreProcess.cpp
)
if (MLLM_OPENMP_STATIC)
target_compile_options(main_vit PRIVATE -fopenmp)
target_link_libraries(main_vit PUBLIC MLLM_CPU -fopenmp -static-openmp)
else ()
target_compile_options(main_vit PRIVATE -fopenmp)
target_link_libraries(main_vit PUBLIC MLLM_CPU -fopenmp)
endif ()
add_executable(main_clip ${PROJECT_SOURCE_DIR}/examples/main_clip.cpp ${DIR_SRC_CPU} ${DIR_SRC_MEM_MANAGER} ${DIR_SRC_EXP} ${DIR_SRC} # ${DIR_SRC_QUANT}
src/tokenizers/Tokenizer.cpp
src/tokenizers/Tokenizer.hpp
src/tokenizers/BPE/Bpe.cpp
src/tokenizers/BPE/Bpe.hpp
src/processor/PreProcess.hpp
src/processor/PreProcess.cpp
src/processor/ClipPreProcess.cpp
src/processor/ClipPreProcess.hpp
)
if (MLLM_OPENMP_STATIC)
target_compile_options(main_clip PRIVATE -fopenmp)
target_link_libraries(main_clip PUBLIC MLLM_CPU -fopenmp -static-openmp)
else ()
target_compile_options(main_clip PRIVATE -fopenmp)
target_link_libraries(main_clip PUBLIC MLLM_CPU -fopenmp)
endif ()
add_executable(main_imagebind ${PROJECT_SOURCE_DIR}/examples/main_imagebind.cpp ${DIR_SRC_CPU} ${DIR_SRC_MEM_MANAGER} ${DIR_SRC_EXP} ${DIR_SRC} # ${DIR_SRC_QUANT}
src/tokenizers/Tokenizer.cpp
src/tokenizers/Tokenizer.hpp
src/tokenizers/BPE/Bpe.cpp
src/tokenizers/BPE/Bpe.hpp
${DIR_SRC_PROCESSOE}
${DIR_THIRDPARTY_AUDIO}
src/processor/PreProcess.hpp
src/processor/PreProcess.cpp
)
if (MLLM_OPENMP_STATIC)
target_compile_options(main_imagebind PRIVATE -fopenmp)
target_link_libraries(main_imagebind PUBLIC MLLM_CPU -fopenmp -static-openmp)
else ()
target_compile_options(main_imagebind PRIVATE -fopenmp)
target_link_libraries(main_imagebind PUBLIC MLLM_CPU -fopenmp)
endif ()
add_executable(demo_stablelm ${PROJECT_SOURCE_DIR}/examples/demo_stablelm.cpp ${DIR_SRC_CPU} ${DIR_SRC_MEM_MANAGER} ${DIR_SRC_EXP} ${DIR_SRC}
src/tokenizers/Tokenizer.cpp
src/tokenizers/BPE/Bpe.cpp
)
if (MLLM_OPENMP_STATIC)
target_compile_options(demo_stablelm PRIVATE -fopenmp)
target_link_libraries(demo_stablelm PUBLIC MLLM_CPU -fopenmp -static-openmp)
else ()
target_compile_options(demo_stablelm PRIVATE -fopenmp)
target_link_libraries(demo_stablelm PUBLIC MLLM_CPU -fopenmp)
endif ()
add_executable(demo_llama ${PROJECT_SOURCE_DIR}/examples/demo_llama.cpp ${DIR_SRC_CPU} ${DIR_SRC_MEM_MANAGER} ${DIR_SRC_EXP} ${DIR_SRC}
src/tokenizers/Tokenizer.cpp
src/tokenizers/BPE/Bpe.cpp
)
if (MLLM_OPENMP_STATIC)
target_compile_options(demo_llama PRIVATE -fopenmp)
target_link_libraries(demo_llama PUBLIC MLLM_CPU -fopenmp -static-openmp)
else ()
target_compile_options(demo_llama PRIVATE -fopenmp)
target_link_libraries(demo_llama PUBLIC MLLM_CPU -fopenmp)
endif ()
add_executable(demo_fuyu ${PROJECT_SOURCE_DIR}/examples/demo_fuyu.cpp ${DIR_SRC_CPU} ${DIR_SRC_MEM_MANAGER} ${DIR_SRC_EXP} ${DIR_SRC}
src/tokenizers/Tokenizer.cpp
src/tokenizers/Unigram/Unigram.cpp
src/processor/FuyuPreProcess.cpp
src/processor/PreProcess.cpp
)
if (MLLM_OPENMP_STATIC)
target_compile_options(demo_fuyu PRIVATE -fopenmp)
target_link_libraries(demo_fuyu PUBLIC MLLM_CPU -fopenmp -static-openmp)
else ()
target_compile_options(demo_fuyu PRIVATE -fopenmp)
target_link_libraries(demo_fuyu PUBLIC MLLM_CPU -fopenmp)
endif ()
add_executable(demo_vit ${PROJECT_SOURCE_DIR}/examples/demo_vit.cpp ${DIR_SRC_CPU} ${DIR_SRC_MEM_MANAGER} ${DIR_SRC_EXP} ${DIR_SRC}
src/processor/PreProcess.cpp
)
if (MLLM_OPENMP_STATIC)
target_compile_options(demo_vit PRIVATE -fopenmp)
target_link_libraries(demo_vit PUBLIC MLLM_CPU -fopenmp -static-openmp)
else ()
target_compile_options(demo_vit PRIVATE -fopenmp)
target_link_libraries(demo_vit PUBLIC MLLM_CPU -fopenmp)
endif ()
add_executable(demo_clip ${PROJECT_SOURCE_DIR}/examples/demo_clip.cpp ${DIR_SRC_CPU} ${DIR_SRC_MEM_MANAGER} ${DIR_SRC_EXP} ${DIR_SRC}
src/tokenizers/Tokenizer.cpp
src/tokenizers/BPE/Bpe.cpp
src/processor/PreProcess.cpp
src/processor/ClipPreProcess.cpp
)
if (MLLM_OPENMP_STATIC)
target_compile_options(demo_clip PRIVATE -fopenmp)
target_link_libraries(demo_clip PUBLIC MLLM_CPU -fopenmp -static-openmp)
else ()
target_compile_options(demo_clip PRIVATE -fopenmp)
target_link_libraries(demo_clip PUBLIC MLLM_CPU -fopenmp)
endif ()
add_executable(demo_imagebind ${PROJECT_SOURCE_DIR}/examples/demo_imagebind.cpp ${DIR_SRC_CPU} ${DIR_SRC_MEM_MANAGER} ${DIR_SRC_EXP} ${DIR_SRC} # ${DIR_SRC_QUANT}
src/tokenizers/Tokenizer.cpp
src/tokenizers/BPE/Bpe.cpp
${DIR_SRC_PROCESSOE}
${DIR_THIRDPARTY_AUDIO}
src/processor/PreProcess.cpp
)
if (MLLM_OPENMP_STATIC)
target_compile_options(demo_imagebind PRIVATE -fopenmp)
target_link_libraries(demo_imagebind PUBLIC MLLM_CPU -fopenmp -static-openmp)
else ()
target_compile_options(demo_imagebind PRIVATE -fopenmp)
target_link_libraries(demo_imagebind PUBLIC MLLM_CPU -fopenmp)
endif ()
add_executable(demo_imagebind_1mod ${PROJECT_SOURCE_DIR}/examples/demo_imagebind_1mod.cpp ${DIR_SRC_CPU} ${DIR_SRC_MEM_MANAGER} ${DIR_SRC_EXP} ${DIR_SRC} # ${DIR_SRC_QUANT}
src/tokenizers/Tokenizer.cpp
src/tokenizers/BPE/Bpe.cpp
${DIR_SRC_PROCESSOE}
${DIR_THIRDPARTY_AUDIO}
src/processor/PreProcess.cpp
)
if (MLLM_OPENMP_STATIC)
target_compile_options(demo_imagebind_1mod PRIVATE -fopenmp)
target_link_libraries(demo_imagebind_1mod PUBLIC MLLM_CPU -fopenmp -static-openmp)
else ()
target_compile_options(demo_imagebind_1mod PRIVATE -fopenmp)
target_link_libraries(demo_imagebind_1mod PUBLIC MLLM_CPU -fopenmp)
endif ()
add_executable(demo_tinyllama ${PROJECT_SOURCE_DIR}/examples/demo_tinyllama.cpp ${DIR_SRC_CPU} ${DIR_SRC_MEM_MANAGER} ${DIR_SRC_EXP} ${DIR_SRC} # ${DIR_SRC_QUANT}
src/tokenizers/Tokenizer.cpp
src/tokenizers/Tokenizer.hpp
src/tokenizers/BPE/Bpe.cpp
src/tokenizers/BPE/Bpe.hpp
)
if (MLLM_OPENMP_STATIC)
target_compile_options(demo_tinyllama PRIVATE -fopenmp)
target_link_libraries(demo_tinyllama PUBLIC MLLM_CPU -fopenmp -static-openmp)
else ()
target_compile_options(demo_tinyllama PRIVATE -fopenmp)
target_link_libraries(demo_tinyllama PUBLIC MLLM_CPU -fopenmp)
endif ()
add_executable(demo_sparse_llama ${PROJECT_SOURCE_DIR}/examples/demo_sparse_llama.cpp ${DIR_SRC_CPU} ${DIR_SRC_MEM_MANAGER} ${DIR_SRC_EXP} ${DIR_SRC} # ${DIR_SRC_QUANT}
src/tokenizers/Tokenizer.cpp
src/tokenizers/Tokenizer.hpp
src/tokenizers/BPE/Bpe.cpp
src/tokenizers/BPE/Bpe.hpp
)
if (MLLM_OPENMP_STATIC)
target_compile_options(demo_sparse_llama PRIVATE -fopenmp)
target_link_libraries(demo_sparse_llama PUBLIC MLLM_CPU -fopenmp -static-openmp)
else ()
target_compile_options(demo_sparse_llama PRIVATE -fopenmp)
target_link_libraries(demo_sparse_llama PUBLIC MLLM_CPU -fopenmp)
endif ()
add_executable(demo_elastic_llama ${PROJECT_SOURCE_DIR}/examples/demo_elastic_llama.cpp ${DIR_SRC_CPU} ${DIR_SRC_MEM_MANAGER} ${DIR_SRC_EXP} ${DIR_SRC} # ${DIR_SRC_QUANT}
src/tokenizers/Tokenizer.cpp
src/tokenizers/Tokenizer.hpp
src/tokenizers/BPE/Bpe.cpp
src/tokenizers/BPE/Bpe.hpp
)
# target_compile_definitions(demo_elastic_llama PRIVATE MLLM_QKK_64)
if (MLLM_OPENMP_STATIC)
target_compile_options(demo_elastic_llama PRIVATE -fopenmp)
target_link_libraries(demo_elastic_llama PUBLIC MLLM_CPU -fopenmp -static-openmp)
else ()
target_compile_options(demo_elastic_llama PRIVATE -fopenmp)
target_link_libraries(demo_elastic_llama PUBLIC MLLM_CPU -fopenmp)
endif ()
add_executable(demo_llava ${PROJECT_SOURCE_DIR}/examples/demo_llava.cpp ${DIR_SRC_CPU} ${DIR_SRC_MEM_MANAGER} ${DIR_SRC_EXP} ${DIR_SRC}
src/tokenizers/Tokenizer.cpp
src/tokenizers/BPE/Bpe.cpp
src/processor/PreProcess.cpp
src/processor/ClipPreProcess.cpp
)
if (MLLM_OPENMP_STATIC)
target_compile_options(demo_llava PRIVATE -fopenmp)
target_link_libraries(demo_llava PUBLIC MLLM_CPU -fopenmp -static-openmp)
else ()
target_compile_options(demo_llava PRIVATE -fopenmp)
target_link_libraries(demo_llava PUBLIC MLLM_CPU -fopenmp)
endif ()
add_executable(demo_gemma ${PROJECT_SOURCE_DIR}/examples/demo_gemma.cpp ${DIR_SRC_CPU} ${DIR_SRC_MEM_MANAGER} ${DIR_SRC_EXP} ${DIR_SRC}
src/tokenizers/Tokenizer.cpp
src/tokenizers/BPE/Bpe.cpp
src/processor/PreProcess.cpp
)
if (MLLM_OPENMP_STATIC)
target_compile_options(demo_gemma PRIVATE -fopenmp)
target_link_libraries(demo_gemma PUBLIC MLLM_CPU -fopenmp -static-openmp)
else ()
target_compile_options(demo_gemma PRIVATE -fopenmp)
target_link_libraries(demo_gemma PUBLIC MLLM_CPU -fopenmp)
endif ()
add_executable(demo_qwen ${PROJECT_SOURCE_DIR}/examples/demo_qwen.cpp ${DIR_SRC_CPU} ${DIR_SRC_MEM_MANAGER} ${DIR_SRC_EXP} ${DIR_SRC}
src/tokenizers/Tokenizer.cpp
src/tokenizers/BPE/Bpe.cpp
src/tokenizers/Unicode.cpp
src/tokenizers/UnicodeData.cpp
src/processor/PreProcess.cpp
)
if (MLLM_OPENMP_STATIC)
target_compile_options(demo_qwen PRIVATE -fopenmp)
target_link_libraries(demo_qwen PUBLIC MLLM_CPU -fopenmp -static-openmp)
else ()
# target_link_libraries(demo_qwen PUBLIC MLLM_CPU)
target_compile_options(demo_qwen PRIVATE -fopenmp)
target_link_libraries(demo_qwen PUBLIC MLLM_CPU -fopenmp)
endif ()
add_executable(demo_mistral ${PROJECT_SOURCE_DIR}/examples/demo_mistral.cpp ${DIR_SRC_CPU} ${DIR_SRC_MEM_MANAGER} ${DIR_SRC_EXP} ${DIR_SRC}
src/tokenizers/Tokenizer.cpp
src/tokenizers/BPE/Bpe.cpp
src/processor/PreProcess.cpp
)
if (MLLM_OPENMP_STATIC)
target_compile_options(demo_mistral PRIVATE -fopenmp)
target_link_libraries(demo_mistral PUBLIC MLLM_CPU -fopenmp -static-openmp)
else ()
target_compile_options(demo_mistral PRIVATE -fopenmp)
target_link_libraries(demo_mistral PUBLIC MLLM_CPU -fopenmp)
endif ()
add_executable(demo_yi ${PROJECT_SOURCE_DIR}/examples/demo_yi.cpp ${DIR_SRC_CPU} ${DIR_SRC_MEM_MANAGER} ${DIR_SRC_EXP} ${DIR_SRC}
src/tokenizers/Tokenizer.cpp
src/tokenizers/BPE/Bpe.cpp
src/processor/PreProcess.cpp
)
if (MLLM_OPENMP_STATIC)
target_compile_options(demo_yi PRIVATE -fopenmp)
target_link_libraries(demo_yi PUBLIC MLLM_CPU -fopenmp -static-openmp)
else ()
target_compile_options(demo_yi PRIVATE -fopenmp)
target_link_libraries(demo_yi PUBLIC MLLM_CPU -fopenmp)
endif ()
add_executable(demo_opt ${PROJECT_SOURCE_DIR}/examples/demo_opt.cpp ${DIR_SRC_CPU} ${DIR_SRC_MEM_MANAGER} ${DIR_SRC_EXP} ${DIR_SRC}
src/tokenizers/Tokenizer.cpp
src/tokenizers/BPE/Bpe.cpp
)
if (MLLM_OPENMP_STATIC)
target_compile_options(demo_opt PRIVATE -fopenmp)
target_link_libraries(demo_opt PUBLIC MLLM_CPU -fopenmp -static-openmp)
else ()
target_compile_options(demo_opt PRIVATE -fopenmp)
target_link_libraries(demo_opt PUBLIC MLLM_CPU -fopenmp)
endif ()
add_executable(demo_phi3 ${PROJECT_SOURCE_DIR}/examples/demo_phi3.cpp ${DIR_SRC_CPU} ${DIR_SRC_MEM_MANAGER} ${DIR_SRC_EXP} ${DIR_SRC}
src/tokenizers/Tokenizer.cpp
src/tokenizers/BPE/Bpe.cpp
)
if (MLLM_OPENMP_STATIC)
target_compile_options(demo_phi3 PRIVATE -fopenmp)
target_link_libraries(demo_phi3 PUBLIC MLLM_CPU -fopenmp -static-openmp)
else ()
target_compile_options(demo_phi3 PRIVATE -fopenmp)
target_link_libraries(demo_phi3 PUBLIC MLLM_CPU -fopenmp)
endif ()
add_executable(demo_minicpm ${PROJECT_SOURCE_DIR}/examples/demo_minicpm.cpp ${DIR_SRC_CPU} ${DIR_SRC_MEM_MANAGER} ${DIR_SRC_EXP} ${DIR_SRC}
src/tokenizers/Tokenizer.cpp
src/tokenizers/BPE/Bpe.cpp
src/processor/PreProcess.cpp
)
if (ARM AND NOT APK)
target_compile_options(demo_minicpm PRIVATE -fopenmp)
target_link_libraries(demo_minicpm PUBLIC MLLM_CPU -fopenmp -static-openmp)
else ()
target_compile_options(demo_minicpm PRIVATE -fopenmp)
target_link_libraries(demo_minicpm PUBLIC MLLM_CPU -fopenmp)
endif ()
# add_executable(demo_deepseek ${PROJECT_SOURCE_DIR}/examples/demo_deepseek.cpp ${DIR_SRC_CPU} ${DIR_SRC_MEM_MANAGER} ${DIR_SRC_EXP} ${DIR_SRC}
# src/tokenizers/Tokenizer.cpp
# src/tokenizers/BPE/Bpe.cpp
# src/processor/PreProcess.cpp
# )
# if (MLLM_OPENMP_STATIC)
# target_compile_options(demo_deepseek PRIVATE -fopenmp)
# target_link_libraries(demo_deepseek PUBLIC MLLM_CPU -fopenmp -static-openmp)
# else ()
# target_compile_options(demo_deepseek PRIVATE -fopenmp)
# target_link_libraries(demo_deepseek PUBLIC MLLM_CPU -fopenmp)
# endif ()
# add_executable(demo_xllm ${PROJECT_SOURCE_DIR}/examples/demo_xllm.cpp ${DIR_SRC_CPU} ${DIR_SRC_MEM_MANAGER} ${DIR_SRC_EXP} ${DIR_SRC}
# src/tokenizers/Tokenizer.cpp
# src/tokenizers/BPE/Bpe.cpp
# src/tokenizers/Unicode.cpp
# src/tokenizers/UnicodeData.cpp
# src/processor/PreProcess.cpp
# )
# if (MLLM_OPENMP_STATIC)
# target_compile_options(demo_xllm PRIVATE -fopenmp)
# target_link_libraries(demo_xllm PUBLIC MLLM_CPU -fopenmp -static-openmp)
# else ()
# target_compile_options(demo_xllm PRIVATE -fopenmp)
# target_link_libraries(demo_xllm PUBLIC MLLM_CPU -fopenmp)
# endif ()
endif() # end of cpu executables
# QNN demo
if(QNN)
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/src/backends/qnn)
# qnn executables
add_executable(main_qwen_npu ${PROJECT_SOURCE_DIR}/examples/main_qwen_npu.cpp ${DIR_SRC_CPU} ${DIR_SRC_MEM_MANAGER} ${DIR_SRC_EXP} ${DIR_SRC}
src/tokenizers/Tokenizer.cpp
src/tokenizers/Unicode.cpp
src/tokenizers/UnicodeData.cpp
src/tokenizers/BPE/Bpe.cpp
src/processor/PreProcess.cpp
)
target_compile_definitions(main_qwen_npu PRIVATE USE_QNN)
if (ARM)
target_compile_options(main_qwen_npu PRIVATE -fopenmp)
target_link_libraries(main_qwen_npu PUBLIC MLLM_CPU MLLM_QNN ${CMAKE_DL_LIBS} -fopenmp -static-openmp)
endif ()
endif()
if (APK)
add_library(mllm_lib STATIC ${DIR_SRC_CPU} ${DIR_SRC_EXP} ${DIR_SRC} ${DIR_SRC_MEM_MANAGER}
src/tokenizers/Tokenizer.cpp
src/tokenizers/Tokenizer.hpp
src/tokenizers/Unigram/Unigram.hpp
src/tokenizers/Unigram/Unigram.cpp
src/tokenizers/Unigram/trie.hpp
src/tokenizers/BPE/Bpe.cpp
src/tokenizers/BPE/Bpe.hpp
src/tokenizers/Unicode.cpp
src/tokenizers/UnicodeData.cpp
src/processor/PreProcess.hpp
src/processor/FuyuPreProcess.hpp
src/processor/FuyuPreProcess.cpp
tools/jni/LibHelper.cpp
tools/jni/LibHelper.hpp
tools/jni/modeling_llama.hpp
tools/jni/modeling_fuyu.hpp
tools/jni/helper.hpp
src/processor/PreProcess.cpp
)
target_link_libraries(mllm_lib MLLM_CPU)
endif ()