llama.cpp
Automatic Arch Linux detection
#1332
Merged

Automatic Arch Linux detection #1332

prusnak merged 6 commits into ggml-org:master from master
daniandtheweb
daniandtheweb2 years ago (edited 2 years ago)❤ 2

This pull request adds a check in the Makefile in order to set automatically the -lcblas flag on Arch Linux. This change is based on koboldcpp's Makefile so the credit for this should go to @LostRuins.

daniandtheweb Automatic Arch Linux detection for BLAS
4e3c178b
daniandtheweb Remove Arch Linux note
a8815a68
SergeAx
SergeAx approved these changes on 2023-05-05
SergeAx2 years ago

This is legit. Here's the original commit: LostRuins@7ba36c2

prusnak
prusnak requested changes on 2023-05-05
Conversation is marked as resolved
Show resolved
Makefile
1313UNAME_M := $(shell uname -m)
1414endif
1515
16
ARCH_LINUX1 := $(shell grep "Arch Linux" /etc/os-release 2>/dev/null)
17
ARCH_LINUX2 := $(shell grep "ID_LIKE=arch" /etc/os-release 2>/dev/null)
18
ifdef ARCH_LINUX1
19
ARCH_ADD = -lcblas
20
endif
21
ifdef ARCH_LINUX2
22
ARCH_ADD = -lcblas
23
endif
prusnak2 years ago (edited 2 years ago)

grep is quite smart and we can leverage this:

Suggested change
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
ARCH_LINUX := $(shell grep -e "Arch Linux" -e "ID_LIKE=arch" /etc/os-release)
ifdef ARCH_LINUX
LDFLAGS_EXTRA += -lcblas
endif
daniandtheweb2 years ago

Makes sense. I didn't know that you could grep multiple strings.

Conversation is marked as resolved
Show resolved
Makefile
108117ifdef LLAMA_OPENBLAS
109118 CFLAGS += -DGGML_USE_OPENBLAS -I/usr/local/include/openblas
110 LDFLAGS += -lopenblas
119
LDFLAGS += -lopenblas $(ARCH_ADD)
prusnak2 years ago
Suggested change
LDFLAGS += -lopenblas $(ARCH_ADD)
LDFLAGS += -lopenblas $(LDFLAGS_EXTRA)
daniandtheweb Optimize Arch Linux check
c0a86cc5
daniandtheweb Rename variable
471624b4
prusnak
prusnak requested changes on 2023-05-05
prusnak2 years ago

Please also test on Arch Linux whether my suggestions work. I don't have one laying around.

Conversation is marked as resolved
Show resolved
Makefile
1313UNAME_M := $(shell uname -m)
1414endif
1515
16
ARCH_LINUX := $(shell grep -e "Arch Linux" -e "ID_LIKE=arch" /etc/os-release)
prusnak2 years ago (edited 2 years ago)

I forgot to keep this (otherwise the grep provides error output if file is not found):

Suggested change
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)
Conversation is marked as resolved
Show resolved
Makefile
108113ifdef LLAMA_OPENBLAS
109114 CFLAGS += -DGGML_USE_OPENBLAS -I/usr/local/include/openblas
110 LDFLAGS += -lopenblas
115
LDFLAGS += -lopenblas $(LDFLAGS_EXTRA)
prusnak2 years ago (edited 2 years ago)

Now thinking about it more. Maybe we should move the whole thing with ARCH_LINUX := ... here to make it more local (and not evaluating when LLAMA_OPENBLAS is not defined) and then use the following directly (without the temp variable)?

ifdef ARCH_LINUX
LDFLAGS += -lopenblas -lcblas
else
LDFLAGS += -lopenblas
endif
daniandtheweb2 years ago

I've included the check inside of the OPENBLAS def.

daniandtheweb Fix possible error
ab5e61d7
daniandtheweb Shrink Arch Linux check
a44c384c
daniandtheweb
daniandtheweb2 years ago (edited 2 years ago)

Like this it works perfectly on Arch Linux. Sorry for the mess with the commits but it's my first time editing a Makefile.

prusnak
prusnak approved these changes on 2023-05-05
prusnak prusnak merged 173d0e64 into master 2 years ago
prusnak
prusnak2 years ago

Sorry for the mess with the commits but it's my first time editing a Makefile.

No worries, you did great and I really like the final form of the submission! 🎉

LostRuins
LostRuins2 years ago

Nice 👍

Login to write a write a comment.

Login via GitHub

Reviewers
Assignees
No one assigned
Labels
Milestone