Go to file
Aries e74106d784 Update README 2023-01-12 17:31:28 +08:00
.github [NFC] Fix exception in version-check.py script 2022-09-15 13:34:29 +02:00
bolt [DebugInfo] llvm::Optional => std::optional 2022-12-05 00:09:22 +00:00
clang Fix bug in addressing space mapping 2023-01-03 10:45:58 +08:00
clang-tools-extra Remove unused #include "llvm/ADT/Optional.h" 2022-12-05 06:31:11 +00:00
cmake [cmake] Add missing CMakePushCheckState include to FindLibEdit.cmake 2022-11-07 18:20:19 +01:00
compiler-rt Add CSRs and kernel metadata buffer offset constant definition ventus.h 2023-01-06 09:32:07 +08:00
cross-project-tests [dexter-tests] Add attribute optnone to main function 2022-10-26 20:57:49 +00:00
flang Remove unused #include "llvm/ADT/Optional.h" 2022-12-05 06:31:11 +00:00
libc [libc][Obvious] Update error bounds for uint_test.QuickMulHiTests. 2022-12-02 18:13:35 -05:00
libclc Finish all work-item functions implementation except get_enqueued_local_size. 2023-01-09 11:08:41 +08:00
libcxx [libc++][NFC] Fix typo in comment 2022-12-02 12:20:27 -08:00
libcxxabi [libc++abi][LIT][AIX] Use Vector instructions available on Power7 in vec_reg_restore.pass.cpp 2022-11-29 14:08:03 -05:00
libunwind [CMake] Use LLVM_TARGET_TRIPLE in runtimes 2022-11-29 04:08:24 +00:00
lld Remove unused #include "llvm/ADT/Optional.h" 2022-12-05 06:31:11 +00:00
lldb Remove unused #include "llvm/ADT/Optional.h" 2022-12-05 06:31:11 +00:00
llvm Update float point instructions test case 2023-01-12 16:43:47 +08:00
llvm-libgcc [cmake] Slight fix ups to make robust to the full range of GNUInstallDirs 2022-07-26 14:48:49 +00:00
mlir [mlir] Use std::nullopt instead of None in comments (NFC) 2022-12-04 19:58:32 -08:00
openmp [OpenMP][libomptarget] Add hasQueue() function in NextGen plugin's AsyncInfoWrapperTy 2022-12-04 13:24:40 +01:00
polly Remove unused #include "llvm/ADT/Optional.h" 2022-12-05 06:31:11 +00:00
pstl Revert "[cmake] Use `CMAKE_INSTALL_LIBDIR` too" 2022-08-18 22:46:32 -04:00
runtimes [runtimes] Fix runtimes-test-depends 2022-11-30 16:55:51 -08:00
third-party [llvm] [cmake] Set EXCLUDE_FROM_ALL on gtest and TestingSupport 2022-11-24 17:52:22 +01:00
utils [bazel] Add a missing dependency after 786cbb09ed 2022-12-02 16:56:05 +01:00
.arcconfig
.arclint
.clang-format
.clang-tidy Add -misc-const-correctness to .clang-tidy 2022-08-08 13:00:52 -07:00
.git-blame-ignore-revs Add __config formatting to .git-blame-ignore-revs 2022-06-14 09:52:49 -04:00
.gitignore gitignore install folder 2022-12-07 09:07:45 +08:00
.mailmap .mailmap: add entry for myself 2022-12-03 09:52:57 +01:00
CONTRIBUTING.md docs: update some bug tracker references (NFC) 2022-01-10 15:59:08 -08:00
LICENSE.TXT [docs] Add LICENSE.txt to the root of the mono-repo 2022-08-24 09:35:00 +02:00
README-LLVM.md Update README 2022-12-29 09:56:50 +08:00
README.md Update README 2023-01-12 17:31:28 +08:00
SECURITY.md [docs] Describe reporting security issues on the chromium tracker. 2021-05-19 15:21:50 -07:00

README.md

This is the Ventus GPGPU port of LLVM Compiler Infrastructure

Ventus GPGPU is based on RISCV RV32IMAZfinxZve32f ISA with fully redefinition the concept of V-extension.

For more architecture detail, please refer to Ventus GPGPU Arch

Getting Started

Build the toolchain

Assume you have already installed essential build tools such as cmake, clang, ninja etc.

git clone https://github.com/THU-DSP-LAB/llvm-project.git
cd llvm-project
mkdir build && cd build
cmake -DCMAKE_BUILD_TYPE=Debug -DLLVM_CCACHE_BUILD=ON -DLLVM_ENABLE_PROJECTS="clang;lld;libclc" -DLLVM_TARGETS_TO_BUILD="AMDGPU;X86;RISCV" -DLLVM_TARGET_ARCH="riscv32" -DBUILD_SHARED_LIBS=ON -DLLVM_BUILD_LLVM_DYLIB=ON -DLLVM_ENABLE_TERMINFO=ON -DCMAKE_INSTALL_PREFIX=../install -G Ninja ../llvm
ninja

Build libclc

LLVM_DIR=~/workspace/ventus-llvm/build/lib/cmake/llvm cmake -DLLVM_CONFIG=~/workspace/ventus-llvm/install/bin/llvm-config ../../libclc -DCMAKE_LLAsm_COMPILER_WORKS=ON -DCMAKE_CLC_COMPILER_WORKS=ON -DCMAKE_CLC_COMPILER_FORCED=ON  -DCMAKE_LLAsm_FLAGS="-target riscv32 -mcpu=ventus-gpgpu" -DLIBCLC_TARGETS_TO_BUILD="riscv32--" -DCMAKE_CXX_FLAGS="-I ~/workspace/ventus-llvm/llvm/include -std=c++17" -G Ninja

Build pocl

# Add ventus-llvm built llvm-config to PATH
export PATH=<path_to_ventus_llvm_install_bin>:$PATH
git clone https://github.com/THU-DSP-LAB/pocl.git
cd pocl
mkdir build && cd build
# NOTE: LLC_TRIPLE and LLC_HOST_CPU is used for kernel target triple and cpu of the OpenCL device, their name should be definitely renamed.
cmake -DCMAKE_INSTALL_PREFIX=../install -DENABLE_HOST_CPU_DEVICES=OFF -DENABLE_VENTUS=ON -DENABLE_ICD=ON -DENABLE_TESTS=OFF -DSTATIC_LLVM=OFF -G Ninja ../
ninja

# Use following command to building pocl with system installed llvm.
cmake -DCMAKE_INSTALL_PREFIX=../install -DENABLE_ICD=ON -DENABLE_TESTS=OFF -DSTATIC_LLVM=OFF -DLLC_HOST_CPU=x86-64 -G Ninja ../

Build pocl as libOpenCL.so(icd loader+icd driver) instead of libpocl.so(icd driver), -DENABLE_ICD=OFF must be specified to cmake.

NOTE: the install folder of ventus-pocl should be merged with the install folder of ventus-llvm in order to correctly locate shared libraries, header files etc.

NOTE: -DPOCL_DEBUG_MESSAGES=ON is default on but not working? Should we manually specify it?

Build icd loader

You can use apt install ocl-icd-libopencl1 to install ocl icd loader libOpenCL.so, but we want to build our own icd loader with debug information, so here it is.

git clone https://github.com/OCL-dev/ocl-icd.git
cd ocl-icd
./bootstrap
./configure
make
ls .libs # libOpenCL.so is located in .libs

Then copy libOpenCL.so* from ocl-icd/.libs to ventus-llvm/install/lib folder(where LLVM shared libraries located)

Run export LD_LIBRARY_PATH=<path_to>/ventus-llvm/install/lib to tell OpenCL application to use your own built libOpenCL.so, also to correctly locate LLVM shared libraries.

Bridge icd loader libOpenCL.so and pocl ocl device driver libpocl.so(pocl built with ENABLE_ICD=ON)

Run export OCL_ICD_VENDORS=<path_to>/libpocl.so to tell ocl icd loader where the icd driver is.

You will see Ventus GPGPU device is found if your setup is correct.

$ poclcc -l

LIST OF DEVICES:
0:
  Vendor:   Ventus
    Name:   Ventus GPGPU device
 Version:   2.2 HSTR: THU-ventus-gpgpu

Then you can build your OpenCL program with -lOpenCL.

Compile a OpenCL C program into Ventus GPGPU assembly

vector_add.cl:

__kernel void vectorAdd(__global float* A, __global float* B) {
  unsigned tid = get_global_id(0);
  A[tid] += B[tid];
}

Compiler OpenCL C into Ventus assembly:

clang -cl-std=CL2.0 -target riscv32 -mcpu=ventus-gpgpu -O1 -S vector_add.cl -o vector_add.s

TODOs

  • Emit barrier instruction for all stores to local/global memory except sGPR spill.
  • Stacks for sGPR spilling and per-thread usage is supported by using RISCV::X2 as warp level stack, RISCV::X4 as per-thread level stack. But the 2 stack size calculation are not yet splitted out, so a lot of stack slots are wasted.
  • VentusRegextInsertion pass may generate incorrect register ordering for next instruction, see FIXME in that pass. To avoid breaking def-use chain, we could keep the extended instruction unmodified by removing Op.setRegIgnoreDUChain() from the pass, the elf generation pass should ignore the higher bit(>2^5) of the register encoding automatically.
  • Pattern match VV and VX optimization. There is only type information in the DAG pattern matching, we can't specify whether to match a DAG to a vop.vv or vop.vx MIR in a tblgen pattern, so a fix pass should be ran after codegen pass.