diff --git a/ml/backend/ggml/ggml/src/ggml-cpu/arch-impls.c b/ml/backend/ggml/ggml/src/ggml-cpu/arch-impls.c new file mode 100644 index 000000000..e1e6005a7 --- /dev/null +++ b/ml/backend/ggml/ggml/src/ggml-cpu/arch-impls.c @@ -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 diff --git a/ml/backend/ggml/ggml/src/ggml-cpu/arch-impls.cpp b/ml/backend/ggml/ggml/src/ggml-cpu/arch-impls.cpp new file mode 100644 index 000000000..60664e4fd --- /dev/null +++ b/ml/backend/ggml/ggml/src/ggml-cpu/arch-impls.cpp @@ -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 diff --git a/ml/backend/ggml/ggml/src/ggml-cpu/cpu.go b/ml/backend/ggml/ggml/src/ggml-cpu/cpu.go index 895b7f6ef..d750f346d 100644 --- a/ml/backend/ggml/ggml/src/ggml-cpu/cpu.go +++ b/ml/backend/ggml/ggml/src/ggml-cpu/cpu.go @@ -7,5 +7,26 @@ package cpu // #cgo linux CPPFLAGS: -D_GNU_SOURCE // #cgo darwin,arm64 CPPFLAGS: -DGGML_USE_ACCELERATE -DACCELERATE_NEW_LAPACK -DACCELERATE_LAPACK_ILP64 // #cgo darwin,arm64 LDFLAGS: -framework Accelerate +// +// #cgo amd64 CFLAGS: -D__amd64__ +// #cgo amd64 CPPFLAGS: -D__amd64__ +// +// #cgo arm64 CFLAGS: -D__arm64__ +// #cgo arm64 CPPFLAGS: -D__arm64__ +// +// #cgo loong64 CFLAGS: -D__loong64__ +// #cgo loong64 CPPFLAGS: -D__loong64__ +// +// #cgo ppc64 CFLAGS: -D__ppc64__ +// #cgo ppc64 CPPFLAGS: -D__ppc64__ +// +// #cgo riscv64 CFLAGS: -D__riscv64__ +// #cgo riscv64 CPPFLAGS: -D__riscv64__ +// +// #cgo s390x CFLAGS: -D__s390x__ +// #cgo s390x CPPFLAGS: -D__s390x__ +// +// #cgo wasm CFLAGS: -D__wasm__ +// #cgo wasm CPPFLAGS: -D__wasm__ import "C" import _ "github.com/ollama/ollama/ml/backend/ggml/ggml/src/ggml-cpu/llamafile"