본문 바로가기

AI Compiler framework

Plan Compiler ( Execution Planner Compiler )

프로그램을 소스 코드로 다시 생성하는 대신, 실행 계획을 만들어 런타임이 그대로 실행하게 하는 컴파일러

AI 컴파일러나 GPU 컴퓨팅 시스템에서 흔한 구조

 

핵심

Program / Graph
      ↓
   IR 변환
      ↓
Execution Plan 생성
      ↓
Kernel Launch / Runtime Execution

컴파일 결과물이 코드가 아닌 실행 계획 데이터 구조

 

1. Plan Compiler 의 핵심 개념

Execution Plan

컴파일 결과물

ExecutionPlan
 ├─ kernel_id
 ├─ variant_id
 ├─ launch_config
 │   ├─ grid
 │   ├─ block
 │   └─ shared_memory
 ├─ memory_layout
 │   ├─ strides
 │   ├─ alignment
 │   └─ packing
 ├─ argument_binding
 │   ├─ tensor pointers
 │   └─ scalar params
 └─ dependency graph

runtime 은 단순

for node in execution_plan:
    launch(node.kernel)

 

Kernel Registry

plan compiler 는 보통 커널을 미리 가지고 있다.

kernel_registry
 ├─ GEMM
 │   ├─ variant_1 (128x128 tile)
 │   ├─ variant_2 (64x128 tile)
 │   └─ variant_3 (tensorcore)
 ├─ Conv
 ├─ Attention

컴파일러는 어떤 variant 가 좋은지만 결정한다.

 

Variant Selection

실제 핵심 로직

입력

tensor shape
dtype
stride
hardware capability

결정

tile size
vectorization
memory layout
kernel variant

즉

Op → best kernel

 

2. Codegen Compiler vs Plan Compiler

Output Execution plan Source / IR code
Kernel prebuilt generated
Compile cost 낮음 높음
runtime flexibility 높음 낮음
complexity 낮음 매우 높음

 

Plan Compiler pipeline

Graph
 ↓
Pattern match
 ↓
Kernel selection
 ↓
Execution plan
 ↓
Launch kernels

 

 

Codegen compiler pipeline

Graph
 ↓
Lowering
 ↓
Loop nest generation
 ↓
Code emission
 ↓
Compile
 ↓
Run

 

3. Plan Compiler 의 진짜 연구 영역

코드 생성이 아닌 선택 문제

Kernel variant selection

tile size
vectorization
warp mapping

Memory layout planning

pack
transpose
stride layout

Kernel fusion

Conv + Bias + ReLU
Attention fusion

runtime adaptation

profiling
dynamic plan switching