From 1ae02b38dd9b0d6e103a08c515b7206433384e86 Mon Sep 17 00:00:00 2001 From: EllisLambda Date: Sat, 11 Nov 2023 00:46:41 +0800 Subject: [PATCH] [examples][cmake] Change mimalloc to snmalloc. --- .gitmodules | 6 +++--- CMakeLists.txt | 11 ++++++----- examples/BuddyLlama/CMakeLists.txt | 4 ++-- examples/BuddyLlama/README.md | 9 +++++---- thirdparty/README.md | 29 ++++++++++++++++------------- thirdparty/mimalloc | 1 - thirdparty/snmalloc | 1 + 7 files changed, 33 insertions(+), 28 deletions(-) delete mode 160000 thirdparty/mimalloc create mode 160000 thirdparty/snmalloc diff --git a/.gitmodules b/.gitmodules index 5ed61a5248..8fcac953f1 100644 --- a/.gitmodules +++ b/.gitmodules @@ -2,6 +2,6 @@ path = llvm url = https://github.com/llvm/llvm-project.git branch = main -[submodule "thirdparty/mimalloc"] - path = thirdparty/mimalloc - url = https://github.com/microsoft/mimalloc.git +[submodule "thirdparty/snmalloc"] + path = thirdparty/snmalloc + url = https://github.com/microsoft/snmalloc.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 12ec97b2e8..3af684aa29 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -168,14 +168,15 @@ if(BUDDY_DSL_EXAMPLES) endif() #------------------------------------------------------------------------------- -# The `mimalloc` Configuration +# The `snmalloc` Configuration #------------------------------------------------------------------------------- -if(BUDDY_MLIR_USE_MIMALLOC) - if(MIMALLOC_BUILD_DIR) - list(APPEND CMAKE_PREFIX_PATH ${MIMALLOC_BUILD_DIR}) +if(BUDDY_MLIR_USE_SNMALLOC) + if(SNMALLOC_BUILD_DIR) + list(APPEND CMAKE_PREFIX_PATH ${SNMALLOC_BUILD_DIR}) endif() - find_package(mimalloc REQUIRED) + add_library(snmalloc-static STATIC IMPORTED) + set_property(TARGET snmalloc-static PROPERTY IMPORTED_LOCATION "${SNMALLOC_BUILD_DIR}/libsnmallocshim-static.a") endif() #------------------------------------------------------------------------------- diff --git a/examples/BuddyLlama/CMakeLists.txt b/examples/BuddyLlama/CMakeLists.txt index 53cbb46512..cc8891c1c4 100644 --- a/examples/BuddyLlama/CMakeLists.txt +++ b/examples/BuddyLlama/CMakeLists.txt @@ -125,8 +125,8 @@ set(BUDDY_LLAMA_LIBS mlir_c_runner_utils omp ) -if(BUDDY_MLIR_USE_MIMALLOC) - list(APPEND BUDDY_LLAMA_LIBS mimalloc) +if(BUDDY_MLIR_USE_SNMALLOC) + list(APPEND BUDDY_LLAMA_LIBS snmalloc-static) endif() target_link_libraries(buddy-llama-run ${BUDDY_LLAMA_LIBS}) diff --git a/examples/BuddyLlama/README.md b/examples/BuddyLlama/README.md index 2821e03f87..b8ea059287 100644 --- a/examples/BuddyLlama/README.md +++ b/examples/BuddyLlama/README.md @@ -78,8 +78,8 @@ $ ./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. -If you wish to utilize `mimalloc` as a memory allocator, you need to set `BUDDY_MLIR_USE_MIMALLOC` and `MIMALLOC_BUILD_DIR`. -For more details, please see [here](../../thirdparty/README.md#the-mimalloc-allocator). +If you wish to utilize `smmalloc` as a memory allocator, you need to set `BUDDY_MLIR_USE_SNMALLOC` and `SNMALLOC_BUILD_DIR`. +For more details, please see [here](../../thirdparty/README.md#the-snmalloc-allocator). If you wish to use LTO to optimize the performance, you need to set `BUDDY_MLIR_USE_LTO`. To ensure version compatibility with the project, you need to use the `lld` and `clang` built within the buddy-mlir. We need to make some modifications to the compilation process. @@ -102,7 +102,8 @@ $ ninja check-clang check-mlir omp clang lld 6. Build and run LLaMA example ``` -$ cmake -G Ninja .. -DBUDDY_LLAMA_EXAMPLES=ON \ - -DBUDDY_LLAMA_USE_LTO=ON \ +$ cmake -G Ninja .. \ + -DBUDDY_LLAMA_EXAMPLES=ON \ + -DBUDDY_LLAMA_USE_LTO=ON $ ninja buddy-llama-run ``` \ No newline at end of file diff --git a/thirdparty/README.md b/thirdparty/README.md index 47b711c73a..73700cb846 100644 --- a/thirdparty/README.md +++ b/thirdparty/README.md @@ -1,20 +1,24 @@ # Third-Party Dependencies -## The `mimalloc` Allocator +## The `snmalloc` Allocator -### Build `mimalloc` +### Build `snmalloc` ``` -$ cd buddy-mlir/thirdparty/mimalloc -$ mkdir -p out/release -$ cd out/release -$ cmake -G Ninja ../.. -DCMAKE_INSTALL_PREFIX=$PWD +$ cd buddy-mlir/thirdparty/snmalloc +$ mkdir -p build +$ cd build +$ cmake -G Ninja .. $ ninja install ``` +It may need new C++ feature to build, If there's problem, use the `clang` built within the buddy-mlir, just follow the instruction of LTO. and change the command to +``` +$ cmake -G Ninja ..\ + -DCMAKE_CXX_COMPILER=$PWD/../../../llvm/build/bin/clang++ +``` +### Use `snmalloc` in buddy-mlir -### Use `mimalloc` in buddy-mlir - -Assign the `mimalloc` installation address to the `BUDDY_MLIR_USE_MIMALLOC` CMake variable. +Assign the `snmalloc` installation address to the `BUDDY_MLIR_USE_SNMALLOC` CMake variable. For example: @@ -25,13 +29,12 @@ $ cmake -G Ninja .. \ -DLLVM_DIR=$PWD/../llvm/build/lib/cmake/llvm \ -DLLVM_ENABLE_ASSERTIONS=ON \ -DCMAKE_BUILD_TYPE=RELEASE \ - -DBUDDY_MLIR_USE_MIMALLOC=ON \ - -DMIMALLOC_BUILD_DIR=$PWD/../thirdparty/mimalloc/out/release + -DBUDDY_MLIR_USE_SNMALLOC=ON \ + -DSNMALLOC_BUILD_DIR=$PWD/../thirdparty/snmalloc/build ``` In the `CMakeLists.txt` file, link shared or static library by using: ``` -target_link_libraries(myapp PUBLIC mimalloc) -target_link_libraries(myapp PUBLIC mimalloc-static) +target_link_libraries(myapp PUBLIC snmalloc-static) ``` diff --git a/thirdparty/mimalloc b/thirdparty/mimalloc deleted file mode 160000 index 4e50d6714d..0000000000 --- a/thirdparty/mimalloc +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 4e50d6714d471b72b2285e25a3df6c92db944593 diff --git a/thirdparty/snmalloc b/thirdparty/snmalloc new file mode 160000 index 0000000000..3c3739ddaf --- /dev/null +++ b/thirdparty/snmalloc @@ -0,0 +1 @@ +Subproject commit 3c3739ddafa384da5c89984ec765a22af4d876a5