Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding risc-v architecture support #231

Open
dhood opened this issue May 14, 2023 · 1 comment
Open

Adding risc-v architecture support #231

dhood opened this issue May 14, 2023 · 1 comment

Comments

@dhood
Copy link

dhood commented May 14, 2023

Hi there, thanks for the great library!! 🙇

Motivated by a pretty specific application (to get alpaca results "verifiable" by running on Cartesi which is ontop of blockchain), I'm trying to compile alpaca.cpp for RISC-V architecture.

It's my first foray into the joys of such, and I have gotten stuck. But before I give up I thought I'd check if anyone happens to have tried it already.

FWICT the main thing is the vector intrinsics:

diff --git a/ggml.c b/ggml.c
index 535c7b7..b6828a8 100644
--- a/ggml.c
+++ b/ggml.c
@@ -151,10 +151,18 @@ typedef double ggml_float;
 #include <altivec.h>
 #undef bool
 #define bool _Bool
+#else
+// RISC-V support
+#if defined(__riscv) || defined(__riscv__)
+#include <riscv_vector.h>
+// Having issues finding this: #include <gnu/stubs-lp64.h>
+// this exists though: #include <gnu/stubs-lp64d.h>
+
 #else
 #include <immintrin.h>
 #endif
 #endif
+#endif
 
 #ifdef __F16C__

But to get that right I had to switch to LLVM/clang and I'm still tweaking the build flags.

diff --git a/Makefile b/Makefile
index 93da626..7617e28 100644
--- a/Makefile
+++ b/Makefile
@@ -10,6 +10,8 @@ ifndef UNAME_M
 UNAME_M := $(shell uname -m)
 endif
 
+CXX := clang++-15
+CC := clang-15
 CCV := $(shell $(CC) --version | head -n 1)
 CXXV := $(shell $(CXX) --version | head -n 1)
 
@@ -160,6 +162,9 @@ ifneq ($(filter armv8%,$(UNAME_M)),)
        # Raspberry Pi 4
        CFLAGS += -mfp16-format=ieee -mno-unaligned-access
 endif
+       # TODO: conditional on riscv
+       CFLAGS += -march=rv64i -mabi=lp64
 
 #
 # Print build information

if RISC-V happens to be on your todo list, I'd be happy to follow any pointers! 😁

@dhood dhood changed the title Attempting to add risc-v architecture support Adding risc-v architecture support May 14, 2023
@pikalover6
Copy link

This repo outdated and obsolete. Check out the ggml or llama.cpp repos.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants