HeteroCL

repository·main·Indexed 43 days ago

https://github.com/cornell-zhang/heterocl

A multi-paradigm programming infrastructure for software-defined reconfigurable computing. It provides a Python-based Domain-Specific Language (DSL) and a compilation flow that decouples algorithm specification from hardware customizations for heterogeneous architectures like GPUs and FPGAs, featuring an MLIR-based dialect.

Tokens
1.5K
Snippets
5
Records
5
Agent score
6%

What's inside HeteroCL

  1. Manual LLVM and HCL-MLIR installation for developers

    main

    If you prefer to manage LLVM manually, you must use version v15.0.0. This process involves three main stages: building LLVM with Python bindings, building the HCL-MLIR dialect, and configuring the HeteroCL environment.

    1. Build LLVM (v15.0.0)

    Clone the LLVM project, checkout the specific tag, install requirements, and build with MLIR and Python bindings enabled.

    2. Build HCL-MLIR Dialect

    Clone the hcl-dialect repository and build it using the MLIR_DIR and LLVM_EXTERNAL_LIT paths from your LLVM build directory.

    3. Configure Environment

    Set the PYTHONPATH to include the generated HCL-MLIR library and the HeteroCL root folder, and add the LLVM bin directory to your PATH.

    # 1. Build LLVM
    $ git clone https://github.com/llvm/llvm-project.git
    $ cd llvm-project
    $ git checkout tags/llvmorg-15.0.0
    $ python3 -m pip install -r mlir/python/requirements.txt
    $ mkdir build && cd build
    $ cmake -G "Unix Makefiles" ../llvm \
           -DLLVM_ENABLE_PROJECTS=mlir \
           -DLLVM_BUILD_EXAMPLES=ON \
           -DLLVM_TARGETS_TO_BUILD="host" \
           -DCMAKE_BUILD_TYPE=Release \
           -DLLVM_ENABLE_ASSERTIONS=ON \
           -DLLVM_INSTALL_UTILS=ON \
           -DMLIR_ENABLE_BINDINGS_PYTHON=ON \
           -DPython3_EXECUTABLE=`which python3`
    $ make -j8
    $ export LLVM_BUILD_DIR=$(pwd)
    $ export LLVM_SYMBOLIZER_PATH=$(pwd)/bin/llvm-symbolizer
    
    # 2. Build HCL-MLIR
    $ git clone git@github.com:cornell-zhang/hcl-dialect.git
    $ cd hcl-dialect
    $ mkdir build && cd build
    $ cmake -G "Unix Makefiles" .. \
           -DMLIR_DIR=$LLVM_BUILD_DIR/lib/cmake/mlir \
           -DLLVM_EXTERNAL_LIT=$LLVM_BUILD_DIR/bin/llvm-lit \
           -DPYTHON_BINDING=ON \
           -DOPENSCOP=OFF \
           -DPython3_EXECUTABLE=`which python3`
    $ make -j8
    $ export PYTHONPATH=$(pwd)/tools/hcl/python_packages/hcl_core:${PYTHONPATH}
    
    # 3. Final HeteroCL Setup
    $ cd /path/to/heterocl-root
    $ export PYTHONPATH=$(pwd):${PYTHONPATH}
    $ export PATH=${LLVM_BUILD_DIR}/bin:${PATH}
    $ python3 -m pytest test
  2. Install MLIR-based HeteroCL

    main

    To install the HeteroCL-MLIR dialect, ensure you have the following dependencies installed:

    • gcc >= 5.4
    • cmake >= 3.19
    • python >= 3.7

    Follow these steps to build the HeteroCL-MLIR dialect and connect it with the HeteroCL frontend. Note that installing the LLVM package may take approximately 10 minutes.

    Note for Developers: If you are developing HeteroCL, refer to the HCL-MLIR repository to build the dialect with Python bindings from source instead of using this method.

    git clone https://github.com/cornell-zhang/heterocl.git heterocl-mlir
    cd heterocl-mlir
    git submodule update --init --recursive
    pip install . -v
    # export LLVM path
    export LLVM_BUILD_DIR=$(pwd)/hcl-dialect/externals/llvm-project/build
    export PATH=${LLVM_BUILD_DIR}/bin:${PATH}
  3. Install HeteroCL via pip

    main

    To install HeteroCL, first clone the repository and initialize submodules to pull the required LLVM repository. Then, use pip to install the package, which will automatically install LLVM 15.0.0 and build all dependencies.

    Prerequisites:

    • cmake >= 3.19
    • python >= 3.7

    Post-installation setup: To ensure environment variables are correctly set, add the following to your .bashrc:

    export LLVM_BUILD_DIR=$(pwd)/hcl-dialect/externals/llvm-project/build
    export PATH=${LLVM_BUILD_DIR}/bin:${PATH}
    $ git clone https://github.com/cornell-zhang/heterocl.git heterocl-mlir
    $ cd heterocl-mlir
    $ git submodule update --init --recursive
    $ pip install .
  4. Set the LLVM path environment variable

    main

    To ensure the system can find the LLVM binaries required by HeteroCL, you must export the LLVM_BUILD_DIR and update your PATH to include the LLVM bin directory.

    export LLVM_BUILD_DIR=$(pwd)/hcl-dialect/externals/llvm-project/build
    export PATH=${LLVM_BUILD_DIR}/bin:${PATH}