By using MLIR, spf-dialect
provides a more portable Sparse Polyhedral Framework (SPF) interface than the existing SPF tools it builds on. SPF is used in a wide variety of research settings. To name a few: SPF is used in synthesizing sparse tensor format conversions and
contractions, and in inspector-executor
compiler optimizations. With spf-dialect
researchers can express SPF in MLIR, and create SPF based optimizations inside MLIR based compilers. Because of the portability of MLIR code generation, SPF based tools can now target a much broader set of hardware than previously possible.
For an MTTKRP kernel, CPU and GPU code generated using spf-dialect
is competitive with code generated using the SPF C
front-end (IEGenLib
), and code from the PASTA benchmark suite. The SPF C
front-end is not capable of generating GPU code.
- Tested against
LLVM
16 at sha:570117b
.
This project builds with CMake
and depends on
LLVM
(MLIR is part of LLVM), and
IEGenLib
. IEGenLib
will be
automatically cloned and built during the spf-dialect
build, however an existing source build of LLVM
is
required before building spf-dialect
.
The LLVM
docs have great instructions on how to build
LLVM, though spf-dialect
requires some
non-standard flags. IEGenLib
requires LLVM
to be built with exception handling and RTTI
(Run Time Type Information), which are not part of a standard LLVM
build.
GPU code generation also requires a few flags to be set. The spf-dialect
tests
require a few LLVM
utilities that aren't part of a regular build. An
example LLVM
build with the required flags is shown here
# shallow clone of llvm to save time
git clone --depth 1 https://github.com/llvm/llvm-project.git
mkdir llvm-project/build && cd llvm-project/build
# To compile LLVM you first have to generate the build script with CMake. Taking
# a look at the flags:
# LLVM_ENABLE_PROJECTS="mlir" - MLIR project must be enabled.
# LLVM_TARGETS_TO_BUILD="X86;NVPTX" - NVPTX adds Nvidia GPU support.
# LLVM_ENABLE_EH=ON - Build llvm with exception handling. This
# is disabled by default, using
# fno-exceptions flag.
# LLVM_ENABLE_RTTI=ON - Build llvm with C++ RTTI.
# LLVM_INSTALL_UTILS=ON - Install utilities, like lit, needed for
# testing spf-dialect.
# MLIR_ENABLE_CUDA_RUNNER=ON - Required for Nvidia GPU code generation
# from MLIR.
cmake -G Ninja ../llvm \
-DLLVM_ENABLE_PROJECTS="mlir" \
-DLLVM_TARGETS_TO_BUILD="X86;NVPTX" \
-DLLVM_REQUIRES_EH=ON \
-DLLVM_ENABLE_RTTI=ON \
-DLLVM_INSTALL_UTILS=ON \
-DMLIR_ENABLE_CUDA_RUNNER=ON
# build all targets
ninja
Building spf-dalect
(once LLVM
is built) requires flags to set the path to the LLVM
build, the path to the lit
tool (built during LLVM
build), and the same RTTI and execption handling flags as the LLVM
build. This setup assumes that you have built LLVM
(with MLIR enabled) in $BUILD_DIR
. To build and launch the tests, run
mkdir build && cd build
# IEGenLib requires building with Makefiles and -j 1 for *reasons*
cmake -G "Unix Makefiles" .. \
-DMLIR_DIR=$BUILD_DIR/lib/cmake/mlir \
-DLLVM_EXTERNAL_LIT=$BUILD_DIR/bin/llvm-lit \
-DLLVM_REQUIRES_EH=ON \
-DLLVM_ENABLE_RTTI=ON
make
make check-spf