Skip to content

Latest commit

 

History

History
131 lines (91 loc) · 2.74 KB

File metadata and controls

131 lines (91 loc) · 2.74 KB

XeGPU examples

Installation

1. GPU Drivers and Level Zero

Install Intel GPU drivers and Level Zero runtime on your system.

2. Compile LLVM with Intel GPU support

To use Lighthouse with Intel GPUs, LLVM must be built with LevelZero runtime.

Set up a Python environment and install Python packages:

pip install pybind11 nanobind PyYAML numpy

Set LLVM_INSTALL_DIR and use the below script to checkout and compile LLVM locally.

export LLVM_INSTALL_DIR=<...>
export LLVM_VERSION=45bee6efe9d6

git clone https://github.com/llvm/llvm-project.git
cd llvm-project
git checkout $LLVM_VERSION
mkdir -p build
cd build

cmake ../llvm -G Ninja \
  -DCMAKE_BUILD_TYPE=Release \
  -DLLVM_ENABLE_PROJECTS=mlir \
  -DLLVM_BUILD_EXAMPLES=OFF \
  -DLLVM_TARGETS_TO_BUILD="host" \
  -DLLVM_ENABLE_ASSERTIONS=ON \
  -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD="SPIRV" \
  -DLLVM_INSTALL_GTEST=ON \
  -DMLIR_ENABLE_LEVELZERO_RUNNER=1 \
  -DMLIR_ENABLE_BINDINGS_PYTHON=1 \
  -DPython3_EXECUTABLE=$(which python3) \
  -DLLVM_INSTALL_UTILS=ON \
  -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR}
cmake --build .
cmake --install .

If cmake cannot find LevelZero, set environment variable LEVEL_ZERO_DIR=<path-to-level-zero-install-root>.

Install Lighthouse

Install Lighthouse as instructed in the main README.

Override the default LLVM package by setting PYTHONPATH to the local LLVM Python bindings:

export PYTHONPATH=${LLVM_INSTALL_DIR}/python_packages/mlir_core

If you wish to point to the build directory instead, do:

export PYTHONPATH=${LLVM_BUILD_DIR}/tools/mlir/python_packages/mlir_core/

Matrix multiplication benchmark

Run the default 4k (float16, float16) -> float32 matrix multiplication benchmark with correctness test:

python matmul.py --check-result

Set different M, N, K problem size

python matmul.py --sizes 1024 2048 4096 ...

Run with ReLU post-op:

python matmul.py --relu ...

See all command line arguments:

python matmul.py --help

Multilayer Perceptron (MLP) benchmark

Run the default single layer MLP (batch=1024, input_features=1024, output_features=1024) benchmark with correctness test:

python mlp.py --check-result

which is equivalent to

python mlp.py -b 1024 -i 1024 -o 1024 --check-result

Run a 3-layer MLP with batch size 128:

python mlp.py -b 128 -i 16384 -o 8192 --hidden-sizes 16384 16384 ...

which corresponds to

MLP with 3 layers
  Layer 0: M=128, N=16384, K=16384
  Layer 1: M=128, N=16384, K=16384
  Layer 2: M=128, N=8192, K=16384

Add bias to all layers and ReLU to hidden layers:

python mlp.py --bias --relu ...

See all command line arguments:

python mlp.py --help