본문 바로가기

GPU-KERNEL

커널 개발 - 프로파일링 - 매트릭 추출 과정 파이프라인 구성

단일 명령으로 커널 실행 -  Nsight Compute - metrics CSV/JSON 의 생성

전체 실행 파이프라인

커널 코드
   │
   ▼
cmake build
   │
   ▼
bench.bat
   │
   ▼
ncu_kernel_extract.bat
   │
   ▼
ncu (Nsight Compute)
   │
   ▼
.ncu-rep 생성
   │
   ▼
rep → csv export
   │
   ▼
ncu_extract.ps1
   │
   ▼
json 생성

 

 생성되는 파일 구조

aicf-kernels
 ┣ out
 ┃ ┣ ncu
 ┃ ┃ └ add_f16x2_kernel_<timestamp>.ncu-rep
 ┃ ┃
 ┃ ┗ metrics
 ┃    ┣ add_f16x2_kernel_<timestamp>.csv
 ┃    ┗ add_f16x2_kernel_<timestamp>.json

 

각 스크립트 역할

1. bench.bat

GPU timer 기반 순수 커널 성능 측정

실행

scripts\bench.bat add_sandbox.exe --dtype f16 --n 16777216 --iters 200

출력

avg_kernel_ms: 0.24

실제 runtime 성능

 

2. ncu_kernel_extract.bat

역할

Nsight Compute 실행
→ 특정 kernel 필터링
→ .ncu-rep 생성
→ CSV export
→ JSON 생성

실행

scripts\ncu_kernel_extract.bat add_f16x2_kernel build\bin\add_sandbox.exe --dtype f16 --n 16777216 --iters 10

내부 실행 흐름

1. ncu profiling
2. .ncu-rep 생성
3. ncu -i export
4. CSV 생성
5. ncu_extract.ps1
6. JSON 생성

 

3. ncu_extract.ps1

역할

CSV → JSON 변환

예 CSV

gpu__time_duration.sum = 368.992 us

JSON

{
  "kernel": "add_f16x2_kernel",
  "metrics": {
    "gpu__time_duration.sum": {
      "avg": 368.992,
      "unit": "us"
    }
  }
}

 

실제 커널 개발 루프

1. 빌드

cmake --build build -j

 

2. 성능 확인

scripts\bench.bat add_sandbox.exe --dtype f16 --n 16777216

 

3. Nsight Compute 분석

scripts\ncu_kernel_extract.bat add_f16x2_kernel build\bin\add_sandbox.exe --dtype f16 --n 16777216

 

4. 결과 확인

out/metrics/*.csv
out/metrics/*.json

 

이 구조의 장점

이 구조는 CUDA 커널 연구 루프와 정확히 맞는다.

커널 수정
   ↓
build
   ↓
bench
   ↓
ncu profiling
   ↓
metrics export
   ↓
analysis