From 4e3c178be43f5135566ffe0a41d85840aa93d2fb Mon Sep 17 00:00:00 2001 From: DaniAndTheWeb <57776841+DaniAndTheWeb@users.noreply.github.com> Date: Fri, 5 May 2023 18:31:05 +0200 Subject: [PATCH 1/6] Automatic Arch Linux detection for BLAS This commit is a port of a detection method used in koboldcpp's Makefile in order to automatically set the -lcblas option on Arch Linux --- Makefile | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 260b2487ffab8..15875a34e879a 100644 --- a/Makefile +++ b/Makefile @@ -13,6 +13,15 @@ ifndef UNAME_M UNAME_M := $(shell uname -m) endif +ARCH_LINUX1 := $(shell grep "Arch Linux" /etc/os-release 2>/dev/null) +ARCH_LINUX2 := $(shell grep "ID_LIKE=arch" /etc/os-release 2>/dev/null) +ifdef ARCH_LINUX1 +ARCH_ADD = -lcblas +endif +ifdef ARCH_LINUX2 +ARCH_ADD = -lcblas +endif + CCV := $(shell $(CC) --version | head -n 1) CXXV := $(shell $(CXX) --version | head -n 1) @@ -107,7 +116,7 @@ ifndef LLAMA_NO_ACCELERATE endif ifdef LLAMA_OPENBLAS CFLAGS += -DGGML_USE_OPENBLAS -I/usr/local/include/openblas - LDFLAGS += -lopenblas + LDFLAGS += -lopenblas $(ARCH_ADD) endif ifdef LLAMA_CUBLAS CFLAGS += -DGGML_USE_CUBLAS -I/usr/local/cuda/include -I/opt/cuda/include -I$(CUDA_PATH)/targets/x86_64-linux/include From a8815a683e7bd18c26b6bce29480d4f4b576d27f Mon Sep 17 00:00:00 2001 From: DaniAndTheWeb <57776841+DaniAndTheWeb@users.noreply.github.com> Date: Fri, 5 May 2023 18:31:48 +0200 Subject: [PATCH 2/6] Remove Arch Linux note --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 233c5c5e1e19c..19cc94aa269c9 100644 --- a/README.md +++ b/README.md @@ -216,7 +216,6 @@ Building the program with BLAS support may lead to some performance improvements ```bash make LLAMA_OPENBLAS=1 ``` - Note: In order to build on Arch Linux with OpenBLAS support enabled you must edit the Makefile adding at the end of the line 105: `-lcblas` - On Windows: From c0a86cc5565d065671ace2e55546fab669ffe4b2 Mon Sep 17 00:00:00 2001 From: DaniAndTheWeb <57776841+DaniAndTheWeb@users.noreply.github.com> Date: Fri, 5 May 2023 22:51:56 +0200 Subject: [PATCH 3/6] Optimize Arch Linux check Co-authored-by: Pavol Rusnak --- Makefile | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 15875a34e879a..a12d97142abd3 100644 --- a/Makefile +++ b/Makefile @@ -13,13 +13,9 @@ ifndef UNAME_M UNAME_M := $(shell uname -m) endif -ARCH_LINUX1 := $(shell grep "Arch Linux" /etc/os-release 2>/dev/null) -ARCH_LINUX2 := $(shell grep "ID_LIKE=arch" /etc/os-release 2>/dev/null) -ifdef ARCH_LINUX1 -ARCH_ADD = -lcblas -endif -ifdef ARCH_LINUX2 -ARCH_ADD = -lcblas +ARCH_LINUX := $(shell grep -e "Arch Linux" -e "ID_LIKE=arch" /etc/os-release) +ifdef ARCH_LINUX +LDFLAGS_EXTRA += -lcblas endif CCV := $(shell $(CC) --version | head -n 1) From 471624b464dbced1eb626279feed9f68d1fd1dd0 Mon Sep 17 00:00:00 2001 From: DaniAndTheWeb <57776841+DaniAndTheWeb@users.noreply.github.com> Date: Fri, 5 May 2023 22:52:49 +0200 Subject: [PATCH 4/6] Rename variable Co-authored-by: Pavol Rusnak --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index a12d97142abd3..1098ce29c09e8 100644 --- a/Makefile +++ b/Makefile @@ -112,7 +112,7 @@ ifndef LLAMA_NO_ACCELERATE endif ifdef LLAMA_OPENBLAS CFLAGS += -DGGML_USE_OPENBLAS -I/usr/local/include/openblas - LDFLAGS += -lopenblas $(ARCH_ADD) + LDFLAGS += -lopenblas $(LDFLAGS_EXTRA) endif ifdef LLAMA_CUBLAS CFLAGS += -DGGML_USE_CUBLAS -I/usr/local/cuda/include -I/opt/cuda/include -I$(CUDA_PATH)/targets/x86_64-linux/include From ab5e61d71040e8428d8dc50d31a40e68ef8362d9 Mon Sep 17 00:00:00 2001 From: DaniAndTheWeb <57776841+DaniAndTheWeb@users.noreply.github.com> Date: Fri, 5 May 2023 23:10:28 +0200 Subject: [PATCH 5/6] Fix possible error Co-authored-by: Pavol Rusnak --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 1098ce29c09e8..e54c68dbe7697 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ ifndef UNAME_M UNAME_M := $(shell uname -m) endif -ARCH_LINUX := $(shell grep -e "Arch Linux" -e "ID_LIKE=arch" /etc/os-release) +ARCH_LINUX := $(shell grep -e "Arch Linux" -e "ID_LIKE=arch" /etc/os-release 2>/dev/null) ifdef ARCH_LINUX LDFLAGS_EXTRA += -lcblas endif From a44c384c56fe07e409ed87bb7e6003cb36dfe7f0 Mon Sep 17 00:00:00 2001 From: DaniAndTheWeb <57776841+DaniAndTheWeb@users.noreply.github.com> Date: Fri, 5 May 2023 23:23:47 +0200 Subject: [PATCH 6/6] Shrink Arch Linux check --- Makefile | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index e54c68dbe7697..0ddff9961ac76 100644 --- a/Makefile +++ b/Makefile @@ -13,11 +13,6 @@ ifndef UNAME_M UNAME_M := $(shell uname -m) endif -ARCH_LINUX := $(shell grep -e "Arch Linux" -e "ID_LIKE=arch" /etc/os-release 2>/dev/null) -ifdef ARCH_LINUX -LDFLAGS_EXTRA += -lcblas -endif - CCV := $(shell $(CC) --version | head -n 1) CXXV := $(shell $(CXX) --version | head -n 1) @@ -112,7 +107,11 @@ ifndef LLAMA_NO_ACCELERATE endif ifdef LLAMA_OPENBLAS CFLAGS += -DGGML_USE_OPENBLAS -I/usr/local/include/openblas - LDFLAGS += -lopenblas $(LDFLAGS_EXTRA) + ifneq ($(shell grep -e "Arch Linux" -e "ID_LIKE=arch" /etc/os-release 2>/dev/null),) + LDFLAGS += -lopenblas -lcblas + else + LDFLAGS += -lopenblas + endif endif ifdef LLAMA_CUBLAS CFLAGS += -DGGML_USE_CUBLAS -I/usr/local/cuda/include -I/opt/cuda/include -I$(CUDA_PATH)/targets/x86_64-linux/include