Skip to content

Commit

Permalink
[RVV] Add static runner utils libraries for RVV environment.
Browse files Browse the repository at this point in the history
Co-authored-by: SForeKeeper <[email protected]>
  • Loading branch information
zhanghb97 and SForeKeeper committed Feb 22, 2024
1 parent 3491e9b commit 057dc47
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 18 deletions.
8 changes: 6 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR BUDDY_MLIR_OUT_OF_TREE_

set(LLVM_MLIR_BINARY_DIR ${MLIR_DIR}/../../../bin)
set(LLVM_MLIR_LIBRARY_DIR ${MLIR_DIR}/../../../lib)
set(LLVM_MLIR_SOURCE_DIR ${MLIR_DIR}/../../../../mlir)
set(LLVM_PROJECT_BUILD_DIR ${MLIR_DIR}/../../../)
set(LLVM_PROJECT_SOURCE_DIR ${MLIR_DIR}/../../../../)
if(NOT DEFINED LLVM_PROJECT_SOURCE_DIR)
get_filename_component(LLVM_PROJECT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/llvm/ ABSOLUTE)
endif()
set(LLVM_MLIR_SOURCE_DIR ${LLVM_PROJECT_SOURCE_DIR}/mlir)

list(APPEND CMAKE_MODULE_PATH "${MLIR_CMAKE_DIR}")
list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}")
Expand Down Expand Up @@ -83,12 +85,14 @@ endif()
set(BUDDY_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(BUDDY_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR})
set(BUDDY_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/bin)
set(BUDDY_LIBRARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/lib)
set(BUDDY_EXAMPLES_DIR ${BUDDY_SOURCE_DIR}/examples)
set(BUDDY_MIDEND_INCLUDE_DIR ${BUDDY_SOURCE_DIR}/midend/include/)
set(BUDDY_THIRDPARTY_INCLUDE_DIR ${BUDDY_SOURCE_DIR}/thirdparty/include/)
set(BUDDY_MLIR_PYTHON_PACKAGES_DIR ${BUDDY_BUILD_DIR}/python_packages)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${BUDDY_BINARY_DIR})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${BUDDY_LIBRARY_DIR})

set(BUDDY_EXAMPLES OFF CACHE BOOL "Build examples")
set(BUDDY_ENABLE_OPENCV OFF CACHE BOOL "Enable OpenCV support.")
Expand Down
1 change: 1 addition & 0 deletions examples/VectorExpDialect/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
log*
core
a.out
*.elf
36 changes: 20 additions & 16 deletions examples/VectorExpDialect/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ CROSS_MLIR_CPU_RUNNER := ../../thirdparty/build-cross-mlir/bin/mlir-cpu-runner
CROSS_MLIR_C_RUNNER_UTILS := ../../thirdparty/build-cross-mlir/lib/libmlir_c_runner_utils.so
CROSS_MLIR_RUNNER_UTILS := ../../thirdparty/build-cross-mlir/lib/libmlir_runner_utils.so
CROSS_MLIR_LIB := ../../thirdparty/build-cross-mlir/lib
CROSS_BUDDY_MLIR_LIB := ../../thirdparty/build-cross-buddy-mlir/lib/

ifeq ($(shell uname),Linux)
MLIR_RUNNER_UTILS := ../../llvm/build/lib/libmlir_runner_utils.so
Expand Down Expand Up @@ -142,22 +143,25 @@ vector-exp-predication-matmul-aot:
-o a.out
@LD_LIBRARY_PATH=${CROSS_MLIR_LIB} ${QEMU} -L ${RISCV_GNU_TOOLCHAIN_SYSROOT} -cpu rv64,x-v=true,vlen=128 a.out

# vector-exp-predication-matmul-elf:
# @${BUDDY_OPT} ./vector-exp-predication-matmul.mlir \
# -lower-affine \
# -convert-scf-to-cf \
# -convert-math-to-llvm \
# -lower-vector-exp \
# -lower-rvv \
# -convert-vector-to-llvm \
# -finalize-memref-to-llvm \
# -convert-func-to-llvm \
# -reconcile-unrealized-casts |\
# ${BUDDY_TRANSLATE} -buddy-to-llvmir | \
# ${LLC} -mtriple riscv64 -mattr=+v,+m -riscv-v-vector-bits-min=128 -filetype=obj -o log.o
# @${RISCV_GNU_TOOLCHAIN}/bin/riscv64-unknown-linux-gnu-gcc log.o \
# -static \
# -o log.elf
vector-exp-predication-matmul-elf:
@${BUDDY_OPT} ./vector-exp-predication-matmul.mlir \
-lower-affine \
-convert-scf-to-cf \
-convert-math-to-llvm \
-lower-vector-exp \
-lower-rvv \
-convert-vector-to-llvm \
-finalize-memref-to-llvm \
-convert-func-to-llvm \
-reconcile-unrealized-casts |\
${BUDDY_TRANSLATE} -buddy-to-llvmir | \
${LLC} -mtriple riscv64 -mattr=+v,+m -riscv-v-vector-bits-min=128 -filetype=obj -o log.o
@${RISCV_GNU_TOOLCHAIN}/bin/riscv64-unknown-linux-gnu-gcc log.o \
-static \
-L${CROSS_BUDDY_MLIR_LIB} \
-lStaticMLIRCRunnerUtils -lStaticMLIRRunnerUtils \
-lstdc++ \
-o test.elf

vector-exp-add-mask-run:
@${BUDDY_OPT} ./vector-exp-add-mask.mlir \
Expand Down
24 changes: 24 additions & 0 deletions midend/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ add_subdirectory(Conversion)
add_subdirectory(Target)
add_subdirectory(Utils)

# Build static library for async runtime.
add_mlir_library(static_mlir_async_runtime
STATIC
${MLIR_MAIN_SRC_DIR}/lib/ExecutionEngine/AsyncRuntime.cpp
Expand All @@ -17,3 +18,26 @@ target_compile_definitions(static_mlir_async_runtime
PRIVATE
MLIR_ASYNCRUNTIME_DEFINE_FUNCTIONS
)

# Build static library for MLIR C runner utils runtime.
add_mlir_library(StaticMLIRCRunnerUtils
${MLIR_MAIN_SRC_DIR}/lib/ExecutionEngine/CRunnerUtils.cpp
${MLIR_MAIN_SRC_DIR}/lib/ExecutionEngine/SparseTensorRuntime.cpp

EXCLUDE_FROM_LIBMLIR

LINK_LIBS PUBLIC
mlir_float16_utils
MLIRSparseTensorEnums
MLIRSparseTensorRuntime
)
set_property(TARGET StaticMLIRCRunnerUtils PROPERTY CXX_STANDARD 17)
target_compile_definitions(StaticMLIRCRunnerUtils PRIVATE StaticMLIRCRunnerUtils_EXPORTS)

# Build static library for MLIR runner utils runtime.
add_mlir_library(StaticMLIRRunnerUtils
${MLIR_MAIN_SRC_DIR}/lib/ExecutionEngine/RunnerUtils.cpp

EXCLUDE_FROM_LIBMLIR
)
target_compile_definitions(StaticMLIRRunnerUtils PRIVATE StaticMLIRRunnerUtils_EXPORTS)
1 change: 1 addition & 0 deletions thirdparty/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
/build-local-clang
/build-cross-clang
/build-cross-mlir
/build-cross-buddy-mlir
28 changes: 28 additions & 0 deletions thirdparty/build-rvv-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,31 @@ then
else
echo "mlir for riscv64 was built already"
fi

#-------------------------------------------------------------------------------
# Build cross Buddy-MLIR
#-------------------------------------------------------------------------------

if [ ! -d "build-cross-buddy-mlir" ]
then
mkdir build-cross-buddy-mlir
cd build-cross-buddy-mlir
cmake -G Ninja ../../ \
-DCMAKE_SYSTEM_NAME=Linux \
-DMLIR_DIR=$PWD/../build-cross-mlir/lib/cmake/mlir \
-DLLVM_DIR=$PWD/../build-cross-mlir/lib/cmake/llvm \
-DCMAKE_CROSSCOMPILING=True \
-DLLVM_TARGETS_TO_BUILD=RISCV \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_ENABLE_ASSERTIONS=ON \
-DLLVM_NATIVE_ARCH=RISCV \
-DLLVM_HOST_TRIPLE=riscv64-unknown-linux-gnu \
-DCMAKE_C_COMPILER=$PWD/../build-local-clang/bin/clang \
-DCMAKE_CXX_COMPILER=$PWD/../build-local-clang/bin/clang++ \
-DCMAKE_C_FLAGS="--target=riscv64-unknown-linux-gnu --sysroot=$PWD/../build-riscv-gnu-toolchain/sysroot --gcc-toolchain=$PWD/../build-riscv-gnu-toolchain" \
-DCMAKE_CXX_FLAGS="--target=riscv64-unknown-linux-gnu --sysroot=$PWD/../build-riscv-gnu-toolchain/sysroot --gcc-toolchain=$PWD/../build-riscv-gnu-toolchain" \
-DLLVM_ENABLE_ZSTD=Off
ninja StaticMLIRCRunnerUtils StaticMLIRRunnerUtils
else
echo "buddy-mlir libs for riscv64 was built already"
fi

0 comments on commit 057dc47

Please sign in to comment.