Makefile 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. ifndef UNAME_S
  2. UNAME_S := $(shell uname -s)
  3. endif
  4. ifndef UNAME_P
  5. UNAME_P := $(shell uname -p)
  6. endif
  7. ifndef UNAME_M
  8. UNAME_M := $(shell uname -m)
  9. endif
  10. CCV := $(shell $(CC) --version | head -n 1)
  11. CXXV := $(shell $(CXX) --version | head -n 1)
  12. # Mac OS + Arm can report x86_64
  13. # ref: https://github.com/ggerganov/whisper.cpp/issues/66#issuecomment-1282546789
  14. ifeq ($(UNAME_S),Darwin)
  15. ifneq ($(UNAME_P),arm)
  16. SYSCTL_M := $(shell sysctl -n hw.optional.arm64 2>/dev/null)
  17. ifeq ($(SYSCTL_M),1)
  18. # UNAME_P := arm
  19. # UNAME_M := arm64
  20. warn := $(warning Your arch is announced as x86_64, but it seems to actually be ARM64. Not fixing that can lead to bad performance. For more info see: https://github.com/ggerganov/whisper.cpp/issues/66\#issuecomment-1282546789)
  21. endif
  22. endif
  23. endif
  24. #
  25. # Compile flags
  26. #
  27. # keep standard at C11 and C++11
  28. CFLAGS = -I. -O3 -DNDEBUG -std=c11 -fPIC
  29. CXXFLAGS = -I. -I./examples -O3 -DNDEBUG -std=c++11 -fPIC
  30. LDFLAGS =
  31. # warnings
  32. CFLAGS += -Wall -Wextra -Wpedantic -Wcast-qual -Wdouble-promotion -Wshadow -Wstrict-prototypes -Wpointer-arith -Wno-unused-function
  33. CXXFLAGS += -Wall -Wextra -Wpedantic -Wcast-qual -Wno-unused-function
  34. # OS specific
  35. # TODO: support Windows
  36. ifeq ($(UNAME_S),Linux)
  37. CFLAGS += -pthread
  38. CXXFLAGS += -pthread
  39. endif
  40. ifeq ($(UNAME_S),Darwin)
  41. CFLAGS += -pthread
  42. CXXFLAGS += -pthread
  43. endif
  44. ifeq ($(UNAME_S),FreeBSD)
  45. CFLAGS += -pthread
  46. CXXFLAGS += -pthread
  47. endif
  48. ifeq ($(UNAME_S),NetBSD)
  49. CFLAGS += -pthread
  50. CXXFLAGS += -pthread
  51. endif
  52. ifeq ($(UNAME_S),OpenBSD)
  53. CFLAGS += -pthread
  54. CXXFLAGS += -pthread
  55. endif
  56. ifeq ($(UNAME_S),Haiku)
  57. CFLAGS += -pthread
  58. CXXFLAGS += -pthread
  59. endif
  60. # Architecture specific
  61. # TODO: probably these flags need to be tweaked on some architectures
  62. # feel free to update the Makefile for your architecture and send a pull request or issue
  63. ifeq ($(UNAME_M),$(filter $(UNAME_M),x86_64 i686))
  64. # Use all CPU extensions that are available:
  65. CFLAGS += -march=native -mtune=native
  66. endif
  67. ifneq ($(filter ppc64%,$(UNAME_M)),)
  68. POWER9_M := $(shell grep "POWER9" /proc/cpuinfo)
  69. ifneq (,$(findstring POWER9,$(POWER9_M)))
  70. CFLAGS += -mcpu=power9
  71. CXXFLAGS += -mcpu=power9
  72. endif
  73. # Require c++23's std::byteswap for big-endian support.
  74. ifeq ($(UNAME_M),ppc64)
  75. CXXFLAGS += -std=c++23 -DGGML_BIG_ENDIAN
  76. endif
  77. endif
  78. ifndef LLAMA_NO_ACCELERATE
  79. # Mac M1 - include Accelerate framework.
  80. # `-framework Accelerate` works on Mac Intel as well, with negliable performance boost (as of the predict time).
  81. ifeq ($(UNAME_S),Darwin)
  82. CFLAGS += -DGGML_USE_ACCELERATE
  83. LDFLAGS += -framework Accelerate
  84. endif
  85. endif
  86. ifdef LLAMA_OPENBLAS
  87. CFLAGS += -DGGML_USE_OPENBLAS -I/usr/local/include/openblas
  88. LDFLAGS += -lopenblas
  89. endif
  90. ifdef LLAMA_GPROF
  91. CFLAGS += -pg
  92. CXXFLAGS += -pg
  93. endif
  94. ifneq ($(filter aarch64%,$(UNAME_M)),)
  95. CFLAGS += -mcpu=native
  96. CXXFLAGS += -mcpu=native
  97. endif
  98. ifneq ($(filter armv6%,$(UNAME_M)),)
  99. # Raspberry Pi 1, 2, 3
  100. CFLAGS += -mfpu=neon-fp-armv8 -mfp16-format=ieee -mno-unaligned-access
  101. endif
  102. ifneq ($(filter armv7%,$(UNAME_M)),)
  103. # Raspberry Pi 4
  104. CFLAGS += -mfpu=neon-fp-armv8 -mfp16-format=ieee -mno-unaligned-access -funsafe-math-optimizations
  105. endif
  106. ifneq ($(filter armv8%,$(UNAME_M)),)
  107. # Raspberry Pi 4
  108. CFLAGS += -mfp16-format=ieee -mno-unaligned-access
  109. endif
  110. #
  111. # Print build information
  112. #
  113. $(info I llama.cpp build info: )
  114. $(info I UNAME_S: $(UNAME_S))
  115. $(info I UNAME_P: $(UNAME_P))
  116. $(info I UNAME_M: $(UNAME_M))
  117. $(info I CFLAGS: $(CFLAGS))
  118. $(info I CXXFLAGS: $(CXXFLAGS))
  119. $(info I LDFLAGS: $(LDFLAGS))
  120. $(info I CC: $(CCV))
  121. $(info I CXX: $(CXXV))
  122. $(info )
  123. default: main quantize perplexity embedding
  124. #
  125. # Build library
  126. #
  127. ggml.o: ggml.c ggml.h
  128. $(CC) $(CFLAGS) -c ggml.c -o ggml.o
  129. llama.o: llama.cpp llama.h
  130. $(CXX) $(CXXFLAGS) -c llama.cpp -o llama.o
  131. common.o: examples/common.cpp examples/common.h
  132. $(CXX) $(CXXFLAGS) -c examples/common.cpp -o common.o
  133. clean:
  134. rm -vf *.o main quantize perplexity embedding
  135. main: examples/main/main.cpp ggml.o llama.o common.o
  136. $(CXX) $(CXXFLAGS) examples/main/main.cpp ggml.o llama.o common.o -o main $(LDFLAGS)
  137. @echo
  138. @echo '==== Run ./main -h for help. ===='
  139. @echo
  140. quantize: examples/quantize/quantize.cpp ggml.o llama.o
  141. $(CXX) $(CXXFLAGS) examples/quantize/quantize.cpp ggml.o llama.o -o quantize $(LDFLAGS)
  142. perplexity: examples/perplexity/perplexity.cpp ggml.o llama.o common.o
  143. $(CXX) $(CXXFLAGS) examples/perplexity/perplexity.cpp ggml.o llama.o common.o -o perplexity $(LDFLAGS)
  144. embedding: examples/embedding/embedding.cpp ggml.o llama.o common.o
  145. $(CXX) $(CXXFLAGS) examples/embedding/embedding.cpp ggml.o llama.o common.o -o embedding $(LDFLAGS)
  146. #
  147. # Tests
  148. #
  149. .PHONY: tests
  150. tests:
  151. bash ./tests/run-tests.sh