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

论算法缓存优化

On Algorithmic Cache Optimization

Neil Bhavikatti

AI总结:

本文研究矩阵乘法的缓存优化,提出O(1)缓存模拟器比较LRU与显式缓存策略,并通过更新C矩阵时间戳“欺骗”LRU以兼得显式策略优势,减少通信差异。

摘要:

我们研究两个大小为 $n \times n$ 的矩阵 $A$ 和 $B$ 的矩阵乘法。该操作产生一个大小为 $n \times n$ 的矩阵 $C$。我们的目标是在给定缓存(cache)的情况下尽可能高效地生成 $C$,缓存是一个一维的有限数据值集合,我们可以利用它来执行基本操作(加法、乘法等)。也就是说,我们尝试在计算过程中最大化地重用来自 $A$、$B$ 和 $C$ 的数据(或者等价地,尽可能频繁地利用快速访问缓存中的数据)。首先,我们介绍了矩阵乘法算法。其次,我们提出了一个标准的双内存模型来模拟计算机的架构,并解释了 LRU(最近最少使用)缓存策略(这是大多数计算机中的标准策略)。第三,我们引入了一个基本的模型缓存模拟器(Cache Simulator),其时间复杂度为 $\mathcal{O}(M)$(这意味着我们仅限于较小的 $M$ 值)。然后,我们讨论并建模了 LFU(最不经常使用)缓存策略和显式控制缓存策略。最后,我们介绍了本文的主要结果,即 $\mathcal{O}(1)$ 缓存模拟器,并使用它来实验比较理想缓存高效矩阵乘法算法在时间、能量和通信方面的节省。缓存模拟器模拟主内存与计算机缓存之间发生的数据移动量。该项目的一个发现是,在某些情况下,LRU 缓存算法与显式缓存控制之间的通信值存在显著差异。我们提出通过“欺骗”LRU 缓存算法来缓解这个问题,即更新我们希望保留在缓存中的数据(即矩阵 $C$ 的条目)的时间戳。这使我们能够在受限于 LRU 范式(CPU 上的现实策略)的同时,获得显式缓存策略的好处。

英文摘要:

We study matrix-matrix multiplication of two matrices, $A$ and $B$, each of size $n \times n$. This operation results in a matrix $C$ of size $n\times n$. Our goal is to produce $C$ as efficiently as possible given a cache: a 1-D limited set of data values that we can work with to perform elementary operations (additions, multiplications, etc.). That is, we attempt to reuse the maximum amount of data from $A$, $B$ and $C$ during our computation (or equivalently, utilize data in the fast-access cache as often as possible). Firstly, we introduce the matrix-matrix multiplication algorithm. Secondly, we present a standard two-memory model to simulate the architecture of a computer, and we explain the LRU (Least Recently Used) Cache policy (which is standard in most computers). Thirdly, we introduce a basic model Cache Simulator, which possesses an $\mathcal{O}(M)$ time complexity (meaning we are limited to small $M$ values). Then we discuss and model the LFU (Least Frequently Used) Cache policy and the explicit control cache policy. Finally, we introduce the main result of this paper, the $\mathcal{O}(1)$ Cache Simulator, and use it to compare, experimentally, the savings of time, energy, and communication incurred from the ideal cache-efficient algorithm for matrix-matrix multiplication. The Cache Simulator simulates the amount of data movement that occurs between the main memory and the cache of the computer. One of the findings of this project is that, in some cases, there is a significant discrepancy in communication values between an LRU cache algorithm and explicit cache control. We propose to alleviate this problem by ``tricking'' the LRU cache algorithm by updating the timestamp of the data we want to keep in cache (namely entries of matrix $C$). This enables us to have the benefits of an explicit cache policy while being constrained by the LRU paradigm (realistic policy on a CPU).

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

↑