Skip to content

Commit

Permalink
add optimization stage
Browse files Browse the repository at this point in the history
  • Loading branch information
AyiStar committed Apr 17, 2024
1 parent 0948dcd commit 06c4475
Show file tree
Hide file tree
Showing 467 changed files with 269 additions and 12 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,12 @@ At this stage, we get familiar with the concept of cross compilation, build and

### Porting Stage
- [x] Alter the makefile for LoongArch cross compilation.
- [x] Cross compile llama.cpp to LoongArch64.
- [x] Cross compile llama.cpp to LoongArch64.

### Optimization Stage
Thanks to [the excellent work from Loongson team](https://github.com/ggerganov/llama.cpp/pull/6454), we have a great oppotunity to learn about SIMD acceleration with LoongArch LSX/LASX vector instruction set. Part of our work are based on them.
- [x] Add LSX/LASX SIMD support for GGML_SIMD in `ggml.c`.

### Benchmark Stage
Benchmark goes along with optimization because we always want to know the exact improvement.
- [ ]
18 changes: 11 additions & 7 deletions docs/tools_setup.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
# Set up the cross compilation and emulation tools for LoongArch


- Use the officially provided [build tools](https://github.com/loongson/build-tools).
- Download the binaries of [cross toolchain](https://github.com/loongson/build-tools/releases/download/2023.08.08/CLFS-loongarch64-8.1-x86_64-cross-tools-gcc-glibc.tar.xz) and [QEMU linux-user](https://github.com/loongson/build-tools/releases/download/2023.08.08/qemu-loongarch64).
- Use the officially provided [cross tools](http://www.loongnix.cn/zh/toolchain/GNU/).
- Download the binaries of [cross toolchain](http://ftp.loongnix.cn/toolchain/gcc/release/loongarch/gcc8/loongson-gnu-toolchain-8.3-x86_64-loongarch64-linux-gnu-rc1.3.tar.xz) and [QEMU linux-user](https://github.com/loongson/build-tools/releases/download/2023.08.08/qemu-loongarch64).
- For convenience, set the root dir of build tools and qemu as $LA_TOOLCHAIN and $LA_QEMU, respective. Add $LA_TOOLCHAIN/bin and $LA_QEMU/bin to $PATH.


## Basic Testing

Test with C
```bash
loongarch64-unknown-linux-gnu-gcc hello_loongarch.c -o hello_loongarch
qemu-loongarch64 -L $LA_TOOLCHAIN/target/ -E LD_LIBRARY_PATH=$LA_TOOLCHAIN/target/lib64/:LD_LIBRARY_PATH hello_loongarch
loongarch64-linux-gnu-gcc hello_loongarch.c -o hello_loongarch
qemu-loongarch64 -L $LA_TOOLCHAIN/loongarch64-linux-gnu/sysroot/usr/ -E LD_LIBRARY_PATH=$LA_TOOLCHAIN/loongarch64-linux-gnu/sysroot/usr/lib64/:LD_LIBRARY_PATH hello_loongarch
```

Test with C++
```bash
loongarch64-unknown-linux-gnu-g++ hello_loongarch.cpp -o hello_loongarch
qemu-loongarch64 -L $LA_TOOLCHAIN/target/ -E LD_LIBRARY_PATH=$LA_TOOLCHAIN/loongarch64-unknown-linux-gnu/lib/:LD_LIBRARY_PATH hello_loongarch
loongarch64-linux-gnu-g++ hello_loongarch.cpp -o hello_loongarch
qemu-loongarch64 -L $LA_TOOLCHAIN/target/ -E LD_LIBRARY_PATH=$LA_TOOLCHAIN/loongarch64-linux-gnu/lib/:LD_LIBRARY_PATH hello_loongarch
```

Test LASX support
```bash
loongarch64-linux-gnu-gcc test_lasx.c -o test_lasx -mlasx
```
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions la-llama.cpp/Makefile → llama.cpp-b2430/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ CXX := riscv64-linux-gnu-g++
endif

ifdef LOONGARCH_CROSS_COMPILE
CC := loongarch64-unknown-linux-gnu-gcc
CXX := loongarch64-unknown-linux-gnu-g++
CC := loongarch64-linux-gnu-gcc
CXX := loongarch64-linux-gnu-g++
endif

#
Expand Down Expand Up @@ -287,8 +287,8 @@ ifdef RISCV
MK_CXXFLAGS += -march=rv64gcv -mabi=lp64d

else ifdef LOONGARCH
MK_CFLAGS += -march=loongarch64 -mabi=lp64d
MK_CXXFLAGS += -march=loongarch64 -mabi=lp64d
MK_CFLAGS += -march=loongarch64 -mabi=lp64d -mlasx
MK_CXXFLAGS += -march=loongarch64 -mabi=lp64d -mlasx

else
ifeq ($(UNAME_M),$(filter $(UNAME_M),x86_64 i686 amd64))
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 06c4475

Please sign in to comment.