@@ -172,6 +172,24 @@ else
172
172
MK_CPPFLAGS += -DNDEBUG
173
173
endif
174
174
175
+ ifdef LLAMA_SANITIZE_THREAD
176
+ MK_CFLAGS += -fsanitize=thread -g
177
+ MK_CXXFLAGS += -fsanitize=thread -g
178
+ MK_LDFLAGS += -fsanitize=thread -g
179
+ endif
180
+
181
+ ifdef LLAMA_SANITIZE_ADDRESS
182
+ MK_CFLAGS += -fsanitize=address -fno-omit-frame-pointer -g
183
+ MK_CXXFLAGS += -fsanitize=address -fno-omit-frame-pointer -g
184
+ MK_LDFLAGS += -fsanitize=address -fno-omit-frame-pointer -g
185
+ endif
186
+
187
+ ifdef LLAMA_SANITIZE_UNDEFINED
188
+ MK_CFLAGS += -fsanitize=undefined -g
189
+ MK_CXXFLAGS += -fsanitize=undefined -g
190
+ MK_LDFLAGS += -fsanitize=undefined -g
191
+ endif
192
+
175
193
ifdef LLAMA_SERVER_VERBOSE
176
194
MK_CPPFLAGS += -DSERVER_VERBOSE=$(LLAMA_SERVER_VERBOSE)
177
195
endif
@@ -517,7 +535,13 @@ OBJS += ggml-alloc.o
517
535
llama.o : llama.cpp ggml.h ggml-alloc.h ggml-cuda.h ggml-metal.h llama.h
518
536
$(CXX ) $(CXXFLAGS ) -c $< -o $@
519
537
520
- common.o : common/common.cpp common/common.h build-info.h common/log.h
538
+ COMMON_H_DEPS = common/common.h common/sampling.h build-info.h common/log.h
539
+ COMMON_DEPS = $(COMMON_H_DEPS ) common.o sampling.o
540
+
541
+ common.o : common/common.cpp $(COMMON_H_DEPS )
542
+ $(CXX ) $(CXXFLAGS ) -c $< -o $@
543
+
544
+ sampling.o : common/sampling.cpp $(COMMON_H_DEPS )
521
545
$(CXX ) $(CXXFLAGS ) -c $< -o $@
522
546
523
547
console.o : common/console.cpp common/console.h
@@ -539,19 +563,19 @@ clean:
539
563
# Examples
540
564
#
541
565
542
- main : examples/main/main.cpp build-info.h ggml.o llama.o common.o console.o grammar-parser.o $(OBJS )
566
+ main : examples/main/main.cpp build-info.h ggml.o llama.o $( COMMON_DEPS ) console.o grammar-parser.o $(OBJS )
543
567
$(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
544
568
@echo
545
569
@echo ' ==== Run ./main -h for help. ===='
546
570
@echo
547
571
548
- infill : examples/infill/infill.cpp build-info.h ggml.o llama.o common.o console.o grammar-parser.o $(OBJS )
572
+ infill : examples/infill/infill.cpp build-info.h ggml.o llama.o $( COMMON_DEPS ) console.o grammar-parser.o $(OBJS )
549
573
$(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
550
574
551
- simple : examples/simple/simple.cpp build-info.h ggml.o llama.o common.o $(OBJS )
575
+ simple : examples/simple/simple.cpp build-info.h ggml.o llama.o $( COMMON_DEPS ) $(OBJS )
552
576
$(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
553
577
554
- batched : examples/batched/batched.cpp build-info.h ggml.o llama.o common.o $(OBJS )
578
+ batched : examples/batched/batched.cpp build-info.h ggml.o llama.o $( COMMON_DEPS ) $(OBJS )
555
579
$(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
556
580
557
581
quantize : examples/quantize/quantize.cpp build-info.h ggml.o llama.o $(OBJS )
@@ -560,53 +584,53 @@ quantize: examples/quantize/quantize.cpp build-info.h ggml.
560
584
quantize-stats : examples/quantize-stats/quantize-stats.cpp build-info.h ggml.o llama.o $(OBJS )
561
585
$(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
562
586
563
- perplexity : examples/perplexity/perplexity.cpp build-info.h ggml.o llama.o common.o $(OBJS )
587
+ perplexity : examples/perplexity/perplexity.cpp build-info.h ggml.o llama.o $( COMMON_DEPS ) $(OBJS )
564
588
$(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
565
589
566
- embedding : examples/embedding/embedding.cpp build-info.h ggml.o llama.o common.o $(OBJS )
590
+ embedding : examples/embedding/embedding.cpp build-info.h ggml.o llama.o $( COMMON_DEPS ) $(OBJS )
567
591
$(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
568
592
569
- save-load-state : examples/save-load-state/save-load-state.cpp build-info.h ggml.o llama.o common.o $(OBJS )
593
+ save-load-state : examples/save-load-state/save-load-state.cpp build-info.h ggml.o llama.o $( COMMON_DEPS ) $(OBJS )
570
594
$(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
571
595
572
- server : examples/server/server.cpp examples/server/httplib.h examples/server/json.hpp examples/server/index.html.hpp examples/server/index.js.hpp examples/server/completion.js.hpp build-info.h ggml.o llama.o common.o grammar-parser.o $(OBJS )
596
+ server : examples/server/server.cpp examples/server/httplib.h examples/server/json.hpp examples/server/index.html.hpp examples/server/index.js.hpp examples/server/completion.js.hpp build-info.h ggml.o llama.o $( COMMON_DEPS ) grammar-parser.o $(OBJS )
573
597
$(CXX ) $(CXXFLAGS ) -Iexamples/server $(filter-out % .h,$(filter-out % .hpp,$^ ) ) -o $@ $(LDFLAGS ) $(LWINSOCK2 )
574
598
575
- $(LIB_PRE ) embdinput$(DSO_EXT ) : examples/embd-input/embd-input.h examples/embd-input/embd-input-lib.cpp build-info.h ggml.o llama.o common.o $(OBJS )
599
+ $(LIB_PRE ) embdinput$(DSO_EXT ) : examples/embd-input/embd-input.h examples/embd-input/embd-input-lib.cpp build-info.h ggml.o llama.o $( COMMON_DEPS ) $(OBJS )
576
600
$(CXX ) --shared $(CXXFLAGS ) $(filter-out % .h,$(filter-out % .hpp,$^ ) ) -o $@ $(LDFLAGS )
577
601
578
602
579
- embd-input-test : $(LIB_PRE ) embdinput$(DSO_EXT ) examples/embd-input/embd-input-test.cpp build-info.h ggml.o llama.o common.o $(OBJS )
603
+ embd-input-test : $(LIB_PRE ) embdinput$(DSO_EXT ) examples/embd-input/embd-input-test.cpp build-info.h ggml.o llama.o $( COMMON_DEPS ) $(OBJS )
580
604
$(CXX ) $(CXXFLAGS ) $(filter-out % $(DSO_EXT ) ,$(filter-out % .h,$(filter-out % .hpp,$^ ) ) ) -o $@ $(LDFLAGS ) -L. -lembdinput
581
605
582
606
gguf : examples/gguf/gguf.cpp ggml.o llama.o $(OBJS )
583
607
$(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
584
608
585
- train-text-from-scratch : examples/train-text-from-scratch/train-text-from-scratch.cpp ggml.o llama.o common.o train.o $(OBJS )
609
+ train-text-from-scratch : examples/train-text-from-scratch/train-text-from-scratch.cpp ggml.o llama.o $( COMMON_DEPS ) train.o $(OBJS )
586
610
$(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
587
611
588
612
convert-llama2c-to-ggml : examples/convert-llama2c-to-ggml/convert-llama2c-to-ggml.cpp ggml.o llama.o $(OBJS )
589
613
$(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
590
614
591
- llama-bench : examples/llama-bench/llama-bench.cpp build-info.h ggml.o llama.o common.o $(OBJS )
615
+ llama-bench : examples/llama-bench/llama-bench.cpp build-info.h ggml.o llama.o $( COMMON_DEPS ) $(OBJS )
592
616
$(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
593
617
594
- baby-llama : examples/baby-llama/baby-llama.cpp ggml.o llama.o common.o train.o $(OBJS )
618
+ baby-llama : examples/baby-llama/baby-llama.cpp ggml.o llama.o $( COMMON_DEPS ) train.o $(OBJS )
595
619
$(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
596
620
597
- beam-search : examples/beam-search/beam-search.cpp build-info.h ggml.o llama.o common.o $(OBJS )
621
+ beam-search : examples/beam-search/beam-search.cpp build-info.h ggml.o llama.o $( COMMON_DEPS ) $(OBJS )
598
622
$(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
599
623
600
- finetune : examples/finetune/finetune.cpp build-info.h ggml.o llama.o common.o train.o $(OBJS )
624
+ finetune : examples/finetune/finetune.cpp build-info.h ggml.o llama.o $( COMMON_DEPS ) train.o $(OBJS )
601
625
$(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
602
626
603
- export-lora : examples/export-lora/export-lora.cpp build-info.h ggml.o llama.o common.o $(OBJS )
627
+ export-lora : examples/export-lora/export-lora.cpp build-info.h ggml.o llama.o $( COMMON_DEPS ) $(OBJS )
604
628
$(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
605
629
606
- speculative : examples/speculative/speculative.cpp build-info.h ggml.o llama.o common.o grammar-parser.o $(OBJS )
630
+ speculative : examples/speculative/speculative.cpp build-info.h ggml.o llama.o $( COMMON_DEPS ) grammar-parser.o $(OBJS )
607
631
$(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
608
632
609
- parallel : examples/parallel/parallel.cpp build-info.h ggml.o llama.o common.o $(OBJS )
633
+ parallel : examples/parallel/parallel.cpp build-info.h ggml.o llama.o $( COMMON_DEPS ) $(OBJS )
610
634
$(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
611
635
612
636
ifdef LLAMA_METAL
@@ -642,40 +666,40 @@ vdot: pocs/vdot/vdot.cpp ggml.o $(OBJS)
642
666
q8dot : pocs/vdot/q8dot.cpp ggml.o $(OBJS )
643
667
$(CXX ) $(CXXFLAGS ) $^ -o $@ $(LDFLAGS )
644
668
645
- tests/test-llama-grammar : tests/test-llama-grammar.cpp build-info.h ggml.o common.o grammar-parser.o $(OBJS )
669
+ tests/test-llama-grammar : tests/test-llama-grammar.cpp build-info.h ggml.o $( COMMON_DEPS ) grammar-parser.o $(OBJS )
646
670
$(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
647
671
648
- tests/test-grammar-parser : tests/test-grammar-parser.cpp build-info.h ggml.o llama.o common.o grammar-parser.o $(OBJS )
672
+ tests/test-grammar-parser : tests/test-grammar-parser.cpp build-info.h ggml.o llama.o $( COMMON_DEPS ) grammar-parser.o $(OBJS )
649
673
$(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
650
674
651
- tests/test-double-float : tests/test-double-float.cpp build-info.h ggml.o llama.o common.o $(OBJS )
675
+ tests/test-double-float : tests/test-double-float.cpp build-info.h ggml.o llama.o $( COMMON_DEPS ) $(OBJS )
652
676
$(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
653
677
654
- tests/test-grad0 : tests/test-grad0.cpp build-info.h ggml.o llama.o common.o $(OBJS )
678
+ tests/test-grad0 : tests/test-grad0.cpp build-info.h ggml.o llama.o $( COMMON_DEPS ) $(OBJS )
655
679
$(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
656
680
657
- tests/test-opt : tests/test-opt.cpp build-info.h ggml.o llama.o common.o $(OBJS )
681
+ tests/test-opt : tests/test-opt.cpp build-info.h ggml.o llama.o $( COMMON_DEPS ) $(OBJS )
658
682
$(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
659
683
660
- tests/test-quantize-fns : tests/test-quantize-fns.cpp build-info.h ggml.o llama.o common.o $(OBJS )
684
+ tests/test-quantize-fns : tests/test-quantize-fns.cpp build-info.h ggml.o llama.o $( COMMON_DEPS ) $(OBJS )
661
685
$(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
662
686
663
- tests/test-quantize-perf : tests/test-quantize-perf.cpp build-info.h ggml.o llama.o common.o $(OBJS )
687
+ tests/test-quantize-perf : tests/test-quantize-perf.cpp build-info.h ggml.o llama.o $( COMMON_DEPS ) $(OBJS )
664
688
$(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
665
689
666
- tests/test-sampling : tests/test-sampling.cpp build-info.h ggml.o llama.o common.o $(OBJS )
690
+ tests/test-sampling : tests/test-sampling.cpp build-info.h ggml.o llama.o $( COMMON_DEPS ) $(OBJS )
667
691
$(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
668
692
669
- tests/test-tokenizer-0-falcon : tests/test-tokenizer-0-falcon.cpp build-info.h ggml.o llama.o common.o $(OBJS )
693
+ tests/test-tokenizer-0-falcon : tests/test-tokenizer-0-falcon.cpp build-info.h ggml.o llama.o $( COMMON_DEPS ) $(OBJS )
670
694
$(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
671
695
672
- tests/test-tokenizer-0-llama : tests/test-tokenizer-0-llama.cpp build-info.h ggml.o llama.o common.o $(OBJS )
696
+ tests/test-tokenizer-0-llama : tests/test-tokenizer-0-llama.cpp build-info.h ggml.o llama.o $( COMMON_DEPS ) $(OBJS )
673
697
$(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
674
698
675
- tests/test-tokenizer-1-bpe : tests/test-tokenizer-1-bpe.cpp build-info.h ggml.o llama.o common.o $(OBJS )
699
+ tests/test-tokenizer-1-bpe : tests/test-tokenizer-1-bpe.cpp build-info.h ggml.o llama.o $( COMMON_DEPS ) $(OBJS )
676
700
$(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
677
701
678
- tests/test-tokenizer-1-llama : tests/test-tokenizer-1-llama.cpp build-info.h ggml.o llama.o common.o $(OBJS )
702
+ tests/test-tokenizer-1-llama : tests/test-tokenizer-1-llama.cpp build-info.h ggml.o llama.o $( COMMON_DEPS ) $(OBJS )
679
703
$(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
680
704
681
705
tests/test-c.o : tests/test-c.c llama.h
0 commit comments