arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2410.00455cs.DC
收藏

RISC-V 上的细粒度向量化归并排序:从寄存器到缓存

Fine-Grained Vectorized Merge Sorting on RISC-V: From Register to Cache

Jin Zhang, Jincheng Zhou, Xiang Zhang, Di Ma, Chunye Gong

AI总结:

本文提出细粒度 RISC-V 向量化归并排序 RVMS,通过以寄存器数据代理数据混洗加速转置、用标量比较替代向量化比较,并提出半归并方案和非对称归并网络,解决从寄存器到缓存层面的归并排序性能瓶颈。

摘要:

归并排序作为一种“分治-排序-归并”范式,已被广泛应用于计算机科学领域。随着第五代精简指令集计算机(RISC-V)等现代精简指令集架构将多个寄存器视为向量寄存器组以实现宽指令并行,利用这种向量化特性优化归并排序变得越来越普遍。本文对“分治-排序-归并”范式进行了全面改造,从寄存器级排序到缓存感知归并,开发了一种细粒度的 RISC-V 向量化归并排序(RVMS)。从寄存器级视角来看,RISC-V 缺少内联向量化转置指令,因此高效实现该操作并非易事。此外,向量化比较在归并网络中并不总能良好工作。这两个问题主要源于昂贵的数据混洗指令。为绕过该指令,RVMS 努力将寄存器数据作为数据混洗的代理,以加速转置操作,同时用标量比较替代向量化比较,实现更轻量的实值交换。另一方面,由于缓存感知归并使得更大规模的数据在缓存中归并,大多数归并方案存在两个缺陷:缓存内归并通常缓存利用率较低,而缓存外归并网络仍然是一种低效的对称结构。为此,我们提出了半归并方案,利用原地归并的辅助空间将朴素归并排序的内存占用减半,同时将一个序列复制到该辅助空间以避免先前的数据交换。此外,还开发了一种非对称归并网络,以适应两种不同的输入规模。

英文摘要:

Merge sort as a divide-sort-merge paradigm has been widely applied in computer science fields. As modern reduced instruction set computing architectures like the fifth generation (RISC-V) regard multiple registers as a vector register group for wide instruction parallelism, optimizing merge sort with this vectorized property is becoming increasingly common. In this paper, we overhaul the divide-sort-merge paradigm, from its register-level sort to the cache-aware merge, to develop a fine-grained RISC-V vectorized merge sort (RVMS). From the register-level view, the inline vectorized transpose instruction is missed in RISC-V, so implementing it efficiently is non-trivial. Besides, the vectorized comparisons do not always work well in the merging networks. Both issues primarily stem from the expensive data shuffle instruction. To bypass it, RVMS strides to take register data as the proxy of data shuffle to accelerate the transpose operation, and meanwhile replaces vectorized comparisons with scalar cousin for more light real value swap. On the other hand, as cache-aware merge makes larger data merge in the cache, most merge schemes have two drawbacks: the in-cache merge usually has low cache utilization, while the out-of-cache merging network remains an ineffectively symmetric structure. To this end, we propose the half-merge scheme to employ the auxiliary space of in-place merge to halve the footprint of naive merge sort, and meanwhile copy one sequence to this space to avoid the former data exchange. Furthermore, an asymmetric merging network is developed to adapt to two different input sizes.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑