본문 바로가기

AI Compiler Generator

Properties 관련 4계층 역할 정리

4계층 역할 정의

1. properties/

역할 문장
연산 변환이 의미 보존적으로 성립하기 위한 최소 legality condition을 정의하는 계층.

무엇을 담는가

  • order_rewritable
  • tile_composable
  • rematerializable
  • representation_invariant
  • precision_relaxable
  • associative_merge
  • local_accumulable
  • schedule_invariant
  • domain_prunable

이 계층의 질문

  • 왜 이 transform이 합법적인가
  • 어떤 조건에서 reorder / decompose / tile / fuse / recompute가 가능한가
  • 어디까지가 성립 경계인가

한 줄 요약
properties는 왜 바꿔도 되는가를 설명한다. 이건 현재 AICF 문구와도 정확히 맞는다.


2. motifs/

역할 문장
서로 다른 operator들 사이에 반복적으로 나타나는 근본 구조적 패턴을 정리하는 계층.

무엇을 담는가

  • mergeable_statistics
  • weighted_reduction
  • rescaled_accumulation
  • bounded_summary_state
  • streaming_normalization
  • coupled_numerator_denominator
  • decomposable_score_value_flow

이 계층의 질문

  • 이 연산군은 어떤 공통 구조를 가지는가
  • 어떤 sufficient state로 요약될 수 있는가
  • 어떤 primitive 후보로 분해될 수 있는가

한 줄 요약
motifs는 무엇이 공통 구조로 존재하는가를 설명한다.


3. primitives/

역할 문장
motif와 property를 바탕으로 실제 GPU 실행 단위로 내려간 reusable execution realization을 구현하는 계층.

무엇을 담는가

  • tree_reduction
  • warp_reduce
  • block_reduce
  • online_accumulation
  • streaming_weighted_sum
  • tile_staging
  • double_buffer_stage
  • rematerialized_epilogue
  • boundary_elimination

이 계층의 질문

  • 이 구조를 GPU에서 어떻게 실현할 것인가
  • realization variant는 무엇인가
  • 어떤 primitive family가 존재하는가

한 줄 요약
primitives는 어떻게 실행 구조로 만들 것인가를 설명한다.


4. ops/

역할 문장
개별 operator가 어떤 motif, property, primitive 조합으로 이해되고 어떤 lowering family로 이어지는지를 정리하는 계층.

무엇을 담는가

  • softmax
  • layernorm
  • rmsnorm
  • attention
  • gemm_epilogue
  • reduce_sum
  • topk
  • conv_like_accumulation

이 계층의 질문

  • 이 operator는 어떤 property profile을 가지는가
  • 어떤 motifs가 핵심 구조인가
  • 어떤 primitives로 실현 가능한가
  • lowering family 후보는 무엇인가

한 줄 요약
ops는 실제 연산자가 위 세 계층과 어떻게 연결되는가를 보여준다. 이것도 현재 Ops Explorer 설명과 맞다.


추천 디렉토리 구조

📦compute
┣ 📂properties
┃ ┣ 📜associative_merge.js
┃ ┣ 📜domain_prunable.js
┃ ┣ 📜local_accumulable.js
┃ ┣ 📜order_rewritable.js
┃ ┣ 📜precision_relaxable.js
┃ ┣ 📜rematerializable.js
┃ ┣ 📜representation_invariant.js
┃ ┣ 📜schedule_invariant.js
┃ ┣ 📜tile_composable.js
┃ ┗ 📜index.js
┣ 📂motifs
┃ ┣ 📜mergeable_statistics.js
┃ ┣ 📜weighted_reduction.js
┃ ┣ 📜rescaled_accumulation.js
┃ ┣ 📜bounded_summary_state.js
┃ ┣ 📜streaming_normalization.js
┃ ┣ 📜coupled_numerator_denominator.js
┃ ┣ 📜decomposable_score_value_flow.js
┃ ┗ 📜index.js
┣ 📂primitives
┃ ┣ 📜tree_reduction.js
┃ ┣ 📜warp_reduce.js
┃ ┣ 📜block_reduce.js
┃ ┣ 📜online_accumulation.js
┃ ┣ 📜streaming_weighted_sum.js
┃ ┣ 📜tile_staging.js
┃ ┣ 📜double_buffer_stage.js
┃ ┣ 📜rematerialized_epilogue.js
┃ ┣ 📜boundary_elimination.js
┃ ┗ 📜index.js
┣ 📂ops
┃ ┣ 📜softmax.js
┃ ┣ 📜layernorm.js
┃ ┣ 📜rmsnorm.js
┃ ┣ 📜attention.js
┃ ┣ 📜gemm_epilogue.js
┃ ┣ 📜reduce_sum.js
┃ ┣ 📜topk.js
┃ ┗ 📜index.js
┗ 📜README.md
 

폴더별 소개 문장

properties/

변환 합법성을 판정하는 계층이다.
operator 이름이 아니라 semantic/algebraic law를 기준으로, 어떤 재배치·분해·병합·타일링·재구성이 의미 보존적으로 허용되는지 정의한다. 현재 페이지가 지향하는 runtime transformation을 허용하는 property라는 설명과 그대로 맞물린다.

motifs/

서로 다른 operator에 반복적으로 나타나는 공통 구조를 정리하는 계층이다.
이곳은 legality 자체보다, 연산군이 공유하는 구조적 핵심과 sufficient state, decomposition pattern, streaming 가능성을 다룬다.

primitives/

motif를 실제 실행 구조로 내리는 계층이다.
GPU에서 재사용 가능한 reduction, accumulation, staging, rematerialization 같은 realization family를 담는다.

ops/

개별 operator의 해석 계층이다.
각 operator가 어떤 property profile을 갖고, 어떤 motifs를 포함하며, 어떤 primitives와 lowering family로 이어지는지 정리한다. 현재 Ops Explorer가 맡고 있는 역할이 여기에 해당한다.


관계를 한 줄로 정리하면

properties = 왜 바꿔도 되는가
motifs = 무엇이 공통 구조인가
primitives = 그것을 어떻게 실행 구조로 만드는가
ops = 실제 operator가 이들과 어떻게 연결되는가
 

가장 추천하는 운영 원칙

이 원칙으로 가면 안 흔들린다.

  • properties에는 법칙과 조건만 넣는다.
  • motifs에는 구조와 패턴만 넣는다.
  • primitives에는 실행 realization만 넣는다.
  • ops에는 연결과 프로파일만 넣는다.

즉,

  • softmax의 shift-invariance는 properties
  • softmax의 coupled numerator/denominator 구조는 motifs
  • online softmax state update는 primitives
  • softmax 전체 profile은 ops

이렇게 자르면 된다.