Skip to content

Commit dd64976

Browse files
authored
[examples][xegpu-matmul] Add XeGPU matrix multiplication example (#28)
Adds XeGPU matrix multiplication example that runs the payload, checks correctness and measures performance. * `matmul.py` is the main script with CLI. * `README.md` has installation instructions and usage examples.
1 parent bd87f3f commit dd64976

File tree

8 files changed

+1259
-1
lines changed

8 files changed

+1259
-1
lines changed

.github/workflows/examples.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ jobs:
2828
- name: Run lit-enabled examples as tests
2929
run: |
3030
export FILECHECK=FileCheck-18 # Ubuntu's llvm-dev appends a version number.
31-
uv run lit python/examples # Makes sure to substitute FileCheck for $FILECHECK
31+
uv run lit python/examples --verbose # Makes sure to substitute FileCheck for $FILECHECK
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# XeGPU matrix multiplication benchmark
2+
3+
## Installation
4+
5+
### 1. GPU Drivers and Level Zero
6+
7+
Install Intel GPU drivers and Level Zero runtime on your system.
8+
9+
### 2. Compile LLVM with Intel GPU support
10+
11+
To use Lighthouse with Intel GPUs, LLVM must be built with LevelZero runtime.
12+
13+
Set up a Python environment and install Python packages:
14+
15+
```bash
16+
pip install pybind11 nanobind PyYAML numpy
17+
```
18+
19+
Set `LLVM_INSTALL_DIR` and use the below script to checkout and compile LLVM locally.
20+
21+
```bash
22+
export LLVM_INSTALL_DIR=<...>
23+
LLVM_VERSION=83765f435d1c
24+
git checkout https://github.com/llvm/llvm-project.git -b $LLVM_VERSION
25+
26+
cd llvm-project
27+
mkdir -p build
28+
cd build
29+
30+
cmake ../llvm -G Ninja \
31+
-DCMAKE_BUILD_TYPE=Release \
32+
-DLLVM_ENABLE_PROJECTS=mlir \
33+
-DLLVM_BUILD_EXAMPLES=OFF \
34+
-DLLVM_TARGETS_TO_BUILD="host" \
35+
-DLLVM_ENABLE_ASSERTIONS=ON \
36+
-DLLVM_ENABLE_RTTI=ON \
37+
-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD="SPIRV" \
38+
-DLLVM_INSTALL_GTEST=ON \
39+
-DMLIR_ENABLE_LEVELZERO_RUNNER=1 \
40+
-DMLIR_ENABLE_BINDINGS_PYTHON=1 \
41+
-DPython3_EXECUTABLE=$(which python3) \
42+
-DLLVM_INSTALL_UTILS=ON \
43+
-DCMAKE_INSTALL_PREFIX=${INSTALL_DIR}
44+
cmake --build .
45+
cmake --install .
46+
```
47+
48+
If cmake cannot find LevelZero, set environment variable `LEVEL_ZERO_DIR=<path-to-level-zero-install-root>`.
49+
50+
### Install Lighthouse
51+
52+
Install Lighthouse as instructed in the main [README](../../../README.md).
53+
54+
Override the default LLVM package by setting `PYTHONPATH` to the local LLVM Python bindings:
55+
56+
```bash
57+
export PYTHONPATH=${LLVM_INSTALL_DIR}/python_packages/mlir_core
58+
```
59+
60+
## Usage
61+
62+
Run the default 4k (float16, float16) -> float32 matrix multiplication benchmark with correctness test:
63+
64+
```bash
65+
python matmul.py --check-result
66+
```
67+
68+
Set different M, N, K problem size
69+
70+
```bash
71+
python matmul.py --sizes 1024 2048 4096 ...
72+
```
73+
74+
Run with ReLU post-op:
75+
76+
```bash
77+
python matmul.py --relu ...
78+
```
79+
80+
See all command line arguments:
81+
82+
```bash
83+
python matmul.py --help
84+
```
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
config.excludes = ["mlir_utils.py", "payload.py", "runner.py", "schedule.py"]

0 commit comments

Comments
 (0)