Skip to content

Commit ccba80f

Browse files
authored
Feature/ncu metric extraction (#17)
* fix: correct pytest -k examples in documentation * feature: added ncu mtric extraction script, and updated DEVELOPMENT to reflect new changes * style: fix ruff formatting in ncu_extract.py
1 parent dd34b23 commit ccba80f

5 files changed

Lines changed: 395 additions & 7 deletions

File tree

.github/workflows/ruff-format.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,23 @@ on:
55
push:
66
pull_request:
77

8+
permissions:
9+
contents: read
10+
11+
concurrency:
12+
group: ruff-${{ github.ref }}
13+
cancel-in-progress: true
14+
815
jobs:
916
format:
1017
runs-on: ubuntu-latest
18+
timeout-minutes: 10
1119
steps:
1220
- name: Checkout code
13-
uses: actions/checkout@v6
21+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
1422

1523
- name: Ruff check
16-
uses: astral-sh/ruff-action@v3
24+
uses: astral-sh/ruff-action@57714a7c8a2e59f32539362ba31877a1957dded1
1725
- name: Ruff format
1826
run: ruff format --check --diff
1927

20-

DEVELOPMENT.md

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,18 @@ Key constraints to keep in mind:
104104
## Testing and correctness
105105

106106
```bash
107+
# Run all tests
107108
uv run pytest -q
108-
uv run pytest tests/test_copy_transpose.py::test_copy_transpose_correctness -k "float16"
109+
110+
# Run specific test file
111+
uv run pytest tests/test_copy_transpose.py
112+
113+
# Run specific test function
114+
uv run pytest tests/test_copy_transpose.py::test_copy_transpose_correctness
115+
116+
# Filter tests by name pattern with -k (matches test function names)
117+
uv run pytest tests/test_softmax_online.py -k correctness
118+
uv run pytest -k "not correctness and not compile"
109119
```
110120

111121
Correctness is the primary gate. Use explicit tolerances and document any
@@ -131,6 +141,48 @@ Add new benchmark cases to `bench/suites.yaml` and keep outputs reproducible.
131141
Nsight Compute with `--set full` can be slow; use lighter sets if needed
132142
(`--set=launchstats`, `--section=SpeedOfLight`, etc.).
133143

144+
### Metric extraction
145+
146+
Extract curated metrics from NCU reports using the `--extract` flag or standalone:
147+
148+
```bash
149+
# Automatic extraction after profiling
150+
./scripts/profile.sh ncu --extract -- uv run python bench/benchmark_copy_transpose.py
151+
152+
# Standalone extraction from existing report
153+
./scripts/ncu_extract.py profiles/ncu_*.ncu-rep
154+
155+
# JSON output
156+
./scripts/ncu_extract.py profiles/ncu_*.ncu-rep --json
157+
158+
# Filter by kernel name
159+
./scripts/ncu_extract.py profiles/ncu_*.ncu-rep --kernel "CopyTranspose"
160+
```
161+
162+
Output includes three metric categories:
163+
- **GPU Throughput**: Memory and Compute (SM) utilization percentages
164+
- **Pipe Utilization**: Tensor Core, FMA, ALU activity
165+
- **Warp Stalls**: Long scoreboard, barrier, memory throttle stalls
166+
167+
### Profiling tips
168+
169+
**For NCU profiling**, use minimal iterations since you're analyzing kernel behavior, not
170+
timing variance. The L2 cache flush adds extra kernel launches per iteration.
171+
172+
```bash
173+
# Fast profiling (recommended)
174+
./scripts/profile.sh ncu --extract -- uv run python bench/benchmark_copy_transpose.py --warmup 2 --iterations 1
175+
176+
# Profile only your kernel (skip reference kernels)
177+
./scripts/profile.sh ncu --kernel-name "copy_transpose" --extract -- uv run python bench/benchmark_copy_transpose.py
178+
```
179+
180+
| Goal | Warmup | Iterations | Notes |
181+
|------|--------|------------|-------|
182+
| Timing benchmarks | 10 | 100 | Default, good for stable p50/p90 |
183+
| Quick profiling | 2 | 1-3 | Sufficient for kernel analysis |
184+
| Deep profiling (`--set full`) | 1 | 1 | Full metrics are slow |
185+
134186
## Linting and formatting
135187

136188
```bash

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ Profile a kernel with helper script:
9090

9191
```bash
9292
./scripts/profile.sh ncu -- uv run python bench/benchmark_copy_transpose.py
93-
./scripts/profile.sh nsys -- uv run pytest tests/test_copy_transpose.py -k "tile_size=16"
93+
./scripts/profile.sh nsys -- uv run pytest tests/test_copy_transpose.py
9494
```
9595

9696
Or use profiling tools directly:
@@ -140,7 +140,7 @@ uv run python -m forge_cute_py.env_check # Verify CUDA/PyTorch setup
140140
```bash
141141
uv run pytest -q # Run all tests
142142
uv run pytest tests/test_copy_transpose.py # Run specific test file
143-
uv run pytest -k "float16 and tile_size=16" # Run filtered tests
143+
uv run pytest -k correctness # Filter by test name pattern
144144
uv run pre-commit run --all-files # Run linting/formatting
145145
```
146146

0 commit comments

Comments
 (0)