Makefile.cpu 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # Build the discrete cpu runner(s) for the platform which do not rely on 3rd party GPU libraries
  2. include make/common-defs.make
  3. CPU_GOFLAGS="-ldflags=-w -s \"-X=github.com/ollama/ollama/version.Version=$(VERSION)\" \"-X=github.com/ollama/ollama/llama.CpuFeatures=$(subst $(space),$(comma),$(TARGET_CPU_FLAGS))\" $(TARGET_LDFLAGS)"
  4. ifeq ($(ARCH),amd64)
  5. ifeq ($(origin CUSTOM_CPU_FLAGS),undefined)
  6. RUNNERS = cpu_avx cpu_avx2
  7. endif
  8. endif
  9. DIST_RUNNERS = $(addprefix $(RUNNERS_DIST_DIR)/,$(addsuffix /ollama_llama_server$(EXE_EXT),$(RUNNERS)))
  10. BUILD_RUNNERS = $(addprefix $(RUNNERS_BUILD_DIR)/,$(addsuffix /ollama_llama_server$(EXE_EXT),$(RUNNERS)))
  11. cpu: $(BUILD_RUNNERS)
  12. dist: $(DIST_RUNNERS)
  13. $(RUNNERS_BUILD_DIR)/cpu_avx/ollama_llama_server$(EXE_EXT): TARGET_CPU_FLAGS="avx"
  14. $(RUNNERS_BUILD_DIR)/cpu_avx/ollama_llama_server$(EXE_EXT): ./llama/*.go ./llama/runner/*.go $(COMMON_SRCS) $(COMMON_HDRS)
  15. @-mkdir -p $(dir $@)
  16. GOARCH=$(ARCH) go build -buildmode=pie $(CPU_GOFLAGS) -trimpath -tags $(subst $(space),$(comma),$(TARGET_CPU_FLAGS)) -o $@ ./cmd/runner
  17. $(RUNNERS_BUILD_DIR)/cpu_avx2/ollama_llama_server$(EXE_EXT): TARGET_CPU_FLAGS="avx avx2"
  18. $(RUNNERS_BUILD_DIR)/cpu_avx2/ollama_llama_server$(EXE_EXT): ./llama/*.go ./llama/runner/*.go $(COMMON_SRCS) $(COMMON_HDRS)
  19. @-mkdir -p $(dir $@)
  20. GOARCH=$(ARCH) go build -buildmode=pie $(CPU_GOFLAGS) -trimpath -tags $(subst $(space),$(comma),$(TARGET_CPU_FLAGS)) -o $@ ./cmd/runner
  21. $(RUNNERS_DIST_DIR)/%: $(RUNNERS_BUILD_DIR)/%
  22. @-mkdir -p $(dir $@)
  23. cp $< $@
  24. clean:
  25. rm -f $(BUILD_RUNNERS) $(DIST_RUNNERS)
  26. .PHONY: clean cpu dist
  27. # Handy debugging for make variables
  28. print-%:
  29. @echo '$*=$($*)'