Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/result-server-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ on:
- "scripts/result.sh"
- "scripts/result_server/**"
- "scripts/estimation/**"
- "scripts/profiling/**"
- "scripts/tests/test_bk_profiler.sh"
- "scripts/tests/test_ncu_plan_generation.sh"
- "scripts/tests/test_estimation_gpu_kernel_ensemble_average.sh"
- "scripts/tests/test_estimation_gpu_kernel_lightgbm_v10.sh"
- "scripts/tests/test_estimation_gpu_kernel_mlp_v15.sh"
Expand Down Expand Up @@ -38,7 +40,9 @@ on:
- "scripts/result.sh"
- "scripts/result_server/**"
- "scripts/estimation/**"
- "scripts/profiling/**"
- "scripts/tests/test_bk_profiler.sh"
- "scripts/tests/test_ncu_plan_generation.sh"
- "scripts/tests/test_estimation_gpu_kernel_ensemble_average.sh"
- "scripts/tests/test_estimation_gpu_kernel_lightgbm_v10.sh"
- "scripts/tests/test_estimation_gpu_kernel_mlp_v15.sh"
Expand Down Expand Up @@ -121,6 +125,7 @@ jobs:
- name: Run profiler, profile-data, and estimation shell tests
run: |
bash scripts/tests/test_bk_profiler.sh
bash scripts/tests/test_ncu_plan_generation.sh
bash scripts/tests/test_result_profile_data.sh
bash scripts/tests/test_send_results_profile_data.sh
bash scripts/tests/test_send_estimate_artifacts.sh
Expand Down
3 changes: 3 additions & 0 deletions docs/guides/add-estimation-package.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ section package は prediction CSV の推定実行時間を合算し、その se
MLP package は `Execution Time [ns]`、LightGBM package は `O-Execution Time` を主な入力列として扱います。
prepared input CSV から source-side の kernel 実測時間を読める場合は、Estimate JSON の metrics に `source_time_ns`, `predicted_time_ns`, `time_ratio_predicted_over_source`, `speedup_factor_source_over_predicted` を出します。
`ncu` の採取 window はアプリ全体の GPU 区間時間ではなく限定された kernel sample なので、実運用ではこの source/target 比を、profiler overhead のないアプリ区間 timing に掛けて FOM を再構築する想定です。
GPU kernel を手で事前調査して `kernel_regex` や launch window を固定することは最終形ではありません。
BenchKit 共通層では `nsys stats` の CUDA kernel summary から `kernel_discovery.json` と `ncu_plan.json` を生成する helper を用意し、推定 package が必要とする NCU 深掘り対象を自動選定する方向に寄せます。
最初の段階ではアプリ全体の上位 kernel を対象にし、NVTX や app section timing が使える場合は section-aware discovery に拡張します。

CI 配管や app 固有の smoke test は、`programs/<code>/estimate.sh` や `scripts/tests/` 側で扱います。
推定 package は、どの app の smoke test で呼ばれるかを知らず、自分が要求する input CSV / prediction CSV / profiler archive だけを見て applicability を判定します。
Expand Down
7 changes: 7 additions & 0 deletions docs/guides/profiler-level-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ Here `both` means text summaries plus CSV reports.
Default report behavior for `ncu` is `text`.
BenchKit stores the Nsight Compute raw report under `bk_profiler_artifact/raw/rep1/` and, when import succeeds, a text details page under `bk_profiler_artifact/reports/ncu_import_rep1.txt`.

For GPU estimation bring-up, BenchKit also has an offline NCU plan generator:
`scripts/profiling/generate_ncu_plan.py`.
It reads an Nsight Systems CUDA kernel summary CSV and writes `kernel_discovery.json`
plus `ncu_plan.json`. This is intentionally separate from the `single/simple`
level presets: discovery decides which kernels deserve expensive NCU sampling,
while `bk_profiler ncu` still owns the concrete Nsight Compute collection.

## Portal Summary

BenchKit stores profiler metadata in `bk_profiler_artifact/meta.json` inside `padata.tgz`, and also copies a compact summary into `result.json` as `profile_data`.
Expand Down
58 changes: 58 additions & 0 deletions docs/guides/profiler-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,64 @@ binary report も保存したいデバッグ用途では、`BK_PROFILER_ARCHIVE_
MPI launcher 経由の GPU application では、既定で `--target-processes all` を付けて child process も採取対象にする。
追加の kernel filter、section set、NVTX filter などは `BK_PROFILER_ARGS` で `ncu` に渡す。

### 5.1 GPU kernel discovery と NCU plan

GPU 性能推定では、アプリ側が kernel 名、launch skip/count、NCU metric list を事前調査して手書きする運用を最終形にしない。
BenchKit 共通層は、次の段階的 flow を目標にする。

1. profiler overhead のない通常実行で FOM と app section timing を取る。
2. 軽量な discovery 実行で `nsys stats --report cuda_gpu_kern_sum --format csv` 相当の kernel summary を得る。
3. summary から GPU 時間の上位 kernel を選び、`ncu_plan.json` を生成する。
4. `ncu_plan.json` に従って、選ばれた代表 kernel launch だけを Nsight Compute で深掘りする。
5. 推定 package は raw NCU CSV / prepared CSV を入力にし、section time への掛け算に使う source/target ratio を返す。

このためのオフライン変換 helper として、`scripts/profiling/generate_ncu_plan.py` を提供する。
この helper は `nsys` や `ncu` を実行せず、CSV fixture だけでテストできる。

```bash
python3 scripts/profiling/generate_ncu_plan.py \
--nsys-csv results/nsys_cuda_gpu_kern_sum.csv \
--out-discovery results/kernel_discovery.json \
--out-plan results/ncu_plan.json \
--top-k 0 \
--launch-count 10
```

`kernel_discovery.json` は kernel 名、呼び出し回数、合計 GPU 時間、平均時間を正規化した summary である。
`ncu_plan.json` は共通 profiler 層や app wrapper が NCU 採取に使える候補 plan で、各 profile に次を含む。
`--top-k 0` は discovery 調査用に全 kernel を plan へ残す指定である。
NCU 実行時は、NSYS で同定した kernel に対して `launch_skip=1` / `launch_count=10`
程度の小さな window から始める。`discovery_gpu_time_pct` は NSYS で観測された
GPU kernel 時間内の割合であり、app FOM 全体に対する割合ではない。

- `kernel_name`
- `kernel_match.name_base`
- `kernel_match.pattern`
- `launch_skip`
- `launch_count`
- `metric_set`
- `selection.source_gpu_duration_ns`
- `selection.discovery_gpu_time_pct`
- `archive_ncu_report`
- `selection` metadata

現時点の helper は app section との対応を自動確定しない。
NVTX range や app-side section timing と接続できる場合は、将来 `section` を埋める拡張で section-aware discovery に進める。
NVTX がない場合でも、アプリ全体の上位 GPU kernel を自動抽出することで、手書きの kernel regex / skip / count を減らせる。

GPU 実機で走らせる前には、plan を `bk_profiler ncu` の dry-run command manifest に変換して確認できる。

```bash
python3 scripts/profiling/render_ncu_plan_commands.py \
--plan results/ncu_plan.json \
--out results/ncu_commands.json \
--level detailed \
-- ./app --input case.inp
```

この manifest は profile ごとの `BK_PROFILER_ARGS`、archive path、raw-dir、`bk_profiler ncu` argv を持つ。
現段階では実行は app wrapper や site runner 側が行い、共通 helper は「自動生成された NCU 採取内容を inspect 可能にする」ことを担当する。

## 6. Archive の考え方

`bk_profiler` は archive の中に少なくとも次を置く。
Expand Down
22 changes: 22 additions & 0 deletions programs/genesis/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,28 @@ BK_GENESIS_NCU_<PROFILE>_NSTEPS
Legacy single-window collection can be requested with `BK_GENESIS_NCU_KERNEL_REGEX`;
the wrapper treats it as a `custom` profile.

The default automatic mode derives candidate NCU windows from an Nsight Systems
CUDA kernel summary and then executes the generated NCU plan:

```bash
BK_GENESIS_NCU_PROFILE_MODE=discovery
```

In this mode, `run.sh` keeps the normal unprofiled benchmark run, then runs a
short NSYS discovery pass, writes `results/kernel_discovery.json` and
`results/ncu_plan.json`, and runs the selected NCU windows. The generated NCU
profiles default to the top three GPU-time kernels with `launch_skip=1` and
`launch_count=10`; the NCU archives are registered as section artifacts and are
used by the GPU estimation packages to compute source/target kernel time ratios.

Use `BK_GENESIS_NCU_PROFILE_MODE=discovery-only` when investigating NSYS output
without paying the NCU cost. That mode writes the full discovery summary and
plan but skips NCU collection. If the NSYS CSV has already been created by
site-local tooling, set
`BK_GENESIS_NCU_DISCOVERY_CSV=/path/to/cuda_gpu_kern_sum.csv` to skip the NSYS
pass and only generate the NCU plan. Manual mode still uses the configured
`inter intra pairlist` windows above.

## Estimation Sections

GENESIS treats the log `dynamics` time as the FOM. The app-side parser
Expand Down
Loading
Loading