mirror of https://gitee.com/namelin2022/ollama
Browse Source
In https://github.com/ggml-org/llama.cpp/pull/13892, all arch-specific implementations were split out into a nested tree structure under ggml-cpu/arch. This conflicts with standard CGO layout where all arch-specific source files are expected to live in the same directory as the parent go module and use suffixes based on GOOS and GOARCH. As such, there were really two options for getting this to work: 1. Add a patch on top of the GGML sync to rearrange the files to match the GO layout convention 2. Use CGO directives to conditionally include the nested source files in the compilation units This commit does (2) in order to minimize the set of changes needed on top of the upstream file layout. To get this to work, there are two key things needed: 1. In cpu.go, #cgo directives are added to explicitly set __${GOARCH}__ in the preprocessor directives 2. In arch-impls.c|cpp, use an #ifdef | #elif defined | #endif chain to explicitly include the .c|.cpp files for the given architecture from the nested directory Branch: GraniteFour Signed-off-by: Gabe Goodhart <ghart@us.ibm.com>jessegross/bump-memory
committed by
Michael Yang
3 changed files with 88 additions and 0 deletions
@ -0,0 +1,33 @@ |
|||
/**
|
|||
* This is a custom source file that explicitly incorporates the cpu-arch |
|||
* implementation files for the target CPU. It is not part of the GGML source |
|||
* and is only used to bind the arch implementations to CGO. |
|||
* |
|||
* The preprocessor defines are specified in cpu.go and correspond to GOARCH |
|||
* values. |
|||
* |
|||
* https://github.com/golang/go/blob/master/src/internal/syslist/syslist.go#L58
|
|||
*/ |
|||
|
|||
#ifdef __amd64__ |
|||
#include "./arch/x86/quants.c" |
|||
|
|||
#elif defined __arm64__ |
|||
#include "./arch/arm/quants.c" |
|||
|
|||
#elif defined __loong64__ |
|||
#include "./arch/loongarch/quants.c" |
|||
|
|||
#elif defined __ppc64__ |
|||
#include "./arch/powerpc/quants.c" |
|||
|
|||
#elif defined __riscv64__ |
|||
#include "./arch/riscv/quants.c" |
|||
|
|||
#elif defined __s390x__ |
|||
#include "./arch/s390/quants.c" |
|||
|
|||
#elif defined __wasm__ |
|||
#include "./arch/wasm/quants.c" |
|||
|
|||
#endif |
|||
@ -0,0 +1,34 @@ |
|||
/**
|
|||
* This is a custom source file that explicitly incorporates the cpu-arch |
|||
* implementation files for the target CPU. It is not part of the GGML source |
|||
* and is only used to bind the arch implementations to CGO. |
|||
* |
|||
* The preprocessor defines are specified in cpu.go and correspond to GOARCH |
|||
* values. |
|||
* |
|||
* https://github.com/golang/go/blob/master/src/internal/syslist/syslist.go#L58
|
|||
*/ |
|||
|
|||
#ifdef __amd64__ |
|||
#include "./arch/x86/cpu-feats.cpp" |
|||
#include "./arch/x86/repack.cpp" |
|||
|
|||
#elif defined __arm64__ |
|||
#include "./arch/arm/repack.cpp" |
|||
|
|||
#elif defined __loong64__ |
|||
// No cpp
|
|||
|
|||
#elif defined __ppc64__ |
|||
#include "./arch/arm/cpu-feats.cpp" |
|||
|
|||
#elif defined __riscv64__ |
|||
#include "./arch/arm/repack.cpp" |
|||
|
|||
#elif defined __s390x__ |
|||
// No cpp
|
|||
|
|||
#elif defined __wasm__ |
|||
// No cpp
|
|||
|
|||
#endif |
|||
Loading…
Reference in new issue