Skip to content

Commit 0f62988

Browse files
authored
Introduce Makefile and some runner targets (#15822)
This way we can do ``` make llama-cpu ``` to build llama runner with CPU backend, instead of the original: ``` cmake --preset llm -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=cmake-out cmake --build cmake-out -j16 --target install --config Release cmake -DCMAKE_INSTALL_PREFIX=cmake-out \ -DCMAKE_BUILD_TYPE=Release \ -Bcmake-out/examples/models/llama \ examples/models/llama cmake --build cmake-out/examples/models/llama -j16 --config Release ``` I added a bunch of runners such as whisper, gemma3, voxtral and llava. Another good thing about `Makefile` is that it supports tab completion. ### Test plan Manually tested a few of them. Changed CI job to use these commands.
1 parent 960c021 commit 0f62988

File tree

12 files changed

+628
-85
lines changed

12 files changed

+628
-85
lines changed

.ci/scripts/test_llama.sh

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -171,15 +171,14 @@ cmake_build_llama_runner() {
171171
git submodule update --init
172172
popd
173173
dir="examples/models/llama"
174-
retry cmake \
175-
-DEXECUTORCH_BUILD_TESTS=ON \
176-
-DBUILD_TESTING=OFF \
177-
-DCMAKE_INSTALL_PREFIX=cmake-out \
178-
-DCMAKE_BUILD_TYPE="$CMAKE_BUILD_TYPE" \
179-
-Bcmake-out/${dir} \
180-
${dir}
181-
cmake --build cmake-out/${dir} -j9 --config "$CMAKE_BUILD_TYPE"
182-
174+
if [[ "$CMAKE_BUILD_TYPE" == "Debug" ]]; then
175+
PRESET="llama-debug"
176+
else
177+
PRESET="llama-release"
178+
fi
179+
pushd "${dir}"
180+
cmake --workflow --preset "${PRESET}"
181+
popd
183182
}
184183

185184
cleanup_files() {

.ci/scripts/test_model_e2e.sh

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -156,24 +156,13 @@ echo "::endgroup::"
156156

157157
echo "::group::Build $MODEL_NAME Runner"
158158

159-
if [ "$DEVICE" = "cuda" ]; then
160-
WORKFLOW="llm-release-cuda"
161-
BUILD_BACKEND="EXECUTORCH_BUILD_CUDA"
162-
elif [ "$DEVICE" = "metal" ]; then
163-
WORKFLOW="llm-release-metal"
164-
BUILD_BACKEND="EXECUTORCH_BUILD_METAL"
165-
else
159+
if [ "$DEVICE" != "cuda" ] && [ "$DEVICE" != "metal" ]; then
166160
echo "Error: Unsupported device '$DEVICE'. Must be 'cuda' or 'metal'."
167161
exit 1
168162
fi
169163

170-
cmake --workflow $WORKFLOW
171-
172-
cmake -D${BUILD_BACKEND}=ON \
173-
-DCMAKE_BUILD_TYPE=Release \
174-
-Sexamples/models/$RUNNER_PATH \
175-
-Bcmake-out/examples/models/$RUNNER_PATH/
176-
cmake --build cmake-out/examples/models/$RUNNER_PATH --target $RUNNER_TARGET --config Release
164+
MAKE_TARGET="${RUNNER_PATH}-${DEVICE}"
165+
make "${MAKE_TARGET}"
177166
echo "::endgroup::"
178167

179168
echo "::group::Run $MODEL_NAME Runner"

Makefile

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
# ==============================================================================
2+
# ExecuTorch Targets Makefile
3+
# ==============================================================================
4+
#
5+
# This Makefile provides convenient targets for building ExecuTorch model runners
6+
# with different backend configurations (CPU, CUDA, Metal), as well as other
7+
# binary targets.
8+
#
9+
# WHAT THIS BUILDS:
10+
# -----------------
11+
# Each target builds:
12+
# 1. ExecuTorch core libraries with the specified backend (CPU, CUDA, or Metal)
13+
# 2. The model-specific runner executable in cmake-out/examples/models/<model>/
14+
#
15+
# SUPPORTED MODELS:
16+
# -----------------
17+
# - voxtral: Multimodal voice + text model (CPU, CUDA, Metal)
18+
# - whisper: Speech recognition model (CPU, CUDA, Metal)
19+
# - llama: Text generation model (CPU)
20+
# - llava: Vision + language model (CPU)
21+
# - gemma3: Text generation model (CPU, CUDA)
22+
#
23+
# USAGE:
24+
# ------
25+
# make <model>-<backend> # Build a specific model with a backend
26+
# make help # Show all available targets
27+
# make clean # Remove all build artifacts
28+
#
29+
# Examples:
30+
# make voxtral-cuda # Build Voxtral with CUDA backend
31+
# make llama-cpu # Build Llama with CPU backend
32+
# make whisper-metal # Build Whisper with Metal backend (macOS)
33+
#
34+
# HOW TO ADD A NEW MODEL:
35+
# -----------------------
36+
# To add a new model (e.g., "mymodel"), follow these steps:
37+
#
38+
# 1. Create a CMakePresets.json in examples/models/mymodel/:
39+
# - Define configurePresets for each backend (base, cpu, cuda, metal)
40+
# - Define buildPresets with the target name from CMakeLists.txt
41+
# - Define workflowPresets that combine configure + build steps
42+
# - See examples/models/voxtral/CMakePresets.json for multi-backend reference
43+
# - Or see examples/models/llama/CMakePresets.json for simple single-preset reference
44+
#
45+
# 2. Add targets to this Makefile:
46+
# a) Add to .PHONY declaration: mymodel-cuda mymodel-cpu mymodel-metal
47+
# b) Add help text in the help target
48+
# c) Add target implementations following this pattern:
49+
#
50+
# mymodel-cuda:
51+
# @echo "==> Building and installing ExecuTorch with CUDA..."
52+
# cmake --workflow --preset llm-release-cuda
53+
# @echo "==> Building MyModel runner with CUDA..."
54+
# cd examples/models/mymodel && cmake --workflow --preset mymodel-cuda
55+
# @echo ""
56+
# @echo "✓ Build complete!"
57+
# @echo " Binary: cmake-out/examples/models/mymodel/mymodel_runner"
58+
#
59+
# mymodel-cpu:
60+
# @echo "==> Building and installing ExecuTorch..."
61+
# cmake --workflow --preset llm-release
62+
# @echo "==> Building MyModel runner (CPU)..."
63+
# cd examples/models/mymodel && cmake --workflow --preset mymodel-cpu
64+
# @echo ""
65+
# @echo "✓ Build complete!"
66+
# @echo " Binary: cmake-out/examples/models/mymodel/mymodel_runner"
67+
#
68+
# mymodel-metal:
69+
# @echo "==> Building and installing ExecuTorch with Metal..."
70+
# cmake --workflow --preset llm-release-metal
71+
# @echo "==> Building MyModel runner with Metal..."
72+
# cd examples/models/mymodel && cmake --workflow --preset mymodel-metal
73+
# @echo ""
74+
# @echo "✓ Build complete!"
75+
# @echo " Binary: cmake-out/examples/models/mymodel/mymodel_runner"
76+
#
77+
# 3. Test your new targets:
78+
# make mymodel-cpu # or mymodel-cuda, mymodel-metal
79+
#
80+
# NOTES:
81+
# ------
82+
# - CUDA backend is only available on Linux systems
83+
# - Metal backend is only available on macOS (Darwin) systems
84+
# - Some models may not support all backends (check model documentation)
85+
# - Binary outputs are located in cmake-out/examples/models/<model>/
86+
# - The preset names in CMakePresets.json must match the names used in Makefile
87+
#
88+
# ==============================================================================
89+
90+
.PHONY: voxtral-cuda voxtral-cpu voxtral-metal whisper-cuda whisper-cpu whisper-metal llama-cpu llava-cpu gemma3-cuda gemma3-cpu clean help
91+
92+
help:
93+
@echo "This Makefile adds targets to build runners for various models on various backends. Run using `make <target>`. Available targets:"
94+
@echo " voxtral-cuda - Build Voxtral runner with CUDA backend"
95+
@echo " voxtral-cpu - Build Voxtral runner with CPU backend"
96+
@echo " voxtral-metal - Build Voxtral runner with Metal backend (macOS only)"
97+
@echo " whisper-cuda - Build Whisper runner with CUDA backend"
98+
@echo " whisper-cpu - Build Whisper runner with CPU backend"
99+
@echo " whisper-metal - Build Whisper runner with Metal backend (macOS only)"
100+
@echo " llama-cpu - Build Llama runner with CPU backend"
101+
@echo " llava-cpu - Build Llava runner with CPU backend"
102+
@echo " gemma3-cuda - Build Gemma3 runner with CUDA backend"
103+
@echo " gemma3-cpu - Build Gemma3 runner with CPU backend"
104+
@echo " clean - Clean build artifacts"
105+
106+
voxtral-cuda:
107+
@echo "==> Building and installing ExecuTorch with CUDA..."
108+
cmake --workflow --preset llm-release-cuda
109+
@echo "==> Building Voxtral runner with CUDA..."
110+
cd examples/models/voxtral && cmake --workflow --preset voxtral-cuda
111+
@echo ""
112+
@echo "✓ Build complete!"
113+
@echo " Binary: cmake-out/examples/models/voxtral/voxtral_runner"
114+
115+
voxtral-cpu:
116+
@echo "==> Building and installing ExecuTorch..."
117+
cmake --workflow --preset llm-release
118+
@echo "==> Building Voxtral runner (CPU)..."
119+
cd examples/models/voxtral && cmake --workflow --preset voxtral-cpu
120+
@echo ""
121+
@echo "✓ Build complete!"
122+
@echo " Binary: cmake-out/examples/models/voxtral/voxtral_runner"
123+
124+
voxtral-metal:
125+
@echo "==> Building and installing ExecuTorch with Metal..."
126+
cmake --workflow --preset llm-release-metal
127+
@echo "==> Building Voxtral runner with Metal..."
128+
cd examples/models/voxtral && cmake --workflow --preset voxtral-metal
129+
@echo ""
130+
@echo "✓ Build complete!"
131+
@echo " Binary: cmake-out/examples/models/voxtral/voxtral_runner"
132+
133+
whisper-cuda:
134+
@echo "==> Building and installing ExecuTorch with CUDA..."
135+
cmake --workflow --preset llm-release-cuda
136+
@echo "==> Building Whisper runner with CUDA..."
137+
cd examples/models/whisper && cmake --workflow --preset whisper-cuda
138+
@echo ""
139+
@echo "✓ Build complete!"
140+
@echo " Binary: cmake-out/examples/models/whisper/whisper_runner"
141+
142+
whisper-cpu:
143+
@echo "==> Building and installing ExecuTorch..."
144+
cmake --workflow --preset llm-release
145+
@echo "==> Building Whisper runner (CPU)..."
146+
cd examples/models/whisper && cmake --workflow --preset whisper-cpu
147+
@echo ""
148+
@echo "✓ Build complete!"
149+
@echo " Binary: cmake-out/examples/models/whisper/whisper_runner"
150+
151+
whisper-metal:
152+
@echo "==> Building and installing ExecuTorch with Metal..."
153+
cmake --workflow --preset llm-release-metal
154+
@echo "==> Building Whisper runner with Metal..."
155+
cd examples/models/whisper && cmake --workflow --preset whisper-metal
156+
@echo ""
157+
@echo "✓ Build complete!"
158+
@echo " Binary: cmake-out/examples/models/whisper/whisper_runner"
159+
160+
llama-cpu:
161+
@echo "==> Building and installing ExecuTorch..."
162+
cmake --workflow --preset llm-release
163+
@echo "==> Building Llama runner (CPU)..."
164+
cd examples/models/llama && cmake --workflow --preset llama-release
165+
@echo ""
166+
@echo "✓ Build complete!"
167+
@echo " Binary: cmake-out/examples/models/llama/llama_main"
168+
169+
llava-cpu:
170+
@echo "==> Building and installing ExecuTorch..."
171+
cmake --workflow --preset llm-release
172+
@echo "==> Building Llava runner (CPU)..."
173+
cd examples/models/llava && cmake --workflow --preset llava
174+
@echo ""
175+
@echo "✓ Build complete!"
176+
@echo " Binary: cmake-out/examples/models/llava/llava_main"
177+
178+
gemma3-cuda:
179+
@echo "==> Building and installing ExecuTorch with CUDA..."
180+
cmake --workflow --preset llm-release-cuda
181+
@echo "==> Building Gemma3 runner with CUDA..."
182+
cd examples/models/gemma3 && cmake --workflow --preset gemma3-cuda
183+
@echo ""
184+
@echo "✓ Build complete!"
185+
@echo " Binary: cmake-out/examples/models/gemma3/gemma3_e2e_runner"
186+
187+
gemma3-cpu:
188+
@echo "==> Building and installing ExecuTorch..."
189+
cmake --workflow --preset llm-release
190+
@echo "==> Building Gemma3 runner (CPU)..."
191+
cd examples/models/gemma3 && cmake --workflow --preset gemma3-cpu
192+
@echo ""
193+
@echo "✓ Build complete!"
194+
@echo " Binary: cmake-out/examples/models/gemma3/gemma3_e2e_runner"
195+
196+
clean:
197+
rm -rf cmake-out
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
{
2+
"version": 6,
3+
"configurePresets": [
4+
{
5+
"name": "gemma3-base",
6+
"hidden": true,
7+
"binaryDir": "${sourceDir}/../../../cmake-out/examples/models/gemma3",
8+
"cacheVariables": {
9+
"CMAKE_BUILD_TYPE": "Release",
10+
"CMAKE_FIND_ROOT_PATH": "${sourceDir}/../../../cmake-out"
11+
}
12+
},
13+
{
14+
"name": "gemma3-cpu",
15+
"displayName": "Gemma3 runner (CPU)",
16+
"inherits": ["gemma3-base"]
17+
},
18+
{
19+
"name": "gemma3-cuda",
20+
"displayName": "Gemma3 runner (CUDA)",
21+
"inherits": ["gemma3-base"],
22+
"cacheVariables": {
23+
"EXECUTORCH_BUILD_CUDA": "ON"
24+
},
25+
"condition": {
26+
"lhs": "${hostSystemName}",
27+
"type": "equals",
28+
"rhs": "Linux"
29+
}
30+
}
31+
],
32+
"buildPresets": [
33+
{
34+
"name": "gemma3-cpu",
35+
"displayName": "Build Gemma3 runner (CPU)",
36+
"configurePreset": "gemma3-cpu",
37+
"targets": ["gemma3_e2e_runner"]
38+
},
39+
{
40+
"name": "gemma3-cuda",
41+
"displayName": "Build Gemma3 runner (CUDA)",
42+
"configurePreset": "gemma3-cuda",
43+
"targets": ["gemma3_e2e_runner"]
44+
}
45+
],
46+
"workflowPresets": [
47+
{
48+
"name": "gemma3-cpu",
49+
"displayName": "Configure and build Gemma3 runner (CPU)",
50+
"steps": [
51+
{
52+
"type": "configure",
53+
"name": "gemma3-cpu"
54+
},
55+
{
56+
"type": "build",
57+
"name": "gemma3-cpu"
58+
}
59+
]
60+
},
61+
{
62+
"name": "gemma3-cuda",
63+
"displayName": "Configure and build Gemma3 runner (CUDA)",
64+
"steps": [
65+
{
66+
"type": "configure",
67+
"name": "gemma3-cuda"
68+
},
69+
{
70+
"type": "build",
71+
"name": "gemma3-cuda"
72+
}
73+
]
74+
}
75+
]
76+
}

examples/models/gemma3/README.md

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,11 @@ Ensure you have a CUDA-capable GPU and CUDA toolkit installed on your system.
7878

7979
### Building for CUDA
8080
```bash
81-
# Install ExecuTorch.
82-
./install_executorch.sh
83-
84-
# Build the multimodal runner with CUDA
85-
cmake --workflow llm-release-cuda
86-
87-
# Build the Gemma3 runner
88-
cmake -DEXECUTORCH_BUILD_CUDA=ON \
89-
-DCMAKE_BUILD_TYPE=Release \
90-
-Sexamples/models/gemma3 \
91-
-Bcmake-out/examples/models/gemma3/
92-
cmake --build cmake-out/examples/models/gemma3 --target gemma3_e2e_runner --config Release
81+
# Build the Gemma3 runner with CUDA enabled
82+
make gemma3-cuda
83+
84+
# Build the Gemma3 runner with CPU enabled
85+
make gemma3-cpu
9386
```
9487

9588
## Running the model

0 commit comments

Comments
 (0)