11# Define the default target now so that it is always the first target
2- BUILD_TARGETS = main quantize quantize-stats perplexity embedding vdot q8dot train-text-from-scratch convert-llama2c-to-ggml simple batched save-load-state server embd-input-test gguf llama-bench baby-llama beam-search speculative infill benchmark-matmult parallel finetune export-lora tests/test-c.o
2+ BUILD_TARGETS = \
3+ main quantize quantize-stats perplexity embedding vdot q8dot train-text-from-scratch convert-llama2c-to-ggml \
4+ simple batched batched-bench save-load-state server embd-input-test gguf llama-bench llava baby-llama beam-search \
5+ speculative infill benchmark-matmult parallel finetune export-lora tests/test-c.o
36
47# Binaries only useful for tests
5- TEST_TARGETS = tests/test-llama-grammar tests/test-grammar-parser tests/test-double-float tests/test-grad0 tests/test-opt tests/test-quantize-fns tests/test-quantize-perf tests/test-sampling tests/test-tokenizer-0-llama tests/test-tokenizer-0-falcon tests/test-tokenizer-1-llama tests/test-tokenizer-1-bpe
8+ TEST_TARGETS = \
9+ tests/test-llama-grammar tests/test-grammar-parser tests/test-double-float tests/test-grad0 tests/test-opt \
10+ tests/test-quantize-fns tests/test-quantize-perf tests/test-sampling tests/test-tokenizer-0-llama \
11+ tests/test-tokenizer-0-falcon tests/test-tokenizer-1-llama tests/test-tokenizer-1-bpe
612
713# Code coverage output files
814COV_TARGETS = *.gcno tests/*.gcno *.gcda tests/*.gcda *.gcov tests/*.gcov lcov-report gcovr-report
@@ -172,6 +178,24 @@ else
172178 MK_CPPFLAGS += -DNDEBUG
173179endif
174180
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+
175199ifdef LLAMA_SERVER_VERBOSE
176200 MK_CPPFLAGS += -DSERVER_VERBOSE=$(LLAMA_SERVER_VERBOSE)
177201endif
@@ -512,12 +536,21 @@ ggml.o: ggml.c ggml.h ggml-cuda.h
512536ggml-alloc.o : ggml-alloc.c ggml.h ggml-alloc.h
513537 $(CC ) $(CFLAGS ) -c $< -o $@
514538
515- OBJS += ggml-alloc.o
539+ ggml-backend.o : ggml-backend.c ggml.h ggml-backend.h
540+ $(CC ) $(CFLAGS ) -c $< -o $@
541+
542+ OBJS += ggml-alloc.o ggml-backend.o
516543
517- llama.o : llama.cpp ggml.h ggml-alloc.h ggml-cuda.h ggml-metal.h llama.h
544+ llama.o : llama.cpp ggml.h ggml-alloc.h ggml-backend.h ggml- cuda.h ggml-metal.h llama.h
518545 $(CXX ) $(CXXFLAGS ) -c $< -o $@
519546
520- 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 )
521554 $(CXX ) $(CXXFLAGS ) -c $< -o $@
522555
523556console.o : common/console.cpp common/console.h
@@ -539,19 +572,22 @@ clean:
539572# Examples
540573#
541574
542- 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 )
543576 $(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
544577 @echo
545578 @echo ' ==== Run ./main -h for help. ===='
546579 @echo
547580
548- 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 )
582+ $(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
583+
584+ simple : examples/simple/simple.cpp build-info.h ggml.o llama.o $(COMMON_DEPS ) $(OBJS )
549585 $(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
550586
551- simple : examples/simple/simple .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 )
552588 $(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
553589
554- batched : examples/batched/batched.cpp build-info.h ggml.o llama.o common.o $(OBJS )
590+ batched-bench : examples/batched-bench /batched-bench .cpp build-info.h ggml.o llama.o common.o $(OBJS )
555591 $(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
556592
557593quantize : examples/quantize/quantize.cpp build-info.h ggml.o llama.o $(OBJS )
@@ -560,60 +596,68 @@ quantize: examples/quantize/quantize.cpp build-info.h ggml.
560596quantize-stats : examples/quantize-stats/quantize-stats.cpp build-info.h ggml.o llama.o $(OBJS )
561597 $(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
562598
563- 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 )
564600 $(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
565601
566- 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 )
567603 $(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
568604
569- 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 )
570606 $(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
571607
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 )
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 )
573609 $(CXX ) $(CXXFLAGS ) -Iexamples/server $(filter-out % .h,$(filter-out % .hpp,$^ ) ) -o $@ $(LDFLAGS ) $(LWINSOCK2 )
574610
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 )
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 )
576612 $(CXX ) --shared $(CXXFLAGS ) $(filter-out % .h,$(filter-out % .hpp,$^ ) ) -o $@ $(LDFLAGS )
577613
578614
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 )
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 )
580616 $(CXX ) $(CXXFLAGS ) $(filter-out % $(DSO_EXT ) ,$(filter-out % .h,$(filter-out % .hpp,$^ ) ) ) -o $@ $(LDFLAGS ) -L. -lembdinput
581617
582618gguf : examples/gguf/gguf.cpp ggml.o llama.o $(OBJS )
583619 $(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
584620
585- 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 )
586622 $(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
587623
588624convert-llama2c-to-ggml : examples/convert-llama2c-to-ggml/convert-llama2c-to-ggml.cpp ggml.o llama.o $(OBJS )
589625 $(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
590626
591- 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 )
592628 $(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
593629
594- baby-llama : examples/baby-llama/baby-llama.cpp ggml.o llama.o common.o train.o $(OBJS )
630+ llava : examples/llava/llava.cpp examples/llava/llava-utils.h examples/llava/clip.cpp examples/llava/clip.h common/stb_image.h ggml.o llama.o $(COMMON_DEPS ) $(OBJS )
631+ $(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS ) -Wno-cast-qual
632+
633+ baby-llama : examples/baby-llama/baby-llama.cpp ggml.o llama.o $(COMMON_DEPS ) train.o $(OBJS )
595634 $(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
596635
597- beam-search : examples/beam-search/beam-search.cpp build-info.h ggml.o llama.o common.o $(OBJS )
636+ beam-search : examples/beam-search/beam-search.cpp build-info.h ggml.o llama.o $( COMMON_DEPS ) $(OBJS )
598637 $(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
599638
600- finetune : examples/finetune/finetune.cpp build-info.h ggml.o llama.o common.o train.o $(OBJS )
639+ finetune : examples/finetune/finetune.cpp build-info.h ggml.o llama.o $( COMMON_DEPS ) train.o $(OBJS )
601640 $(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
602641
603- export-lora : examples/export-lora/export-lora.cpp build-info.h ggml.o llama.o common.o $(OBJS )
642+ export-lora : examples/export-lora/export-lora.cpp build-info.h ggml.o llama.o $( COMMON_DEPS ) $(OBJS )
604643 $(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
605644
606- speculative : examples/speculative/speculative.cpp build-info.h ggml.o llama.o common.o grammar-parser.o $(OBJS )
645+ speculative : examples/speculative/speculative.cpp build-info.h ggml.o llama.o $( COMMON_DEPS ) grammar-parser.o $(OBJS )
607646 $(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
608647
609- parallel : examples/parallel/parallel.cpp build-info.h ggml.o llama.o common.o $(OBJS )
648+ parallel : examples/parallel/parallel.cpp build-info.h ggml.o llama.o $( COMMON_DEPS ) $(OBJS )
610649 $(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
611650
612651ifdef LLAMA_METAL
613652metal : examples/metal/metal.cpp ggml.o $(OBJS )
614653 $(CXX ) $(CXXFLAGS ) $^ -o $@ $(LDFLAGS )
615654endif
616655
656+ ifeq ($(UNAME_S ) ,Darwin)
657+ swift : examples/batched.swift
658+ (cd examples/batched.swift; make build)
659+ endif
660+
617661build-info.h : $(wildcard .git/index) scripts/build-info.sh
618662 @sh scripts/build-info.sh $(CC ) > $@ .tmp
619663 @if ! cmp -s $@ .tmp $@ ; then \
@@ -634,48 +678,48 @@ benchmark-matmult: examples/benchmark/benchmark-matmult.cpp build-info.h ggml.o
634678run-benchmark-matmult : benchmark-matmult
635679 ./$@
636680
637- .PHONY : run-benchmark-matmult
681+ .PHONY : run-benchmark-matmult swift
638682
639683vdot : pocs/vdot/vdot.cpp ggml.o $(OBJS )
640684 $(CXX ) $(CXXFLAGS ) $^ -o $@ $(LDFLAGS )
641685
642686q8dot : pocs/vdot/q8dot.cpp ggml.o $(OBJS )
643687 $(CXX ) $(CXXFLAGS ) $^ -o $@ $(LDFLAGS )
644688
645- tests/test-llama-grammar : tests/test-llama-grammar.cpp build-info.h ggml.o common.o grammar-parser.o $(OBJS )
689+ tests/test-llama-grammar : tests/test-llama-grammar.cpp build-info.h ggml.o $( COMMON_DEPS ) grammar-parser.o $(OBJS )
646690 $(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
647691
648- tests/test-grammar-parser : tests/test-grammar-parser.cpp build-info.h ggml.o llama.o common.o grammar-parser.o $(OBJS )
692+ tests/test-grammar-parser : tests/test-grammar-parser.cpp build-info.h ggml.o llama.o $( COMMON_DEPS ) grammar-parser.o $(OBJS )
649693 $(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
650694
651- tests/test-double-float : tests/test-double-float.cpp build-info.h ggml.o llama.o common.o $(OBJS )
695+ tests/test-double-float : tests/test-double-float.cpp build-info.h ggml.o llama.o $( COMMON_DEPS ) $(OBJS )
652696 $(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
653697
654- tests/test-grad0 : tests/test-grad0.cpp build-info.h ggml.o llama.o common.o $(OBJS )
698+ tests/test-grad0 : tests/test-grad0.cpp build-info.h ggml.o llama.o $( COMMON_DEPS ) $(OBJS )
655699 $(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
656700
657- tests/test-opt : tests/test-opt.cpp build-info.h ggml.o llama.o common.o $(OBJS )
701+ tests/test-opt : tests/test-opt.cpp build-info.h ggml.o llama.o $( COMMON_DEPS ) $(OBJS )
658702 $(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
659703
660- tests/test-quantize-fns : tests/test-quantize-fns.cpp build-info.h ggml.o llama.o common.o $(OBJS )
704+ tests/test-quantize-fns : tests/test-quantize-fns.cpp build-info.h ggml.o llama.o $( COMMON_DEPS ) $(OBJS )
661705 $(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
662706
663- tests/test-quantize-perf : tests/test-quantize-perf.cpp build-info.h ggml.o llama.o common.o $(OBJS )
707+ tests/test-quantize-perf : tests/test-quantize-perf.cpp build-info.h ggml.o llama.o $( COMMON_DEPS ) $(OBJS )
664708 $(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
665709
666- tests/test-sampling : tests/test-sampling.cpp build-info.h ggml.o llama.o common.o $(OBJS )
710+ tests/test-sampling : tests/test-sampling.cpp build-info.h ggml.o llama.o $( COMMON_DEPS ) $(OBJS )
667711 $(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
668712
669- tests/test-tokenizer-0-falcon : tests/test-tokenizer-0-falcon.cpp build-info.h ggml.o llama.o common.o $(OBJS )
713+ tests/test-tokenizer-0-falcon : tests/test-tokenizer-0-falcon.cpp build-info.h ggml.o llama.o $( COMMON_DEPS ) $(OBJS )
670714 $(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
671715
672- tests/test-tokenizer-0-llama : tests/test-tokenizer-0-llama.cpp build-info.h ggml.o llama.o common.o $(OBJS )
716+ tests/test-tokenizer-0-llama : tests/test-tokenizer-0-llama.cpp build-info.h ggml.o llama.o $( COMMON_DEPS ) $(OBJS )
673717 $(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
674718
675- tests/test-tokenizer-1-bpe : tests/test-tokenizer-1-bpe.cpp build-info.h ggml.o llama.o common.o $(OBJS )
719+ tests/test-tokenizer-1-bpe : tests/test-tokenizer-1-bpe.cpp build-info.h ggml.o llama.o $( COMMON_DEPS ) $(OBJS )
676720 $(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
677721
678- tests/test-tokenizer-1-llama : tests/test-tokenizer-1-llama.cpp build-info.h ggml.o llama.o common.o $(OBJS )
722+ tests/test-tokenizer-1-llama : tests/test-tokenizer-1-llama.cpp build-info.h ggml.o llama.o $( COMMON_DEPS ) $(OBJS )
679723 $(CXX ) $(CXXFLAGS ) $(filter-out % .h,$^ ) -o $@ $(LDFLAGS )
680724
681725tests/test-c.o : tests/test-c.c llama.h
0 commit comments