Skip to content

Commit 0148810

Browse files
committed
add the skill for running a docker container with correct options; build and run tests in the container
1 parent 00c4678 commit 0148810

2 files changed

Lines changed: 385 additions & 0 deletions

File tree

.claude/skills/ck-docker

Lines changed: 309 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,309 @@
1+
#!/bin/bash
2+
# CK Docker Skill - Build and test composable_kernel in Docker with ROCm support
3+
4+
set -e
5+
6+
# Find project root (where .git directory is)
7+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
8+
PROJECT_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)"
9+
10+
# Detect git branch and sanitize for docker naming (replace / and special chars with _)
11+
GIT_BRANCH=$(cd "${PROJECT_ROOT}" && git rev-parse --abbrev-ref HEAD 2>/dev/null | tr '/' '_' | tr -cd 'a-zA-Z0-9_-')
12+
13+
# Default container name: ck_<username>_<branch>
14+
DEFAULT_NAME="ck_${USER}_${GIT_BRANCH}"
15+
CONTAINER_NAME="${CK_CONTAINER_NAME:-${DEFAULT_NAME}}"
16+
17+
# Help message
18+
show_help() {
19+
cat << EOF
20+
CK Docker Skill - Build and test composable_kernel in Docker
21+
22+
Usage: ck-docker <command> [options]
23+
24+
Commands:
25+
start [name] Start Docker container
26+
build [target] [--name] Build target
27+
test <test> [options] Run test
28+
shell [name] Open shell in container
29+
status [name] Check container status
30+
stop [name] Stop and remove container
31+
rebuild-cmake [name] Reconfigure CMake from scratch
32+
33+
Examples:
34+
ck-docker start
35+
ck-docker build test_amdgcn_mma
36+
ck-docker test test_amdgcn_mma --gtest_filter=*Fp16*
37+
ck-docker shell
38+
39+
Environment:
40+
CK_CONTAINER_NAME - Override default container name (default: ck_<username>_<branch>)
41+
EOF
42+
}
43+
44+
# Detect GPU target
45+
detect_gpu() {
46+
local container=$1
47+
docker exec ${container} bash -c "
48+
rocminfo 2>/dev/null | grep -oP 'gfx[0-9a-z]+' | head -1 || echo 'gfx950'
49+
" | tr -d '\r\n'
50+
}
51+
52+
# Start container
53+
cmd_start() {
54+
local name="${1:-${CONTAINER_NAME}}"
55+
56+
if docker ps -a -f name=${name} | grep -q ${name}; then
57+
if docker ps -f name=${name} | grep -q ${name}; then
58+
echo "Container '${name}' is already running"
59+
return 0
60+
else
61+
echo "Starting existing container '${name}'..."
62+
docker start ${name}
63+
echo "Container started"
64+
return 0
65+
fi
66+
fi
67+
68+
echo "Creating new Docker container '${name}'..."
69+
docker run -d \
70+
--name ${name} \
71+
--device=/dev/kfd --device=/dev/dri \
72+
--security-opt seccomp=unconfined \
73+
--group-add video \
74+
-v "${PROJECT_ROOT}":/workspace \
75+
-w /workspace \
76+
rocm/composable_kernel:ck_ub24.04_rocm7.0.1 \
77+
tail -f /dev/null
78+
79+
echo "Container '${name}' started successfully"
80+
docker exec ${name} bash -c "echo 'Working directory:' && pwd"
81+
}
82+
83+
# Build target
84+
cmd_build() {
85+
local target=""
86+
local name="${CONTAINER_NAME}"
87+
88+
while [[ $# -gt 0 ]]; do
89+
case $1 in
90+
--name)
91+
name="$2"
92+
shift 2
93+
;;
94+
*)
95+
target="$1"
96+
shift
97+
;;
98+
esac
99+
done
100+
101+
if ! docker ps -f name=${name} | grep -q ${name}; then
102+
echo "Container '${name}' not running. Starting..."
103+
cmd_start ${name}
104+
fi
105+
106+
if ! docker exec ${name} test -f /workspace/build/build.ninja 2>/dev/null; then
107+
echo "Detecting GPU target..."
108+
local gpu_target=$(detect_gpu ${name})
109+
110+
echo "Configuring build with CMake for GPU target: ${gpu_target}"
111+
docker exec ${name} bash -c "
112+
cd /workspace &&
113+
rm -rf build &&
114+
mkdir build &&
115+
cd build &&
116+
cmake .. -GNinja \
117+
-DGPU_TARGETS=${gpu_target} \
118+
-DCMAKE_BUILD_TYPE=Release \
119+
-DCMAKE_CXX_COMPILER=/opt/rocm/llvm/bin/clang++ \
120+
-DBUILD_TESTING=ON 2>&1 | tail -30
121+
"
122+
fi
123+
124+
if [ -z "$target" ]; then
125+
echo "Building all configured targets..."
126+
else
127+
echo "Building target: ${target}"
128+
fi
129+
130+
docker exec ${name} bash -c "
131+
cd /workspace/build &&
132+
ninja ${target} 2>&1
133+
"
134+
135+
echo "Build complete"
136+
}
137+
138+
# Run test
139+
cmd_test() {
140+
local test_name=""
141+
local name="${CONTAINER_NAME}"
142+
local test_options=""
143+
144+
while [[ $# -gt 0 ]]; do
145+
case $1 in
146+
--name)
147+
name="$2"
148+
shift 2
149+
;;
150+
--gtest_*|--help)
151+
test_options="${test_options} $1"
152+
shift
153+
;;
154+
*)
155+
if [ -z "$test_name" ]; then
156+
test_name="$1"
157+
else
158+
test_options="${test_options} $1"
159+
fi
160+
shift
161+
;;
162+
esac
163+
done
164+
165+
if [ -z "$test_name" ]; then
166+
echo "Error: test_name required"
167+
echo "Usage: ck-docker test <test_name> [--name container_name] [gtest_options]"
168+
return 1
169+
fi
170+
171+
if ! docker ps -f name=${name} | grep -q ${name}; then
172+
echo "Error: Container '${name}' not running"
173+
echo "Start it with: ck-docker start --name ${name}"
174+
return 1
175+
fi
176+
177+
if ! docker exec ${name} test -f "/workspace/build/bin/${test_name}" 2>/dev/null; then
178+
echo "Test executable not found. Building ${test_name}..."
179+
cmd_build ${test_name} --name ${name}
180+
fi
181+
182+
echo "Running: ${test_name} ${test_options}"
183+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
184+
docker exec ${name} bash -c "
185+
cd /workspace/build &&
186+
./bin/${test_name} ${test_options}
187+
"
188+
}
189+
190+
# Shell
191+
cmd_shell() {
192+
local name="${1:-${CONTAINER_NAME}}"
193+
194+
if ! docker ps -f name=${name} | grep -q ${name}; then
195+
echo "Container '${name}' not running. Starting..."
196+
cmd_start ${name}
197+
fi
198+
199+
echo "Opening shell in '${name}' (type 'exit' to leave)..."
200+
docker exec -it ${name} bash
201+
}
202+
203+
# Status
204+
cmd_status() {
205+
local name="${1:-}"
206+
207+
if [ -z "$name" ]; then
208+
echo "Composable Kernel Docker Containers:"
209+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
210+
docker ps -a --filter "ancestor=rocm/composable_kernel:ck_ub24.04_rocm7.0.1" \
211+
--format "table {{.Names}}\t{{.Status}}\t{{.CreatedAt}}" || echo "No containers found"
212+
else
213+
if docker ps -f name=${name} | grep -q ${name}; then
214+
echo "Container '${name}' is RUNNING"
215+
docker ps -f name=${name} --format "table {{.Names}}\t{{.Status}}\t{{.Image}}"
216+
echo ""
217+
echo "GPU Information:"
218+
docker exec ${name} bash -c "rocm-smi --showproductname 2>/dev/null | head -10 || echo 'No GPU detected'"
219+
elif docker ps -a -f name=${name} | grep -q ${name}; then
220+
echo "Container '${name}' exists but is STOPPED"
221+
echo "Start with: ck-docker start ${name}"
222+
else
223+
echo "Container '${name}' does NOT exist"
224+
echo "Create with: ck-docker start ${name}"
225+
fi
226+
fi
227+
}
228+
229+
# Stop
230+
cmd_stop() {
231+
local name="${1:-${CONTAINER_NAME}}"
232+
233+
if docker ps -a -f name=${name} | grep -q ${name}; then
234+
echo "Stopping and removing container '${name}'..."
235+
docker stop ${name} 2>/dev/null || true
236+
docker rm ${name} 2>/dev/null || true
237+
echo "Container stopped and removed"
238+
else
239+
echo "Container '${name}' does not exist"
240+
fi
241+
}
242+
243+
# Rebuild CMake
244+
cmd_rebuild_cmake() {
245+
local name="${1:-${CONTAINER_NAME}}"
246+
247+
if ! docker ps -f name=${name} | grep -q ${name}; then
248+
echo "Container '${name}' not running. Starting..."
249+
cmd_start ${name}
250+
fi
251+
252+
echo "Detecting GPU target..."
253+
local gpu_target=$(detect_gpu ${name})
254+
255+
echo "Reconfiguring CMake from scratch in '${name}' for GPU target: ${gpu_target}"
256+
docker exec ${name} bash -c "
257+
cd /workspace &&
258+
rm -rf build &&
259+
mkdir build &&
260+
cd build &&
261+
cmake .. -GNinja \
262+
-DGPU_TARGETS=${gpu_target} \
263+
-DCMAKE_BUILD_TYPE=Release \
264+
-DCMAKE_CXX_COMPILER=/opt/rocm/llvm/bin/clang++ \
265+
-DBUILD_TESTING=ON 2>&1 | tail -30
266+
"
267+
echo "CMake configuration complete for ${gpu_target}"
268+
}
269+
270+
# Main command dispatcher
271+
case "${1:-}" in
272+
start)
273+
shift
274+
cmd_start "$@"
275+
;;
276+
build)
277+
shift
278+
cmd_build "$@"
279+
;;
280+
test)
281+
shift
282+
cmd_test "$@"
283+
;;
284+
shell)
285+
shift
286+
cmd_shell "$@"
287+
;;
288+
status)
289+
shift
290+
cmd_status "$@"
291+
;;
292+
stop)
293+
shift
294+
cmd_stop "$@"
295+
;;
296+
rebuild-cmake)
297+
shift
298+
cmd_rebuild_cmake "$@"
299+
;;
300+
help|--help|-h)
301+
show_help
302+
;;
303+
*)
304+
echo "Unknown command: ${1:-}"
305+
echo ""
306+
show_help
307+
exit 1
308+
;;
309+
esac

.claude/skills/ck-docker.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# ck-docker
2+
3+
Build and test composable_kernel in Docker with ROCm support.
4+
5+
## Terminal Usage
6+
7+
Direct command-line usage:
8+
9+
```bash
10+
# From composable_kernel directory
11+
.claude/skills/ck-docker start
12+
.claude/skills/ck-docker build test_amdgcn_mma
13+
.claude/skills/ck-docker test test_amdgcn_mma --gtest_filter=*Fp16*
14+
.claude/skills/ck-docker status
15+
.claude/skills/ck-docker shell
16+
17+
# Or add to PATH
18+
export PATH="$PATH:$PWD/.claude/skills"
19+
ck-docker start
20+
```
21+
22+
## Ask Claude
23+
24+
Just ask in natural language:
25+
- "Start the docker container"
26+
- "Build test_amdgcn_mma"
27+
- "Run test_amdgcn_mma with filter *Fp16*"
28+
- "Check container status"
29+
- "Open a shell in the container"
30+
31+
## Commands
32+
33+
```
34+
ck-docker start [name] Start Docker container
35+
ck-docker build [target] Build target
36+
ck-docker test <name> [options] Run test
37+
ck-docker shell [name] Interactive shell
38+
ck-docker status [name] Check status
39+
ck-docker stop [name] Stop container
40+
ck-docker rebuild-cmake [name] Reconfigure CMake
41+
```
42+
43+
## Configuration
44+
45+
- **Image**: rocm/composable_kernel:ck_ub24.04_rocm7.0.1
46+
- **GPU**: Auto-detected via rocminfo (fallback: gfx950)
47+
- **Compiler**: /opt/rocm/llvm/bin/clang++
48+
- **Build**: Ninja + CMake (Release)
49+
- **Mount**: Current directory → /workspace
50+
- **Container Name**: Auto-generated as `ck_<username>_<branch>` to avoid clashes
51+
52+
## Environment
53+
54+
```bash
55+
export CK_CONTAINER_NAME=my_build # Override default container name
56+
```
57+
58+
## Examples
59+
60+
```bash
61+
# Start container
62+
ck-docker start
63+
64+
# Build and run test
65+
ck-docker build test_amdgcn_mma
66+
ck-docker test test_amdgcn_mma
67+
68+
# Custom container
69+
ck-docker start my_build
70+
ck-docker build test_amdgcn_mma --name my_build
71+
ck-docker test test_amdgcn_mma --name my_build
72+
73+
# Debug
74+
ck-docker shell
75+
ck-docker status
76+
```

0 commit comments

Comments
 (0)