Skip to content

Commit

Permalink
[thirdparty] Add mimalloc third-party dependency.
Browse files Browse the repository at this point in the history
Co-authored-by: EllisLambda <[email protected]>
  • Loading branch information
zhanghb97 and EllisLambda committed Oct 30, 2023
1 parent ba241c1 commit efcacbd
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +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
11 changes: 11 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,17 @@ if(BUDDY_DSL_EXAMPLES)
find_package(ANTLR REQUIRED)
endif()

#-------------------------------------------------------------------------------
# The `mimalloc` Configuration
#-------------------------------------------------------------------------------

if(BUDDY_MLIR_USE_MIMALLOC)
if(MIMALLOC_BUILD_DIR)
list(APPEND CMAKE_PREFIX_PATH ${MIMALLOC_BUILD_DIR})
endif()
find_package(mimalloc REQUIRED)
endif()

#-------------------------------------------------------------------------------
# Initialize Python packages
#-------------------------------------------------------------------------------
Expand Down
37 changes: 37 additions & 0 deletions thirdparty/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Third-Party Dependencies

## The `mimalloc` Allocator

### Build `mimalloc`

```
$ cd buddy-mlir/thirdparty/mimalloc
$ mkdir -p out/release
$ cd out/release
$ cmake -G Ninja ../.. -DCMAKE_INSTALL_PREFIX=$PWD
$ ninja install
```

### Use `mimalloc` in buddy-mlir

Assign the `mimalloc` installation address to the `BUDDY_MLIR_USE_MIMALLOC` CMake variable.

For example:

```
$ cd buddy-mlir/build
$ cmake -G Ninja .. \
-DMLIR_DIR=$PWD/../llvm/build/lib/cmake/mlir \
-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
```

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)
```
1 change: 1 addition & 0 deletions thirdparty/mimalloc
Submodule mimalloc added at 4e50d6

0 comments on commit efcacbd

Please sign in to comment.