一句话:提出一种编译器设计,自动检测稀疏散射并插入模块化稀疏中间工作区张量,以高效生成稀疏张量代数代码。
稀疏张量代数编译器在将值散射到不支持随机插入的稀疏结果张量时,常生成时间与空间低效的代码。本文提出一种编译器设计:自动检测张量表达式中的稀疏散射行为,并插入稀疏中间张量(稀疏工作区)作为散射计算与结果张量之间的高效适配器;同时给出模块化的工作区插入算法模板,支持跨越多个用户自定义实现的工作区。评估显示,稀疏工作区比此前工作的稠密工作区最高快 27.12×,但某些场景下稠密工作区反而最高快 7.58×,因此编译器需同时支持两者。生成的顺序代码在其支持的表达式上可与手工优化的线性代数与张量库竞争,且稀疏工作区通过压缩零元素可渐近降低内存占用,使原本会内存不足的张量计算成为可能。
Recent years have seen considerable work on compiling sparse tensor algebra expressions. This paper addresses a shortcoming in that work, namely how to generate efficient code (in time and space) that scatters values into a sparse result tensor. We address this shortcoming through a compiler design that generates code that uses sparse intermediate tensors (sparse workspaces) as efficient adapters between compute code that scatters and result tensors that do not support random insertion. Our compiler automatically detects sparse scattering behavior in tensor expressions and inserts necessary intermediate workspace tensors. We present an algorithm template for workspace insertion that is the backbone of our code generation algorithm. Our algorithm template is modular by design, supporting sparse workspaces that span multiple user-defined implementations. Our evaluation shows that sparse workspaces can be up to 27.12 × faster than the dense workspaces of prior work. On the other hand, dense workspaces can be up to 7.58 × faster than the sparse workspaces generated by our compiler in other situations, which motivates our compiler design that supports both. Our compiler produces sequential code that is competitive with hand-optimized linear and tensor algebra libraries on the expressions they support, but that generalizes to any other expression. Sparse workspaces are also more memory efficient than dense workspaces as they compress away zeros. This compression can asymptotically decrease memory usage, enabling tensor computations on data that would otherwise run out of memory.
DOI 原文 · arXiv · PDF(开放获取) · DBLP
@article{ZhangHK24,
title = {Compilation of Modular and General Sparse Workspaces},
author = {Genghan Zhang and Olivia Hsu and Fredrik Kjolstad},
journal = {Proceedings of the ACM on Programming Languages},
volume = {8},
number = {PLDI},
year = {2024},
doi = {10.1145/3656426}
}