@@ -178,6 +178,24 @@ else
178
178
MK_CPPFLAGS += -DNDEBUG
179
179
endif
180
180
181
+ ifdef LLAMA_SANITIZE_THREAD
182
+ MK_CFLAGS += -fsanitize=thread -g
183
+ MK_CXXFLAGS += -fsanitize=thread -g
184
+ MK_LDFLAGS += -fsanitize=thread -g
185
+ endif
186
+
187
+ ifdef LLAMA_SANITIZE_ADDRESS
188
+ MK_CFLAGS += -fsanitize=address -fno-omit-frame-pointer -g
189
+ MK_CXXFLAGS += -fsanitize=address -fno-omit-frame-pointer -g
190
+ MK_LDFLAGS += -fsanitize=address -fno-omit-frame-pointer -g
191
+ endif
192
+
193
+ ifdef LLAMA_SANITIZE_UNDEFINED
194
+ MK_CFLAGS += -fsanitize=undefined -g
195
+ MK_CXXFLAGS += -fsanitize=undefined -g
196
+ MK_LDFLAGS += -fsanitize=undefined -g
197
+ endif
198
+
181
199
ifdef LLAMA_SERVER_VERBOSE
182
200
MK_CPPFLAGS += -DSERVER_VERBOSE=$(LLAMA_SERVER_VERBOSE)
183
201
endif
@@ -526,7 +544,13 @@ OBJS += ggml-alloc.o ggml-backend.o
526
544
llama.o : llama.cpp ggml.h ggml-alloc.h ggml-backend.h ggml-cuda.h ggml-metal.h llama.h
527
545
$(CXX ) $(CXXFLAGS ) -c $< -o $@
528
546
529
- common.o : common/common.cpp common/common.h build-info.h common/log.h
547
+ COMMON_H_DEPS = common/common.h common/sampling.h build-info.h common/log.h
548
+ COMMON_DEPS = $(COMMON_H_DEPS ) common.o sampling.o
549
+
550
+ common.o : common/common.cpp $(COMMON_H_DEPS )
551
+ $(CXX ) $(CXXFLAGS ) -c $< -o $@
552
+
553
+ sampling.o : common/sampling.cpp $(COMMON_H_DEPS )
530
554
$(CXX ) $(CXXFLAGS ) -c $< -o $@
531
555
532
556
console.o : common/console.cpp common/console.h
@@ -548,19 +572,19 @@ clean:
548
572
# Examples
549
573
#
550
574
551
- main : examples/main/main.cpp build-info.h ggml.o llama.o common.o console.o grammar-parser.o $(OBJS )
575
+ main : examples/main/main.cpp build-info.h ggml.o llama.o $( COMMON_DEPS ) console.o grammar-parser.o $(OBJS )
552
576
$(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
553
577
@echo
554
578
@echo ' ==== Run ./main -h for help. ===='
555
579
@echo
556
580
557
- infill : examples/infill/infill.cpp build-info.h ggml.o llama.o common.o console.o grammar-parser.o $(OBJS )
581
+ infill : examples/infill/infill.cpp build-info.h ggml.o llama.o $( COMMON_DEPS ) console.o grammar-parser.o $(OBJS )
558
582
$(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
559
583
560
- simple : examples/simple/simple.cpp build-info.h ggml.o llama.o common.o $(OBJS )
584
+ simple : examples/simple/simple.cpp build-info.h ggml.o llama.o $( COMMON_DEPS ) $(OBJS )
561
585
$(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
562
586
563
- batched : examples/batched/batched.cpp build-info.h ggml.o llama.o common.o $(OBJS )
587
+ batched : examples/batched/batched.cpp build-info.h ggml.o llama.o $( COMMON_DEPS ) $(OBJS )
564
588
$(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
565
589
566
590
batched-bench : examples/batched-bench/batched-bench.cpp build-info.h ggml.o llama.o common.o $(OBJS )
@@ -572,53 +596,53 @@ quantize: examples/quantize/quantize.cpp build-info.h ggml.
572
596
quantize-stats : examples/quantize-stats/quantize-stats.cpp build-info.h ggml.o llama.o $(OBJS )
573
597
$(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
574
598
575
- perplexity : examples/perplexity/perplexity.cpp build-info.h ggml.o llama.o common.o $(OBJS )
599
+ perplexity : examples/perplexity/perplexity.cpp build-info.h ggml.o llama.o $( COMMON_DEPS ) $(OBJS )
576
600
$(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
577
601
578
- embedding : examples/embedding/embedding.cpp build-info.h ggml.o llama.o common.o $(OBJS )
602
+ embedding : examples/embedding/embedding.cpp build-info.h ggml.o llama.o $( COMMON_DEPS ) $(OBJS )
579
603
$(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
580
604
581
- save-load-state : examples/save-load-state/save-load-state.cpp build-info.h ggml.o llama.o common.o $(OBJS )
605
+ save-load-state : examples/save-load-state/save-load-state.cpp build-info.h ggml.o llama.o $( COMMON_DEPS ) $(OBJS )
582
606
$(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
583
607
584
- 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 )
608
+ 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 )
585
609
$(CXX ) $(CXXFLAGS ) -Iexamples/server $(filter-out % .h,$(filter-out % .hpp,$^ ) ) -o $@ $(LDFLAGS ) $(LWINSOCK2 )
586
610
587
- $(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 )
611
+ $(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 )
588
612
$(CXX ) --shared $(CXXFLAGS ) $(filter-out % .h,$(filter-out % .hpp,$^ ) ) -o $@ $(LDFLAGS )
589
613
590
614
591
- 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 )
615
+ 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 )
592
616
$(CXX ) $(CXXFLAGS ) $(filter-out % $(DSO_EXT ) ,$(filter-out % .h,$(filter-out % .hpp,$^ ) ) ) -o $@ $(LDFLAGS ) -L. -lembdinput
593
617
594
618
gguf : examples/gguf/gguf.cpp ggml.o llama.o $(OBJS )
595
619
$(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
596
620
597
- train-text-from-scratch : examples/train-text-from-scratch/train-text-from-scratch.cpp ggml.o llama.o common.o train.o $(OBJS )
621
+ train-text-from-scratch : examples/train-text-from-scratch/train-text-from-scratch.cpp ggml.o llama.o $( COMMON_DEPS ) train.o $(OBJS )
598
622
$(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
599
623
600
624
convert-llama2c-to-ggml : examples/convert-llama2c-to-ggml/convert-llama2c-to-ggml.cpp ggml.o llama.o $(OBJS )
601
625
$(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
602
626
603
- llama-bench : examples/llama-bench/llama-bench.cpp build-info.h ggml.o llama.o common.o $(OBJS )
627
+ llama-bench : examples/llama-bench/llama-bench.cpp build-info.h ggml.o llama.o $( COMMON_DEPS ) $(OBJS )
604
628
$(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
605
629
606
- baby-llama : examples/baby-llama/baby-llama.cpp ggml.o llama.o common.o train.o $(OBJS )
630
+ baby-llama : examples/baby-llama/baby-llama.cpp ggml.o llama.o $( COMMON_DEPS ) train.o $(OBJS )
607
631
$(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
608
632
609
- beam-search : examples/beam-search/beam-search.cpp build-info.h ggml.o llama.o common.o $(OBJS )
633
+ beam-search : examples/beam-search/beam-search.cpp build-info.h ggml.o llama.o $( COMMON_DEPS ) $(OBJS )
610
634
$(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
611
635
612
- finetune : examples/finetune/finetune.cpp build-info.h ggml.o llama.o common.o train.o $(OBJS )
636
+ finetune : examples/finetune/finetune.cpp build-info.h ggml.o llama.o $( COMMON_DEPS ) train.o $(OBJS )
613
637
$(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
614
638
615
- export-lora : examples/export-lora/export-lora.cpp build-info.h ggml.o llama.o common.o $(OBJS )
639
+ export-lora : examples/export-lora/export-lora.cpp build-info.h ggml.o llama.o $( COMMON_DEPS ) $(OBJS )
616
640
$(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
617
641
618
- speculative : examples/speculative/speculative.cpp build-info.h ggml.o llama.o common.o grammar-parser.o $(OBJS )
642
+ speculative : examples/speculative/speculative.cpp build-info.h ggml.o llama.o $( COMMON_DEPS ) grammar-parser.o $(OBJS )
619
643
$(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
620
644
621
- parallel : examples/parallel/parallel.cpp build-info.h ggml.o llama.o common.o $(OBJS )
645
+ parallel : examples/parallel/parallel.cpp build-info.h ggml.o llama.o $( COMMON_DEPS ) $(OBJS )
622
646
$(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
623
647
624
648
ifdef LLAMA_METAL
@@ -659,40 +683,40 @@ vdot: pocs/vdot/vdot.cpp ggml.o $(OBJS)
659
683
q8dot : pocs/vdot/q8dot.cpp ggml.o $(OBJS )
660
684
$(CXX ) $(CXXFLAGS ) $^ -o $@ $(LDFLAGS )
661
685
662
- tests/test-llama-grammar : tests/test-llama-grammar.cpp build-info.h ggml.o common.o grammar-parser.o $(OBJS )
686
+ tests/test-llama-grammar : tests/test-llama-grammar.cpp build-info.h ggml.o $( COMMON_DEPS ) grammar-parser.o $(OBJS )
663
687
$(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
664
688
665
- tests/test-grammar-parser : tests/test-grammar-parser.cpp build-info.h ggml.o llama.o common.o grammar-parser.o $(OBJS )
689
+ tests/test-grammar-parser : tests/test-grammar-parser.cpp build-info.h ggml.o llama.o $( COMMON_DEPS ) grammar-parser.o $(OBJS )
666
690
$(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
667
691
668
- tests/test-double-float : tests/test-double-float.cpp build-info.h ggml.o llama.o common.o $(OBJS )
692
+ tests/test-double-float : tests/test-double-float.cpp build-info.h ggml.o llama.o $( COMMON_DEPS ) $(OBJS )
669
693
$(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
670
694
671
- tests/test-grad0 : tests/test-grad0.cpp build-info.h ggml.o llama.o common.o $(OBJS )
695
+ tests/test-grad0 : tests/test-grad0.cpp build-info.h ggml.o llama.o $( COMMON_DEPS ) $(OBJS )
672
696
$(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
673
697
674
- tests/test-opt : tests/test-opt.cpp build-info.h ggml.o llama.o common.o $(OBJS )
698
+ tests/test-opt : tests/test-opt.cpp build-info.h ggml.o llama.o $( COMMON_DEPS ) $(OBJS )
675
699
$(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
676
700
677
- tests/test-quantize-fns : tests/test-quantize-fns.cpp build-info.h ggml.o llama.o common.o $(OBJS )
701
+ tests/test-quantize-fns : tests/test-quantize-fns.cpp build-info.h ggml.o llama.o $( COMMON_DEPS ) $(OBJS )
678
702
$(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
679
703
680
- tests/test-quantize-perf : tests/test-quantize-perf.cpp build-info.h ggml.o llama.o common.o $(OBJS )
704
+ tests/test-quantize-perf : tests/test-quantize-perf.cpp build-info.h ggml.o llama.o $( COMMON_DEPS ) $(OBJS )
681
705
$(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
682
706
683
- tests/test-sampling : tests/test-sampling.cpp build-info.h ggml.o llama.o common.o $(OBJS )
707
+ tests/test-sampling : tests/test-sampling.cpp build-info.h ggml.o llama.o $( COMMON_DEPS ) $(OBJS )
684
708
$(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
685
709
686
- tests/test-tokenizer-0-falcon : tests/test-tokenizer-0-falcon.cpp build-info.h ggml.o llama.o common.o $(OBJS )
710
+ tests/test-tokenizer-0-falcon : tests/test-tokenizer-0-falcon.cpp build-info.h ggml.o llama.o $( COMMON_DEPS ) $(OBJS )
687
711
$(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
688
712
689
- tests/test-tokenizer-0-llama : tests/test-tokenizer-0-llama.cpp build-info.h ggml.o llama.o common.o $(OBJS )
713
+ tests/test-tokenizer-0-llama : tests/test-tokenizer-0-llama.cpp build-info.h ggml.o llama.o $( COMMON_DEPS ) $(OBJS )
690
714
$(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
691
715
692
- tests/test-tokenizer-1-bpe : tests/test-tokenizer-1-bpe.cpp build-info.h ggml.o llama.o common.o $(OBJS )
716
+ tests/test-tokenizer-1-bpe : tests/test-tokenizer-1-bpe.cpp build-info.h ggml.o llama.o $( COMMON_DEPS ) $(OBJS )
693
717
$(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
694
718
695
- tests/test-tokenizer-1-llama : tests/test-tokenizer-1-llama.cpp build-info.h ggml.o llama.o common.o $(OBJS )
719
+ tests/test-tokenizer-1-llama : tests/test-tokenizer-1-llama.cpp build-info.h ggml.o llama.o $( COMMON_DEPS ) $(OBJS )
696
720
$(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
697
721
698
722
tests/test-c.o : tests/test-c.c llama.h
0 commit comments