Skip to content

Commit

Permalink
[examples][BuddyLlama] Limit the parallelization level and add Mimall…
Browse files Browse the repository at this point in the history
…oc option.
  • Loading branch information
EllisLambda committed Oct 29, 2023
1 parent f356a61 commit 1edc891
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
22 changes: 17 additions & 5 deletions examples/BuddyLlama/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ add_custom_command(
-linalg-bufferize
-convert-linalg-to-affine-loops
-affine-loop-fusion
-affine-parallelize
-affine-parallelize="max-nested=2"
-lower-affine
-convert-scf-to-openmp
-func-bufferize
Expand Down Expand Up @@ -48,10 +48,22 @@ SET_SOURCE_FILES_PROPERTIES(
EXTERNAL_OBJECT true
GENERATED true)

SET_TARGET_PROPERTIES(
LLAMA
PROPERTIES
LINKER_LANGUAGE C)
if(${BUDDY_LLAMA_EXAMPLES_ENABLE_MIMALLOC})
add_library(MIMALLOC_STATIC STATIC IMPORTED)
set_target_properties(MIMALLOC_STATIC PROPERTIES
IMPORTED_LOCATION "${BUDDY_SOURCE_DIR}/thirdparty/mimalloc/out/release/mimalloc.o"
)
SET_TARGET_PROPERTIES(
MIMALLOC_STATIC
LLAMA
PROPERTIES
LINKER_LANGUAGE C)
elseif()
SET_TARGET_PROPERTIES(
LLAMA
PROPERTIES
LINKER_LANGUAGE C)
endif()

add_executable(buddy-llama-run llama-main.cpp)
target_link_directories(buddy-llama-run PRIVATE ${LLVM_MLIR_LIBRARY_DIR})
Expand Down
18 changes: 18 additions & 0 deletions examples/BuddyLlama/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,21 @@ $ cd bin
$ ./buddy-llama-run
```
This build will spend a few minutes. We recommend you to use better cpu such as server-level cpu to run buddy-llama-run.

To improve performance and reduce memory usage, you can use mimalloc for memory allocation. You can follow the steps below to build.
```
$ cd buddy-mlir
$ git submodule add \
https://github.com/microsoft/mimalloc.git thirdparty/mimalloc
$ git submodule update
$ cd thirdparty/mimalloc
$ mkdir -p out/release
$ cd out/release
$ cmake ../..
$ make
$ cd ../../../../../build
$ cmake -G Ninja .. \
-DBUDDY_LLAMA_EXAMPLES=ON \
-DBUDDY_LLAMA_EXAMPLES_ENABLE_MIMALLOC=ON
$ ninja buddy-llama-run
```
3 changes: 3 additions & 0 deletions thirdparty/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@
/build-local-clang
/build-cross-clang
/build-cross-mlir

# Mimalloc
/mimalloc

0 comments on commit 1edc891

Please sign in to comment.