Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to run outside of Docker? #12

Open
godjos opened this issue Mar 27, 2024 · 1 comment
Open

How to run outside of Docker? #12

godjos opened this issue Mar 27, 2024 · 1 comment
Assignees

Comments

@godjos
Copy link

godjos commented Mar 27, 2024

Hello! I really think your work is excellent, but I have a question to ask: Since I would like to integrate your work into another sparse solver, such as Petsc, could you please provide information on the software dependencies required and offer an example code for that integration?

@Sibylau Sibylau self-assigned this Apr 29, 2024
@Sibylau
Copy link
Collaborator

Sibylau commented May 6, 2024

Hi! Sorry for the late reply. Here are software dependencies:

  • LLVM 15.0.0 release
  • cmake v3.18.0
  • Eigen v3.4.0 $wget https://gitlab.com/libeigen/eigen/-/archive/3.4.0/eigen-3.4.0.tar.gz
  • ninja v1.10.1 (optional)

when building LLVM, please make sure to enable projects clang, lld and mlir. Assume the LLVM project path is $LLVM_ROOT. Here's an example build command for LLVM without ninja:

$ mkdir -p $LLVM_ROOT/build && cd $LLVM_ROOT/build
$ cmake ../llvm -DLLVM_ENABLE_PROJECTS="clang;lld;mlir" \
        -DLLVM_BUILD_EXAMPLES=ON -DLLVM_TARGETS_TO_BUILD="host;NVPTX" \
        -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=ON \
        -DLLVM_INSTALL_UTILS=ON -DLLVM_BUILD_UTILS=ON \
        -DLLVM_USE_LINKER=lld -DMLIR_INCLUDE_INTEGRATION_TESTS=ON \
        -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++
 $ cmake --build . -j $(nproc)

Please export the corresponding environment variables for cmake, eigen and LLVM tools.
Please install openmp in LLVM and add the environment variables as well:

$ cd $LLVM_ROOT/openmp && \
    mkdir build && cd build && \
    cmake -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ .. 
$ make -j $(nproc)
$ export CPATH=$LLVM_ROOT/openmp/build/runtime/src:$CPATH
$ export LD_LIBRARY_PATH=$LLVM_ROOT/openmp/build/runtime/src:$LD_LIBRARY_PATH

After finishing the installation, build the UniSparse project and add the environment variables. Assume the UniSparse project path is $UniSparse_ROOT:

$ mkdir -p $UniSparse_ROOT/build && cd $UniSparse_ROOT/build
$ cmake .. \
   -DMLIR_DIR=$LLVM_ROOT/build/lib/cmake/mlir \
   -DLLVM_EXTERNAL_LIT=$LLVM_ROOT/build/bin/llvm-lit \
   -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ 
$ cmake --build . -j $(nproc)
$ export LD_LIBRARY_PATH=$UniSparse_ROOT/build/lib:$LD_LIBRARY_PATH
$ export PATH=$UniSparse_ROOT/build/bin:$PATH

Let's use the CSR SpMM example to show how to run an example test case. Go to $ UniSparse_ROOT/test/UniSparse/KernelGen/CPU, run:

$ unisparse-opt ./unisparse_csr_spmm_F32.mlir -unisparse-codegen -lower-format-conversion -lower-struct -dce | \
    mlir-opt -one-shot-bufferize="bufferize-function-boundaries=1 allow-return-allocs unknown-type-conversion=identity-layout-map function-boundary-type-conversion=identity-layout-map" \
    -finalizing-bufferize -convert-linalg-to-loops -convert-vector-to-scf -convert-scf-to-cf -lower-affine \
    -convert-vector-to-llvm -convert-memref-to-llvm -convert-complex-to-standard -convert-math-to-llvm \
    -convert-math-to-libm -convert-complex-to-libm -convert-complex-to-llvm -convert-func-to-llvm \
    -reconcile-unrealized-casts  | mlir-translate -mlir-to-llvmir | opt -O3 -S | llc -O3 -relocation-model=pic -filetype=obj -o csr_spmm_F32.o

$ clang++ csr_spmm_F32.o -L$SPLHOME/build/lib -lmlir_unisparse_runner_utils \
     -L$LLVM_ROOT/build/lib -lmlir_runner_utils -lmlir_c_runner_utils -o csr_spmm_F32

Be sure to export the $TENSOR0 environment variable to be the path of the sparse matrix under test. Here we can use a simple matrix under $UniSparse_ROOT/test/Data/tensor46.mtx.

$ export TENSOR0=$UniSparse_ROOT/test/Data/tensor46.mtx
$ ./csr_spmm_F32

And it will print out the output result of SpMM.

Hope it helps, and please let me know if you have any issues!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants