[논문 리뷰] A Deep Learning Based Cost Model for Automatic Code Optimization
이 논문은 Tiramisu 컴파일러에서 전체 프로그램에 적용된 코드 변환으로부터 속도 향상을 예측하는 딥 러닝 기반 비용 모델을 제시하며, 평균 절대 백분율 오차(MAPE)가 약 16%에 이르고, heavy feature engineering 없이도 경쟁력 있는 자동 최적화를 가능하게 한다.
Enabling compilers to automatically optimize code has been a longstanding goal for the compiler community. Efficiently solving this problem requires using precise cost models. These models predict whether applying a sequence of code transformations reduces the execution time of the program. Building an analytical cost model to do so is hard in modern x86 architectures due to the complexity of the microarchitecture. In this paper, we present a novel deep learning based cost model for automatic code optimization. This model was integrated in a search method and implemented in the Tiramisu compiler to select the best code transformations. The input of the proposed model is a set of simple features representing the unoptimized code and a sequence of code transformations. The model predicts the speedup expected when the code transformations are applied. Unlike previous models, the proposed one works on full programs and does not rely on any heavy feature engineering. The proposed model has only 16% of mean absolute percentage error in predicting speedups on full programs. The proposed model enables Tiramisu to automatically find code transformations that match or are better than state-of-the-art compilers without requiring the same level of heavy feature engineering required by those compilers.
연구 동기 및 목표
- 학습된 비용 모델을 사용해 변환 탐색을 안내하고 코드 최적화를 자동화하는 것을 동기화한다.
- 무거운 특징 공학(feature engineering)을 피하는 전체 프로그램 딥 러닝 회귀 모델을 개발한다.
- 모델을 검색 전략과 통합하여 고성능 코드 변환을 자동으로 식별한다.
- 실제 벤치마크에서 최첨단 모델 및 베이스라인과의 정확도와 효과를 평가한다.
제안 방법
- 데이터 생성기를 구성하여 무작위 Tiramisu 프로그램과 유효한 변환 시퀀스를 생성하고 실제 속도 향상을 측정한다.
- 루프 중첩, 대입, 변환 등을 포함하는 컴팩트한 AST 기반 계산 벡터로 프로그램을 표현한다.
- 계산 임베딩, 재귀적 루프 임베딩 유닛(두 개의 LSTM + 융합), 및 회귀 층을 결합한 하이브리드 신경망 아키텍처를 제안해 속도 향상을 예측한다.
- MAPE를 최소화하도록 PyTorch와 AdamW를 사용해 모델을 훈련한다.
- 학습된 모델을 트리 기반 탐색(빔 탐색 및 몬테카를로 트리 탐색)에서 목표로 사용하여 모델 불확실성을 고려하며 코드 변환 시퀀스를 탐색한다.
- Halide 기반 비용 모델과 비교하고 정확도, 순위 및 탐색 시간과 최종 성능 간의 트레이드오프를 분석한다.
실험 결과
연구 질문
- RQ1CPU 맥락에서 전체 프로그램에 적용된 코드 변환 시퀀스로부터 속도 향상을 예측하는 딥 러닝 모델이 가능한가?
- RQ2전체 프로그램에서 작동하는 무거운 핸드 엔지니어링 특징을 피하는 경우 예측 정확도와 랭킹 품질이 저하되는가 아니면 유지되는가?
- RQ3학습된 모델이 현실적인 벤치마크에서 빔 탐색과 MCTS를 얼마나 효과적으로 안내해 고성능 변환 시퀀스를 발견할 수 있는가?
- RQ4제안된 모델이 정확도 면에서 Halide의 비용 모델과 그리고 다양한 워크로드에서 자동 최적화를 촉진하는 면에서 어떻게 비교되는가?
주요 결과
- 테스트 세트에서 속도향상 예측의 MAPE가 16%이다.
- 예상 속도향상/랭크 간 피어슨 상관계수 0.90, 스피어만 상관계수 0.95.
- 모델은 타이루마수(Tiramisu)가 여러 벤치마크에서 최첨단 컴파일러에 필적하거나 이를 능가하는 변환을 자동으로 찾도록 한다.
- 비용 모델을 활용한 빔 탐색은 최종 성능의 소폭 저하와 함께 탐색 시간에서 상당한 속도 향상을 달성한다(평균 약 15%).
- 모델을 활용한 MCTS는 경쟁력 있는 결과를 제공하며 일부 벤치마크에서 모델 불확실성 처리에 더 나은 성능을 보인다.
이 논문 읽기
누빈트 뷰어에서 원문을 열고, 읽으면서 궁금한 곳을 바로 물어보세요.
누빈트에서 이 논문 읽기이 리뷰는 AI가 논문 원문을 바탕으로 만들었습니다. 인용하기 전에 원문을 확인해 주세요.