构建说明
要求
- 可用的C和C++工具链(编译器、链接器)
- cmake
- make或ninja
1. 克隆Polygeist
git clone --recursive https://github.com/llvm/Polygeist
cd Polygeist
2. 安装LLVM、MLIR、Clang和Polygeist
选项1:使用预构建的LLVM、MLIR和Clang
Polygeist可以通过提供预构建的MLIR和Clang工具链的路径来构建。
1. 构建LLVM、MLIR和Clang:
mkdir llvm-project/build
cd llvm-project/build
cmake -G Ninja ../llvm \
-DLLVM_ENABLE_PROJECTS="mlir;clang" \
-DLLVM_TARGETS_TO_BUILD="host" \
-DLLVM_ENABLE_ASSERTIONS=ON \
-DCMAKE_BUILD_TYPE=DEBUG
ninja
ninja check-mlir
要启用CUDA编译,请添加-DMLIR_ENABLE_CUDA_RUNNER=1
并从cmake参数中移除-DLLVM_TARGETS_TO_BUILD="host"
。(您可能需要指定CUDACXX
、CUDA_PATH
和/或-DCMAKE_CUDA_COMPILER
)
要启用ROCM后端,请添加-DMLIR_ENABLE_ROCM_RUNNER=1
并从cmake参数中移除-DLLVM_TARGETS_TO_BUILD="host"
。(您可能需要指定-DHIP_CLANG_INCLUDE_PATH
和/或ROCM_PATH
)
对于启用ISL的polymer,必须将polly
添加到LLVM_ENABLE_PROJECTS
变量中。
为了加快编译速度,我们建议使用-DLLVM_USE_LINKER=lld
。
2. 构建Polygeist:
mkdir build
cd build
cmake -G Ninja .. \
-DMLIR_DIR=$PWD/../llvm-project/build/lib/cmake/mlir \
-DCLANG_DIR=$PWD/../llvm-project/build/lib/cmake/clang \
-DLLVM_TARGETS_TO_BUILD="host" \
-DLLVM_ENABLE_ASSERTIONS=ON \
-DCMAKE_BUILD_TYPE=DEBUG
ninja
ninja check-polygeist-opt && ninja check-cgeist
为了加快编译速度,我们建议使用-DPOLYGEIST_USE_LINKER=lld
。
GPU后端
要启用CUDA后端,请添加-DPOLYGEIST_ENABLE_CUDA=1
要启用ROCM后端,请添加-DPOLYGEIST_ENABLE_ROCM=1
Polymer
要启用polymer,请添加-DPOLYGEIST_ENABLE_POLYMER=1
可以构建两种polymer配置 - 一种使用Pluto,另一种使用ISL。
Pluto
添加-DPOLYGEIST_POLYMER_ENABLE_PLUTO=1
这将导致cmake调用拉取并构建polymer的依赖项。要指定依赖项的自定义目录,请指定-DPOLYMER_DEP_DIR=<绝对路径>
。依赖项将使用tools/polymer/build_polymer_deps.sh
进行构建。
要运行polymer pluto测试,请使用ninja check-polymer
。
ISL
添加-DPOLYGEIST_POLYMER_ENABLE_ISL=1
这需要一个启用了polly
作为子项目的llvm-project
构建。
选项2:使用统一的LLVM、MLIR、Clang和Polygeist构建
Polygeist也可以作为外部LLVM项目使用LLVM_EXTERNAL_PROJECTS进行构建。
- 构建LLVM、MLIR、Clang和Polygeist:
mkdir build
cd build
cmake -G Ninja ../llvm-project/llvm \
-DLLVM_ENABLE_PROJECTS="clang;mlir" \
-DLLVM_EXTERNAL_PROJECTS="polygeist" \
-DLLVM_EXTERNAL_POLYGEIST_SOURCE_DIR=.. \
-DLLVM_TARGETS_TO_BUILD="host" \
-DLLVM_ENABLE_ASSERTIONS=ON \
-DCMAKE_BUILD_TYPE=DEBUG
ninja
ninja check-polygeist-opt && ninja check-cgeist
ninja check-polygeist-opt
运行Polygeist/test/polygeist-opt
中的测试
ninja check-cgeist
运行Polygeist/tools/cgeist/Test
中的测试
引用Polygeist
如果您使用Polygeist,请考虑引用以下相关出版物:
@inproceedings{polygeistPACT,
title = {Polygeist: Raising C to Polyhedral MLIR},
author = {Moses, William S. and Chelini, Lorenzo and Zhao, Ruizhe and Zinenko, Oleksandr},
booktitle = {Proceedings of the ACM International Conference on Parallel Architectures and Compilation Techniques},
numpages = {12},
location = {Virtual Event},
series = {PACT '21},
publisher = {Association for Computing Machinery},
year = {2021},
address = {New York, NY, USA},
keywords = {Polygeist, MLIR, Polyhedral, LLVM, Compiler, C++, Pluto, Polly, OpenScop, Parallel, OpenMP, Affine, Raising, Transformation, Splitting, Automatic-Parallelization, Reduction, Polybench},
}
@inproceedings{10.1145/3572848.3577475,
author = {Moses, William S. and Ivanov, Ivan R. and Domke, Jens and Endo, Toshio and Doerfert, Johannes and Zinenko, Oleksandr},
title = {High-Performance GPU-to-CPU Transpilation and Optimization via High-Level Parallel Constructs},
year = {2023},
isbn = {9798400700156},
publisher = {Association for Computing Machinery},
address = {New York, NY, USA},
url = {https://doi.org/10.1145/3572848.3577475},
doi = {10.1145/3572848.3577475},
booktitle = {Proceedings of the 28th ACM SIGPLAN Annual Symposium on Principles and Practice of Parallel Programming},
pages = {119–134},
numpages = {16},
keywords = {MLIR, polygeist, CUDA, barrier synchronization},
location = {Montreal, QC, Canada},
series = {PPoPP '23}
}
@inproceedings{10444828,
author = {Ivanov, Ivan R. and Zinenko, Oleksandr and Domke, Jens and Endo, Toshio and Moses, William S.},
booktitle = {2024 IEEE/ACM International Symposium on Code Generation and Optimization (CGO)},
title = {Retargeting and Respecializing GPU Workloads for Performance Portability},
year = {2024},
volume = {},
issn = {},
pages = {119-132},
doi = {10.1109/CGO57630.2024.10444828},
url = {https://doi.ieeecomputersociety.org/10.1109/CGO57630.2024.10444828},
publisher = {IEEE Computer Society},
address = {Los Alamitos, CA, USA},
month = {mar}
}