본문 바로가기

AI Compiler framework

PlanCache vs KernelCache ( Execution Decision Lifetime Design)

왜 Cache 를 나눠야 하는가

AI Compiler 에서 두 가지 결정

  • 커널 자체에 대한 결정
  • 실행 순서 + 실행 맥락에 대한 결정

이 둘의 lifetime 이 다르기 때문에 Cache 도 분리 필요

 

KernelCache

  • 컴파일된 커널 바이너리
  • 커널 코드 그 자체

KernelCache Key 예시

(kernel_id,
 device_arch)

or

(kernel_name,
 sm_version)

해당 커널 코드가 이미 있는지만 확인

 

PlanCache 의 역할

이 조건이면 이렇게 실행한다

  • 커널
  • 순서
  • 파라미터
  • 메모리 맥락
(op_sequence_signature,
 shape_signature,
 dtype,
 layout,
 device_arch)

/////////////////////////

ExecutionPlan {
  step 0: kernel A, launch cfg
  step 1: kernel B, launch cfg
  step 2: kernel C, launch cfg
}

 

올바른 설계

컴파일 시

plan = compile(graph, context)
plan_cache[key] = plan

실행 시

plan = plan_cache[key]
replay(plan)

 

 

커널 선택 결과를 커널 캐시에 넣으면 안되는 이유는, 

커널이 같아도 의미가 다르기 때문