forked from flashinfer-ai/flashinfer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
668 lines (616 loc) · 30.8 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
cmake_minimum_required(VERSION 3.23.1)
project(flashinfer CUDA CXX)
include(cmake/utils/Utils.cmake)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CUDA_STANDARD 17)
if(EXISTS ${CMAKE_BINARY_DIR}/config.cmake)
include(${CMAKE_BINARY_DIR}/config.cmake)
else()
if(EXISTS ${CMAKE_SOURCE_DIR}/config.cmake)
include(${CMAKE_SOURCE_DIR}/config.cmake)
endif()
endif()
find_package(Python3 REQUIRED)
if(NOT Python3_FOUND)
message(FATAL_ERROR "Python3 not found.")
endif()
# NOTE: do not modify this file to change option values. You can create a
# config.cmake at build folder and add set(OPTION VALUE) to override these build
# options. Alernatively, use cmake -DOPTION=VALUE through command-line.
flashinfer_option(FLASHINFER_ENABLE_FP8
"Whether to compile fp8 kernels or not." ON)
flashinfer_option(FLASHINFER_ENABLE_BF16
"Whether to compile bf16 kernels or not." ON)
flashinfer_option(
FLASHINFER_PREFILL
"Whether to compile prefill kernel tests/benchmarks or not." OFF)
flashinfer_option(
FLASHINFER_DECODE "Whether to compile decode kernel tests/benchmarks or not."
OFF)
flashinfer_option(FLASHINFER_PAGE
"Whether to compile page kernel tests/benchmarks or not." OFF)
flashinfer_option(
FLASHINFER_CASCADE
"Whether to compile cascade kernel tests/benchmarks or not." OFF)
flashinfer_option(
FLASHINFER_SAMPLING
"Whether to compile sampling kernel tests/benchmarks or not." OFF)
flashinfer_option(
FLASHINFER_NORM
"Whether to compile normalization kernel tests/benchmarks or not." OFF)
flashinfer_option(
FLASHINFER_DISTRIBUTED
"Whether to compile distributed kernel tests/benchmarks or not." OFF)
flashinfer_option(FLASHINFER_FASTDIV_TEST
"Whether to compile fastdiv kernel tests or not." OFF)
flashinfer_option(FLASHINFER_FASTDEQAUNT_TEST
"Whether to compile fast dequant kernel tests or not." OFF)
flashinfer_option(FLASHINFER_TVM_BINDING
"Whether to compile tvm binding or not." OFF)
flashinfer_option(FLASHINFER_TVM_SOURCE_DIR
"The path to tvm for building tvm binding." "")
# The following configurations can impact the binary size of the generated
# library
flashinfer_option(FLASHINFER_GEN_HEAD_DIMS "Head dims to enable" 64 128 256)
flashinfer_option(FLASHINFER_GEN_POS_ENCODING_MODES "Pos encodings to enable" 0
1 2)
flashinfer_option(FLASHINFER_GEN_ALLOW_FP16_QK_REDUCTIONS
"QK reductions to enable" "false" "true")
flashinfer_option(FLASHINFER_GEN_MASK_MODES "Mask modes to enable" 0 1 2)
if(DEFINED FLASHINFER_CUDA_ARCHITECTURES)
message(
STATUS "CMAKE_CUDA_ARCHITECTURES set to ${FLASHINFER_CUDA_ARCHITECTURES}.")
set(CMAKE_CUDA_ARCHITECTURES ${FLASHINFER_CUDA_ARCHITECTURES})
else(DEFINED FLASHINFER_CUDA_ARCHITECTURES)
message(STATUS "CMAKE_CUDA_ARCHITECTURES is ${CMAKE_CUDA_ARCHITECTURES}")
endif(DEFINED FLASHINFER_CUDA_ARCHITECTURES)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
if(FLASHINFER_PREFILL
OR FLASHINFER_DECODE
OR FLASHINFER_PAGE
OR FLASHINFER_CASCADE
OR FLASHINFER_SAMPLING
OR FLASHINFER_NORM)
message(STATUS "NVBench and GoogleTest enabled")
add_subdirectory(3rdparty/nvbench)
if(FLASHINFER_DISTRIBUTED)
add_subdirectory(3rdparty/mscclpp)
else(FLASHINFER_DISTRIBUTED)
add_subdirectory(3rdparty/googletest)
endif(FLASHINFER_DISTRIBUTED)
endif(
FLASHINFER_PREFILL
OR FLASHINFER_DECODE
OR FLASHINFER_PAGE
OR FLASHINFER_CASCADE
OR FLASHINFER_SAMPLING
OR FLASHINFER_NORM)
find_package(Thrust REQUIRED)
set(FLASHINFER_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include)
if(FLASHINFER_ENABLE_FP8)
message(STATUS "Compile fp8 kernels.")
add_definitions(-DFLASHINFER_ENABLE_FP8)
endif(FLASHINFER_ENABLE_FP8)
if(FLASHINFER_ENABLE_BF16)
message(STATUS "Compile bf16 kernels.")
add_definitions(-DFLASHINFER_ENABLE_BF16)
endif(FLASHINFER_ENABLE_BF16)
# generate kernel inst
set(HEAD_DIMS ${FLASHINFER_GEN_HEAD_DIMS})
set(POS_ENCODING_MODES ${FLASHINFER_GEN_POS_ENCODING_MODES})
set(ALLOW_FP16_QK_REDUCTIONS ${FLASHINFER_GEN_ALLOW_FP16_QK_REDUCTIONS})
set(MASK_MODES ${FLASHINFER_GEN_MASK_MODES})
set(DECODE_DTYPES "f16")
set(PREFILL_DTYPES "f16")
set(DECODE_FP8_DTYPES)
set(IDTYPES "i32")
if(FLASHINFER_ENABLE_FP8)
list(APPEND DECODE_DTYPES "e4m3" "e5m2")
list(APPEND DECODE_FP8_DTYPES "e4m3" "e5m2")
list(APPEND PREFILL_FP8_DTYPES "e4m3" "e5m2")
endif(FLASHINFER_ENABLE_FP8)
if(FLASHINFER_ENABLE_BF16)
list(APPEND DECODE_DTYPES "bf16")
list(APPEND PREFILL_DTYPES "bf16")
endif(FLASHINFER_ENABLE_BF16)
# log options
message(STATUS "FLASHINFER_HEAD_DIMS=${HEAD_DIMS}")
message(STATUS "FLASHINFER_POS_ENCODING_MODES=${POS_ENCODING_MODES}")
message(
STATUS "FLASHINFER_ALLOW_FP16_QK_REDUCTIONS=${ALLOW_FP16_QK_REDUCTIONS}")
message(STATUS "FLASHINFER_MASK_MODES=${MASK_MODES}")
file(MAKE_DIRECTORY ${PROJECT_SOURCE_DIR}/src/generated)
set(dispatch_inc_file ${PROJECT_SOURCE_DIR}/src/dispatch.inc)
add_custom_command(
OUTPUT ${dispatch_inc_file}
COMMAND
${Python3_EXECUTABLE}
${PROJECT_SOURCE_DIR}/python/_aot_build_utils/generate_dispatch_inc.py
--path ${PROJECT_SOURCE_DIR}/src/dispatch.inc --head_dims ${HEAD_DIMS}
--pos_encoding_modes ${POS_ENCODING_MODES} --allow_fp16_qk_reductions
${ALLOW_FP16_QK_REDUCTIONS} --mask_modes ${MASK_MODES}
DEPENDS ${PROJECT_SOURCE_DIR}/python/_aot_build_utils/generate_dispatch_inc.py
COMMENT "Generating additional source file ${generated_dispatch_inc}"
VERBATIM)
add_custom_target(dispatch_inc DEPENDS ${dispatch_inc_file})
# single decode kernel inst generation
foreach(head_dim IN LISTS HEAD_DIMS)
foreach(pos_encoding_mode IN LISTS POS_ENCODING_MODES)
foreach(dtype IN LISTS DECODE_DTYPES)
set(generated_kernel_src
${PROJECT_SOURCE_DIR}/src/generated/single_decode_head_${head_dim}_posenc_${pos_encoding_mode}_dtypeq_${dtype}_dtypekv_${dtype}_dtypeout_${dtype}.cu
)
add_custom_command(
OUTPUT ${generated_kernel_src}
COMMAND
${Python3_EXECUTABLE}
${PROJECT_SOURCE_DIR}/python/_aot_build_utils/generate_single_decode_inst.py
${generated_kernel_src}
DEPENDS
${PROJECT_SOURCE_DIR}/python/_aot_build_utils/generate_single_decode_inst.py
COMMENT "Generating additional source file ${generated_kernel_src}"
VERBATIM)
list(APPEND single_decode_kernels_src ${generated_kernel_src})
endforeach(dtype)
# fp8 kv-cache
foreach(dtype_kv IN LISTS DECODE_FP8_DTYPES)
set(generated_kernel_src
${PROJECT_SOURCE_DIR}/src/generated/single_decode_head_${head_dim}_posenc_${pos_encoding_mode}_dtypeq_f16_dtypekv_${dtype_kv}_dtypeout_f16.cu
)
add_custom_command(
OUTPUT ${generated_kernel_src}
COMMAND
${Python3_EXECUTABLE}
${PROJECT_SOURCE_DIR}/python/_aot_build_utils/generate_single_decode_inst.py
${generated_kernel_src}
DEPENDS
${PROJECT_SOURCE_DIR}/python/_aot_build_utils/generate_single_decode_inst.py
COMMENT "Generating additional source file ${generated_kernel_src}"
VERBATIM)
list(APPEND single_decode_kernels_src ${generated_kernel_src})
endforeach(dtype_kv)
endforeach(pos_encoding_mode)
endforeach(head_dim)
# batch decode kernel inst generation
foreach(head_dim IN LISTS HEAD_DIMS)
foreach(pos_encoding_mode IN LISTS POS_ENCODING_MODES)
# paged kv-cache
foreach(idtype IN LISTS IDTYPES)
foreach(dtype IN LISTS DECODE_DTYPES)
set(generated_kernel_src
${PROJECT_SOURCE_DIR}/src/generated/batch_paged_decode_head_${head_dim}_posenc_${pos_encoding_mode}_dtypeq_${dtype}_dtypekv_${dtype}_dtypeout_${dtype}_idtype_${idtype}.cu
)
add_custom_command(
OUTPUT ${generated_kernel_src}
COMMAND
${Python3_EXECUTABLE}
${PROJECT_SOURCE_DIR}/python/_aot_build_utils/generate_batch_paged_decode_inst.py
${generated_kernel_src}
DEPENDS
${PROJECT_SOURCE_DIR}/python/_aot_build_utils/generate_batch_paged_decode_inst.py
COMMENT "Generating additional source file ${generated_kernel_src}"
VERBATIM)
list(APPEND batch_decode_kernels_src ${generated_kernel_src})
endforeach(dtype)
# fp8 kv-cache
foreach(dtype_kv IN LISTS DECODE_FP8_DTYPES)
set(generated_kernel_src
${PROJECT_SOURCE_DIR}/src/generated/batch_paged_decode_head_${head_dim}_posenc_${pos_encoding_mode}_dtypeq_f16_dtypekv_${dtype_kv}_dtypeout_f16_idtype_${idtype}.cu
)
add_custom_command(
OUTPUT ${generated_kernel_src}
COMMAND
${Python3_EXECUTABLE}
${PROJECT_SOURCE_DIR}/python/_aot_build_utils/generate_batch_paged_decode_inst.py
${generated_kernel_src}
DEPENDS
${PROJECT_SOURCE_DIR}/python/_aot_build_utils/generate_batch_paged_decode_inst.py
COMMENT "Generating additional source file ${generated_kernel_src}"
VERBATIM)
list(APPEND batch_decode_kernels_src ${generated_kernel_src})
endforeach(dtype_kv)
endforeach(idtype)
endforeach(pos_encoding_mode)
endforeach(head_dim)
add_library(decode_kernels STATIC ${single_decode_kernels_src}
${batch_decode_kernels_src})
target_include_directories(decode_kernels PRIVATE ${FLASHINFER_INCLUDE_DIR})
target_compile_options(decode_kernels PRIVATE -Xcompiler=-fPIC --fatbin-options
-compress-all)
# single prefill kernel inst generation
foreach(head_dim IN LISTS HEAD_DIMS)
foreach(pos_encoding_mode IN LISTS POS_ENCODING_MODES)
foreach(allow_fp16_qk_reduction IN LISTS ALLOW_FP16_QK_REDUCTIONS)
foreach(mask_mode IN LISTS MASK_MODES)
foreach(dtype IN LISTS PREFILL_DTYPES)
set(generated_kernel_src
${PROJECT_SOURCE_DIR}/src/generated/single_prefill_head_${head_dim}_posenc_${pos_encoding_mode}_fp16qkred_${allow_fp16_qk_reduction}_mask_${mask_mode}_dtypeq_${dtype}_dtypekv_${dtype}_dtypeout_${dtype}.cu
)
add_custom_command(
OUTPUT ${generated_kernel_src}
COMMAND
${Python3_EXECUTABLE}
${PROJECT_SOURCE_DIR}/python/_aot_build_utils/generate_single_prefill_inst.py
${generated_kernel_src}
DEPENDS
${PROJECT_SOURCE_DIR}/python/_aot_build_utils/generate_single_prefill_inst.py
COMMENT "Generating additional source file ${generated_kernel_src}"
VERBATIM)
list(APPEND single_prefill_kernels_src ${generated_kernel_src})
endforeach(dtype)
foreach(dtype_kv IN LISTS PREFILL_FP8_DTYPES)
set(generated_kernel_src
${PROJECT_SOURCE_DIR}/src/generated/single_prefill_head_${head_dim}_posenc_${pos_encoding_mode}_fp16qkred_${allow_fp16_qk_reduction}_mask_${mask_mode}_dtypeq_f16_dtypekv_${dtype_kv}_dtypeout_f16.cu
)
add_custom_command(
OUTPUT ${generated_kernel_src}
COMMAND
${Python3_EXECUTABLE}
${PROJECT_SOURCE_DIR}/python/_aot_build_utils/generate_single_prefill_inst.py
${generated_kernel_src}
DEPENDS
${PROJECT_SOURCE_DIR}/python/_aot_build_utils/generate_single_prefill_inst.py
COMMENT "Generating additional source file ${generated_kernel_src}"
VERBATIM)
list(APPEND single_prefill_kernels_src ${generated_kernel_src})
endforeach(dtype_kv)
endforeach(mask_mode)
endforeach(allow_fp16_qk_reduction)
endforeach(pos_encoding_mode)
endforeach(head_dim)
# batch paged prefill kernel inst generation
foreach(head_dim IN LISTS HEAD_DIMS)
foreach(pos_encoding_mode IN LISTS POS_ENCODING_MODES)
foreach(allow_fp16_qk_reduction IN LISTS ALLOW_FP16_QK_REDUCTIONS)
foreach(mask_mode IN LISTS MASK_MODES)
foreach(idtype IN LISTS IDTYPES)
foreach(dtype IN LISTS PREFILL_DTYPES)
set(generated_kernel_src
${PROJECT_SOURCE_DIR}/src/generated/batch_paged_prefill_head_${head_dim}_posenc_${pos_encoding_mode}_fp16qkred_${allow_fp16_qk_reduction}_mask_${mask_mode}_dtypeq_${dtype}_dtypekv_${dtype}_dtypeout_${dtype}_idtype_${idtype}.cu
)
add_custom_command(
OUTPUT ${generated_kernel_src}
COMMAND
${Python3_EXECUTABLE}
${PROJECT_SOURCE_DIR}/python/_aot_build_utils/generate_batch_paged_prefill_inst.py
${generated_kernel_src}
DEPENDS
${PROJECT_SOURCE_DIR}/python/_aot_build_utils/generate_batch_paged_prefill_inst.py
COMMENT
"Generating additional source file ${generated_kernel_src}"
VERBATIM)
list(APPEND batch_paged_prefill_kernels_src ${generated_kernel_src})
endforeach(dtype)
foreach(dtype_kv IN LISTS PREFILL_FP8_DTYPES)
set(generated_kernel_src
${PROJECT_SOURCE_DIR}/src/generated/batch_paged_prefill_head_${head_dim}_posenc_${pos_encoding_mode}_fp16qkred_${allow_fp16_qk_reduction}_mask_${mask_mode}_dtypeq_f16_dtypekv_${dtype_kv}_dtypeout_f16_idtype_${idtype}.cu
)
add_custom_command(
OUTPUT ${generated_kernel_src}
COMMAND
${Python3_EXECUTABLE}
${PROJECT_SOURCE_DIR}/python/_aot_build_utils/generate_batch_paged_prefill_inst.py
${generated_kernel_src}
DEPENDS
${PROJECT_SOURCE_DIR}/python/_aot_build_utils/generate_batch_paged_prefill_inst.py
COMMENT
"Generating additional source file ${generated_kernel_src}"
VERBATIM)
list(APPEND batch_paged_prefill_kernels_src ${generated_kernel_src})
endforeach(dtype_kv)
endforeach(idtype)
endforeach(mask_mode)
endforeach(allow_fp16_qk_reduction)
endforeach(pos_encoding_mode)
endforeach(head_dim)
# batch ragged prefill kernel inst generation
foreach(head_dim IN LISTS HEAD_DIMS)
foreach(pos_encoding_mode IN LISTS POS_ENCODING_MODES)
foreach(allow_fp16_qk_reduction IN LISTS ALLOW_FP16_QK_REDUCTIONS)
foreach(mask_mode IN LISTS MASK_MODES)
foreach(idtype IN LISTS IDTYPES)
foreach(dtype IN LISTS PREFILL_DTYPES)
set(generated_kernel_src
${PROJECT_SOURCE_DIR}/src/generated/batch_ragged_prefill_head_${head_dim}_posenc_${pos_encoding_mode}_fp16qkred_${allow_fp16_qk_reduction}_mask_${mask_mode}_dtypeq_${dtype}_dtypekv_${dtype}_dtypeout_${dtype}_idtype_${idtype}.cu
)
add_custom_command(
OUTPUT ${generated_kernel_src}
COMMAND
${Python3_EXECUTABLE}
${PROJECT_SOURCE_DIR}/python/_aot_build_utils/generate_batch_ragged_prefill_inst.py
${generated_kernel_src}
DEPENDS
${PROJECT_SOURCE_DIR}/python/_aot_build_utils/generate_batch_ragged_prefill_inst.py
COMMENT
"Generating additional source file ${generated_kernel_src}"
VERBATIM)
list(APPEND batch_ragged_prefill_kernels_src
${generated_kernel_src})
endforeach(dtype)
foreach(dtype_kv IN LISTS PREFILL_FP8_DTYPES)
set(generated_kernel_src
${PROJECT_SOURCE_DIR}/src/generated/batch_ragged_prefill_head_${head_dim}_posenc_${pos_encoding_mode}_fp16qkred_${allow_fp16_qk_reduction}_mask_${mask_mode}_dtypeq_f16_dtypekv_${dtype_kv}_dtypeout_f16_idtype_${idtype}.cu
)
add_custom_command(
OUTPUT ${generated_kernel_src}
COMMAND
${Python3_EXECUTABLE}
${PROJECT_SOURCE_DIR}/python/_aot_build_utils/generate_batch_ragged_prefill_inst.py
${generated_kernel_src}
DEPENDS
${PROJECT_SOURCE_DIR}/python/_aot_build_utils/generate_batch_ragged_prefill_inst.py
COMMENT
"Generating additional source file ${generated_kernel_src}"
VERBATIM)
list(APPEND batch_ragged_prefill_kernels_src
${generated_kernel_src})
endforeach(dtype_kv)
endforeach(idtype)
endforeach(mask_mode)
endforeach(allow_fp16_qk_reduction)
endforeach(pos_encoding_mode)
endforeach(head_dim)
add_library(
prefill_kernels STATIC
${single_prefill_kernels_src} ${batch_paged_prefill_kernels_src}
${batch_ragged_prefill_kernels_src})
target_include_directories(prefill_kernels PRIVATE ${FLASHINFER_INCLUDE_DIR})
target_compile_options(prefill_kernels PRIVATE -Xcompiler=-fPIC
--fatbin-options -compress-all)
if(FLASHINFER_DECODE)
message(STATUS "Compile single decode kernel benchmarks.")
file(GLOB_RECURSE BENCH_DECODE_SRCS
${PROJECT_SOURCE_DIR}/src/bench_single_decode.cu)
add_executable(bench_single_decode ${BENCH_DECODE_SRCS})
target_include_directories(bench_single_decode
PRIVATE ${FLASHINFER_INCLUDE_DIR})
target_include_directories(bench_single_decode
PRIVATE ${PROJECT_SOURCE_DIR}/3rdparty/nvbench)
add_dependencies(bench_single_decode dispatch_inc)
target_link_libraries(bench_single_decode
PRIVATE nvbench::main decode_kernels prefill_kernels)
target_compile_options(bench_single_decode PRIVATE -Wno-switch-bool)
message(STATUS "Compile single decode kernel tests.")
file(GLOB_RECURSE TEST_DECODE_SRCS
${PROJECT_SOURCE_DIR}/src/test_single_decode.cu)
add_executable(test_single_decode ${TEST_DECODE_SRCS})
target_include_directories(test_single_decode
PRIVATE ${FLASHINFER_INCLUDE_DIR})
target_include_directories(
test_single_decode PRIVATE ${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR})
add_dependencies(test_single_decode dispatch_inc)
target_link_libraries(test_single_decode PRIVATE gtest gtest_main
decode_kernels)
target_compile_options(test_single_decode PRIVATE -Wno-switch-bool)
message(STATUS "Compile batch decode kernel benchmarks.")
file(GLOB_RECURSE BENCH_DECODE_SRCS
${PROJECT_SOURCE_DIR}/src/bench_batch_decode.cu)
add_executable(bench_batch_decode ${BENCH_DECODE_SRCS})
target_include_directories(bench_batch_decode
PRIVATE ${FLASHINFER_INCLUDE_DIR})
target_include_directories(bench_batch_decode
PRIVATE ${PROJECT_SOURCE_DIR}/3rdparty/nvbench)
add_dependencies(bench_batch_decode dispatch_inc)
target_link_libraries(bench_batch_decode PRIVATE nvbench::main decode_kernels
prefill_kernels)
target_compile_options(bench_batch_decode PRIVATE -Wno-switch-bool)
message(STATUS "Compile batch mla decode kernel benchmarks.")
file(GLOB_RECURSE BENCH_DECODE_MLA_SRCS
${PROJECT_SOURCE_DIR}/src/bench_batch_decode_mla.cu)
add_executable(bench_batch_decode_mla ${BENCH_DECODE_MLA_SRCS})
target_include_directories(bench_batch_decode_mla
PRIVATE ${FLASHINFER_INCLUDE_DIR})
target_include_directories(bench_batch_decode_mla
PRIVATE ${PROJECT_SOURCE_DIR}/3rdparty/nvbench)
add_dependencies(bench_batch_decode_mla dispatch_inc)
target_link_libraries(bench_batch_decode_mla PRIVATE nvbench::main
decode_kernels)
target_compile_options(bench_batch_decode_mla PRIVATE -Wno-switch-bool)
message(STATUS "Compile batch decode kernel tests.")
file(GLOB_RECURSE TEST_DECODE_SRCS
${PROJECT_SOURCE_DIR}/src/test_batch_decode.cu)
add_executable(test_batch_decode ${TEST_DECODE_SRCS})
target_include_directories(test_batch_decode
PRIVATE ${FLASHINFER_INCLUDE_DIR})
target_include_directories(
test_batch_decode PRIVATE ${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR})
add_dependencies(test_batch_decode dispatch_inc)
target_link_libraries(test_batch_decode PRIVATE gtest gtest_main
decode_kernels)
target_compile_options(test_batch_decode PRIVATE -Wno-switch-bool)
endif(FLASHINFER_DECODE)
if(FLASHINFER_PREFILL)
message(STATUS "Compile single prefill kernel benchmarks")
file(GLOB_RECURSE BENCH_PREFILL_SRCS
${PROJECT_SOURCE_DIR}/src/bench_single_prefill.cu)
add_executable(bench_single_prefill ${BENCH_PREFILL_SRCS})
target_include_directories(bench_single_prefill
PRIVATE ${FLASHINFER_INCLUDE_DIR})
target_include_directories(bench_single_prefill
PRIVATE ${PROJECT_SOURCE_DIR}/3rdparty/nvbench)
add_dependencies(bench_single_prefill dispatch_inc)
target_link_libraries(bench_single_prefill PRIVATE nvbench::main
prefill_kernels)
target_compile_options(bench_single_prefill PRIVATE -Wno-switch-bool)
message(STATUS "Compile single prefill kernel tests.")
file(GLOB_RECURSE TEST_PREFILL_SRCS
${PROJECT_SOURCE_DIR}/src/test_single_prefill.cu)
add_executable(test_single_prefill ${TEST_PREFILL_SRCS})
target_include_directories(test_single_prefill
PRIVATE ${FLASHINFER_INCLUDE_DIR})
target_include_directories(
test_single_prefill PRIVATE ${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR})
add_dependencies(test_single_prefill dispatch_inc)
target_link_libraries(test_single_prefill PRIVATE gtest gtest_main
prefill_kernels)
target_compile_options(test_single_prefill PRIVATE -Wno-switch-bool)
message(STATUS "Compile batch prefill kernel benchmarks.")
file(GLOB_RECURSE BENCH_PREFILL_SRCS
${PROJECT_SOURCE_DIR}/src/bench_batch_prefill.cu)
add_executable(bench_batch_prefill ${BENCH_PREFILL_SRCS})
target_include_directories(bench_batch_prefill
PRIVATE ${FLASHINFER_INCLUDE_DIR})
target_include_directories(bench_batch_prefill
PRIVATE ${PROJECT_SOURCE_DIR}/3rdparty/nvbench)
add_dependencies(bench_batch_prefill dispatch_inc)
target_link_libraries(bench_batch_prefill PRIVATE nvbench::main
prefill_kernels)
target_compile_options(bench_batch_prefill PRIVATE -Wno-switch-bool)
message(STATUS "Compile batch prefill kernel tests.")
file(GLOB_RECURSE TEST_PREFILL_SRCS
${PROJECT_SOURCE_DIR}/src/test_batch_prefill.cu)
add_executable(test_batch_prefill ${TEST_PREFILL_SRCS})
target_include_directories(test_batch_prefill
PRIVATE ${FLASHINFER_INCLUDE_DIR})
target_include_directories(
test_batch_prefill PRIVATE ${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR})
add_dependencies(test_batch_prefill dispatch_inc)
target_link_libraries(test_batch_prefill PRIVATE gtest gtest_main
prefill_kernels)
target_compile_options(test_batch_prefill PRIVATE -Wno-switch-bool)
endif(FLASHINFER_PREFILL)
if(FLASHINFER_PAGE)
message(STATUS "Compile page kernel tests.")
file(GLOB_RECURSE TEST_PAGE_SRCS ${PROJECT_SOURCE_DIR}/src/test_page.cu)
add_executable(test_page ${TEST_PAGE_SRCS})
target_include_directories(test_page PRIVATE ${FLASHINFER_INCLUDE_DIR})
target_include_directories(test_page PRIVATE ${gtest_SOURCE_DIR}/include
${gtest_SOURCE_DIR})
target_link_libraries(test_page PRIVATE gtest gtest_main)
target_compile_options(test_page PRIVATE -Wno-switch-bool)
endif(FLASHINFER_PAGE)
if(FLASHINFER_CASCADE)
message(STATUS "Compile cascade kernel benchmarks.")
file(GLOB_RECURSE BENCH_CASCADE_SRCS
${PROJECT_SOURCE_DIR}/src/bench_cascade.cu)
add_executable(bench_cascade ${BENCH_CASCADE_SRCS})
target_include_directories(bench_cascade PRIVATE ${FLASHINFER_INCLUDE_DIR})
target_include_directories(bench_cascade
PRIVATE ${PROJECT_SOURCE_DIR}/3rdparty/nvbench)
add_dependencies(bench_cascade dispatch_inc)
target_link_libraries(bench_cascade PRIVATE nvbench::main decode_kernels
prefill_kernels)
target_compile_options(bench_cascade PRIVATE -Wno-switch-bool)
message(STATUS "Compile cascade kernel tests.")
file(GLOB_RECURSE TEST_CASCADE_SRCS ${PROJECT_SOURCE_DIR}/src/test_cascade.cu)
add_executable(test_cascade ${TEST_CASCADE_SRCS})
target_include_directories(test_cascade PRIVATE ${FLASHINFER_INCLUDE_DIR})
target_include_directories(test_cascade PRIVATE ${gtest_SOURCE_DIR}/include
${gtest_SOURCE_DIR})
add_dependencies(test_cascade dispatch_inc)
target_link_libraries(test_cascade PRIVATE gtest gtest_main decode_kernels
prefill_kernels)
target_compile_options(test_cascade PRIVATE -Wno-switch-bool)
endif(FLASHINFER_CASCADE)
if(FLASHINFER_SAMPLING)
message(STATUS "Compile sampling kernel benchmarks.")
file(GLOB_RECURSE BENCH_SAMPLING_SRCS
${PROJECT_SOURCE_DIR}/src/bench_sampling.cu)
add_executable(bench_sampling ${BENCH_SAMPLING_SRCS})
target_include_directories(bench_sampling PRIVATE ${FLASHINFER_INCLUDE_DIR})
target_include_directories(bench_sampling
PRIVATE ${PROJECT_SOURCE_DIR}/3rdparty/nvbench)
target_link_libraries(bench_sampling PRIVATE nvbench::main)
target_compile_options(bench_sampling PRIVATE -Wno-switch-bool)
message(STATUS "Compile sampling kernel tests.")
file(GLOB_RECURSE TEST_SAMPLING_SRCS
${PROJECT_SOURCE_DIR}/src/test_sampling.cu)
add_executable(test_sampling ${TEST_SAMPLING_SRCS})
target_include_directories(test_sampling PRIVATE ${FLASHINFER_INCLUDE_DIR})
target_include_directories(test_sampling PRIVATE ${gtest_SOURCE_DIR}/include
${gtest_SOURCE_DIR})
target_link_libraries(test_sampling PRIVATE gtest gtest_main)
target_compile_options(test_sampling PRIVATE -Wno-switch-bool)
endif(FLASHINFER_SAMPLING)
if(FLASHINFER_NORM)
message(STATUS "Compile normalization kernel benchmarks.")
file(GLOB_RECURSE BENCH_NORM_SRCS ${PROJECT_SOURCE_DIR}/src/bench_norm.cu)
add_executable(bench_norm ${BENCH_NORM_SRCS})
target_include_directories(bench_norm PRIVATE ${FLASHINFER_INCLUDE_DIR})
target_include_directories(bench_norm
PRIVATE ${PROJECT_SOURCE_DIR}/3rdparty/nvbench)
target_link_libraries(bench_norm PRIVATE nvbench::main)
target_compile_options(bench_norm PRIVATE -Wno-switch-bool)
message(STATUS "Compile normalization kernel tests.")
file(GLOB_RECURSE TEST_NORM_SRCS ${PROJECT_SOURCE_DIR}/src/test_norm.cu)
add_executable(test_norm ${TEST_NORM_SRCS})
target_include_directories(test_norm PRIVATE ${FLASHINFER_INCLUDE_DIR})
target_include_directories(test_norm PRIVATE ${gtest_SOURCE_DIR}/include
${gtest_SOURCE_DIR})
target_link_libraries(test_norm PRIVATE gtest gtest_main)
target_compile_options(test_norm PRIVATE -Wno-switch-bool)
endif(FLASHINFER_NORM)
if(FLASHINFER_TVM_BINDING)
message(STATUS "Compile tvm binding.")
if(NOT FLASHINFER_TVM_SOURCE_DIR STREQUAL "")
set(TVM_SOURCE_DIR_SET ${FLASHINFER_TVM_SOURCE_DIR})
elseif(DEFINED ENV{TVM_SOURCE_DIR})
set(TVM_SOURCE_DIR_SET $ENV{TVM_SOURCE_DIR})
elseif(DEFINED ENV{TVM_HOME}) # for backward compatibility
set(TVM_SOURCE_DIR_SET $ENV{TVM_HOME})
else()
message(
FATAL_ERROR
"Error: Cannot find TVM. Please set the path to TVM by 1) adding `-DFLASHINFER_TVM_SOURCE_DIR=path/to/tvm` in the cmake command, or 2) setting the environment variable `TVM_SOURCE_DIR` to the tvm path."
)
endif()
message(STATUS "FlashInfer uses TVM home ${TVM_SOURCE_DIR_SET}.")
file(GLOB_RECURSE TVM_BINDING_SRCS ${PROJECT_SOURCE_DIR}/src/tvm_wrapper.cu)
add_library(flashinfer_tvm OBJECT ${TVM_BINDING_SRCS})
target_compile_definitions(flashinfer_tvm PRIVATE -DDMLC_USE_LOGGING_LIBRARY=
\<tvm/runtime/logging.h\>)
target_link_libraries(flashinfer_tvm PRIVATE decode_kernels prefill_kernels)
target_include_directories(flashinfer_tvm PRIVATE ${FLASHINFER_INCLUDE_DIR})
target_include_directories(flashinfer_tvm
PRIVATE ${TVM_SOURCE_DIR_SET}/include)
target_include_directories(
flashinfer_tvm PRIVATE ${TVM_SOURCE_DIR_SET}/3rdparty/dlpack/include)
target_include_directories(
flashinfer_tvm PRIVATE ${TVM_SOURCE_DIR_SET}/3rdparty/dmlc-core/include)
add_dependencies(flashinfer_tvm dispatch_inc)
target_compile_options(flashinfer_tvm PRIVATE -Xcompiler=-fPIC -diag-suppress
"1305" -Wno-switch-bool)
endif(FLASHINFER_TVM_BINDING)
if(FLASHINFER_FASTDIV_TEST)
message(STATUS "Compile fastdiv test.")
file(GLOB_RECURSE TEST_FASTDIV_SRCS ${PROJECT_SOURCE_DIR}/src/test_fastdiv.cu)
add_executable(test_fastdiv ${TEST_FASTDIV_SRCS})
target_include_directories(test_fastdiv PRIVATE ${FLASHINFER_INCLUDE_DIR})
target_include_directories(test_fastdiv PRIVATE ${gtest_SOURCE_DIR}/include
${gtest_SOURCE_DIR})
target_link_libraries(test_fastdiv PRIVATE gtest gtest_main)
endif(FLASHINFER_FASTDIV_TEST)
if(FLASHINFER_FASTDEQUANT_TEST)
message(STATUS "Compile fast dequant test.")
file(GLOB_RECURSE TEST_FAST_DEQUANT_SRCS
${PROJECT_SOURCE_DIR}/src/test_fast_dequant.cu)
add_executable(test_fast_dequant ${TEST_FAST_DEQUANT_SRCS})
target_include_directories(test_fast_dequant
PRIVATE ${FLASHINFER_INCLUDE_DIR})
target_include_directories(
test_fast_dequant PRIVATE ${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR})
target_link_libraries(test_fast_dequant PRIVATE gtest gtest_main)
endif(FLASHINFER_FASTDEQUANT_TEST)
if(FLASHINFER_DISTRIBUTED)
find_package(MPI REQUIRED)
message(STATUS "Compile sum all-reduce kernel tests.")
file(GLOB_RECURSE TEST_DIST_SUM_ALL_REDUCE_SRCS
${PROJECT_SOURCE_DIR}/src/test_sum_all_reduce.cu)
add_executable(test_sum_all_reduce ${TEST_DIST_SUM_ALL_REDUCE_SRCS})
target_include_directories(
test_sum_all_reduce
PRIVATE ${FLASHINFER_INCLUDE_DIR} 3rdparty/mscclpp/include
3rdparty/spdlog/include)
target_link_libraries(test_sum_all_reduce PRIVATE MPI::MPI_CXX mscclpp)
target_compile_definitions(test_sum_all_reduce PRIVATE -DENABLE_MPI)
message(STATUS "Compile attention allreduce kernel tests.")
file(GLOB_RECURSE TEST_DIST_ATTN_ALL_REDUCE_SRCS
${PROJECT_SOURCE_DIR}/src/test_attn_all_reduce.cu)
add_executable(test_attn_all_reduce ${TEST_DIST_ATTN_ALL_REDUCE_SRCS})
target_include_directories(
test_attn_all_reduce
PRIVATE ${FLASHINFER_INCLUDE_DIR} 3rdparty/mscclpp/include
3rdparty/spdlog/include)
target_link_libraries(test_attn_all_reduce PRIVATE MPI::MPI_CXX mscclpp)
target_compile_definitions(test_attn_all_reduce PRIVATE -DENABLE_MPI)
endif(FLASHINFER_DISTRIBUTED)