[Triton] Gluon의 to_linear_layout에서 TensorMemory 레이아웃 지원
PR 링크: triton-lang/triton#8682 상태: Merged | 변경: +100 / -47
들어가며
Triton의 Gluon 프론트엔드는 to_linear_layout 함수를 통해 다양한 인코딩을 LinearLayout으로 변환한다. 기존에는 DistributedLayout과 SharedLayout만 지원했는데, 이 PR은 NVIDIA Blackwell의 TensorMemory 인코딩도 처리할 수 있도록 확장한다. 이는 TMEM 관련 디버깅과 레이아웃 출력에 필수적이다.
핵심 코드 분석
C++ 레이어 확장 (gluon_ir.cc)
Before:
auto linearLayout = ttg::toLinearLayout(shape, layout);
auto attr = ttg::LinearEncodingAttr::get(ctx, linearLayout);
return layoutToGluon(attr);
After:
auto linearLayout = ttg::toLinearLayout(shape, layout);
if (isa<ttg::DistributedEncodingTrait>(layout)) {
auto attr = ttg::LinearEncodingAttr::get(ctx, linearLayout);
return layoutToGluon(attr);
}
if (isa<ttg::SharedEncodingTrait>(layout)) {
auto alignment = cast<ttg::SharedEncodingTrait>(layout).getAlignment();
auto attr = ttg::SharedLinearEncodingAttr::get(ctx, linearLayout, alignment);
return layoutToGluon(attr);
}
// TensorMemory: wrap as print-only Python object
인코딩 타입에 따라 적절한 LinearLayout 래퍼를 생성한다. TensorMemory의 경우 Python 측의 _TensorMemoryLinearLayout 객체로 감싼다.
Python semantic 확장
_check(
isinstance(layout, (DistributedLayout, SharedLayout,
TensorMemoryLayout, TensorMemoryScalesLayout)),
lambda: f"Expected a supported layout type, got {type(layout)}"
)
왜 이게 좋은가
- 통합 API: 모든 레이아웃 타입이 하나의
to_linear_layout함수로 처리된다 - 디버깅 용이: TMEM 레이아웃도
static_print로 출력하여 개발 시 확인 가능 - SharedLinearLayout에 shape 속성 추가: 기존에 없던
shape프로퍼티를 계산하여 반환
정리
LinearLayout은 Triton에서 모든 데이터 분배를 표현하는 핵심 추상화다. 새로운 메모리 타입(TensorMemory)이 추가될 때 이 추상화로 통합하는 것은 장기적으로 코드 일관성을 유지하는 데 중요하다.
참고 자료
이 글은 AI(Claude)의 도움을 받아 작성되었습니다. 코드 분석 내용은 실제 PR diff를 기반으로 합니다.
관련 포스트
PR Analysis 의 다른글
- 이전글 [pydantic-ai] Anthropic 캐시 가능 타입에 document 추가
- 현재글 : [Triton] Gluon의 to_linear_layout에서 TensorMemory 레이아웃 지원
- 다음글 [triton] Out-of-tree TTIR/TTGIR 패스 플러그인 시스템
댓글