From 712e99d477d7a6725d077079ee2b27f55e6209e6 Mon Sep 17 00:00:00 2001 From: Daniel Hiltgen Date: Wed, 30 Oct 2024 12:28:36 -0700 Subject: [PATCH] Soften windows clang requirement (#7428) This will no longer error if built with regular gcc on windows. To help triage issues that may come in related to different compilers, the runner now reports the compier used by cgo. --- .github/workflows/release.yaml | 4 ++++ .github/workflows/test.yaml | 3 +++ docs/development.md | 2 +- llama/llama.go | 22 +++++++++++++++++++++- llama/make/common-defs.make | 4 ---- llama/runner/runner.go | 2 +- 6 files changed, 30 insertions(+), 7 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index b7b94098..bf249136 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -115,6 +115,7 @@ jobs: $env:CMAKE_SYSTEM_VERSION="10.0.22621.0" $env:PATH="$gopath;$env:PATH" $cores = (Get-ComputerInfo -Property CsProcessors).CsProcessors.NumberOfCores + if (!(gcc --version | select-string -quiet clang)) { throw "wrong gcc compiler detected - must be clang" } make -j $cores name: make - uses: actions/upload-artifact@v4 @@ -201,6 +202,7 @@ jobs: $env:OLLAMA_SKIP_CPU_GENERATE="1" $env:HIP_PATH=$(Resolve-Path 'C:\Program Files\AMD\ROCm\*\bin\clang.exe' | split-path | split-path) $cores = (Get-ComputerInfo -Property CsProcessors).CsProcessors.NumberOfCores + if (!(gcc --version | select-string -quiet clang)) { throw "wrong gcc compiler detected - must be clang" } make -j $cores name: make - uses: actions/upload-artifact@v4 @@ -299,6 +301,7 @@ jobs: $env:PATH="$gopath;$cudabin;$env:PATH" $env:OLLAMA_SKIP_CPU_GENERATE="1" $cores = (Get-ComputerInfo -Property CsProcessors).CsProcessors.NumberOfCores + if (!(gcc --version | select-string -quiet clang)) { throw "wrong gcc compiler detected - must be clang" } make -j $cores - uses: actions/upload-artifact@v4 with: @@ -545,6 +548,7 @@ jobs: $env:PATH="$gopath;$env:PATH" $env:OLLAMA_SKIP_GENERATE="1" $env:ARCH="amd64" + if (!(gcc --version | select-string -quiet clang)) { throw "wrong gcc compiler detected - must be clang" } & .\scripts\build_windows.ps1 - uses: actions/upload-artifact@v4 with: diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 10065182..4961b200 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -138,6 +138,7 @@ jobs: $env:HIP_PATH=$(Resolve-Path 'C:\Program Files\AMD\ROCm\*\bin\clang.exe' | split-path | split-path) $cores = (Get-ComputerInfo -Property CsProcessors).CsProcessors.NumberOfCores write-host $env:HIP_PATH + if (!(gcc --version | select-string -quiet clang)) { throw "wrong gcc compiler detected - must be clang" } make -C llama print-HIP_PATH print-HIP_LIB_DIR make -j $cores rocm name: make @@ -198,6 +199,7 @@ jobs: $env:PATH="$gopath;$cudabin;$env:PATH" $env:OLLAMA_SKIP_CPU_GENERATE="1" $cores = (Get-ComputerInfo -Property CsProcessors).CsProcessors.NumberOfCores + if (!(gcc --version | select-string -quiet clang)) { throw "wrong gcc compiler detected - must be clang" } make -j $cores cuda_v11 env: OLLAMA_SKIP_CPU_GENERATE: '1' @@ -257,6 +259,7 @@ jobs: $env:CMAKE_SYSTEM_VERSION="10.0.22621.0" $env:PATH="$gopath;$gccpath;$env:PATH" echo $env:PATH + if (!(gcc --version | select-string -quiet clang)) { throw "wrong gcc compiler detected - must be clang" } make -j 4 - name: 'Build Unix Go Runners' if: ${{ ! startsWith(matrix.os, 'windows-') }} diff --git a/docs/development.md b/docs/development.md index 48894920..f2039a08 100644 --- a/docs/development.md +++ b/docs/development.md @@ -124,7 +124,7 @@ The following tools are required as a minimal development environment to build C - Assuming you used the default install prefix for msys2 above, add `C:\msys64\clang64\bin` and `c:\msys64\usr\bin` to your environment variable `PATH` where you will perform the build steps below (e.g. system-wide, account-level, powershell, cmd, etc.) > [!NOTE] -> Due to bugs in the GCC C++ library for unicode support, Ollama requires clang on windows. If the gcc executable in your path is not the clang compatibility wrapper, the build will error. +> Due to bugs in the GCC C++ library for unicode support, Ollama should be built with clang on windows. Then, build the `ollama` binary: diff --git a/llama/llama.go b/llama/llama.go index 54f4de9a..7663e446 100644 --- a/llama/llama.go +++ b/llama/llama.go @@ -68,6 +68,17 @@ package llama #include "sampling_ext.h" bool llamaProgressCallback(float progress, void *user_data); + +typedef enum {COMP_UNKNOWN,COMP_GCC,COMP_CLANG} COMPILER; +COMPILER inline get_compiler() { +#if defined(__clang__) + return COMP_CLANG; +#elif defined(__GNUC__) + return COMP_GCC; +#else + return UNKNOWN_COMPILER; +#endif +} */ import "C" @@ -88,7 +99,16 @@ func BackendInit() { } func PrintSystemInfo() string { - return C.GoString(C.llama_print_system_info()) + var compiler string + switch C.get_compiler() { + case C.COMP_UNKNOWN: + compiler = "cgo(unknown_compiler)" + case C.COMP_GCC: + compiler = "cgo(gcc)" + case C.COMP_CLANG: + compiler = "cgo(clang)" + } + return C.GoString(C.llama_print_system_info()) + compiler } type ContextParams struct { diff --git a/llama/make/common-defs.make b/llama/make/common-defs.make index 58fb72e9..8ba33501 100644 --- a/llama/make/common-defs.make +++ b/llama/make/common-defs.make @@ -57,10 +57,6 @@ ifeq ($(OS),windows) EXE_EXT := .exe SHARED_PREFIX := CPU_FLAG_PREFIX := /arch: - _GCC_TEST:=$(findstring clang,$(shell gcc --version)) - ifneq ($(_GCC_TEST),clang) -$(error WRONG COMPILER DETECTED $(shell type gcc) - gcc must be a clang compat compiler on windows - see docs/development.md for setup instructions) - endif ifneq ($(HIP_PATH),) # If HIP_PATH has spaces, hipcc trips over them when subprocessing HIP_PATH := $(shell cygpath -m -s "$(patsubst %\,%,$(HIP_PATH))") diff --git a/llama/runner/runner.go b/llama/runner/runner.go index f472d076..bbd1c0fb 100644 --- a/llama/runner/runner.go +++ b/llama/runner/runner.go @@ -874,7 +874,7 @@ func main() { }) slog.SetDefault(slog.New(handler)) slog.Info("starting go runner") - slog.Debug("system info", "cpu", llama.PrintSystemInfo(), "threads", *threads) + slog.Info("system", "info", llama.PrintSystemInfo(), "threads", *threads) server := &Server{ batchSize: *batchSize,