我想了解人们是如何进行缓存优化的,我被一位朋友推荐为实现这一目标的有用工具。
作为CPU模拟器,当使用cache差使时,假设有一个2级缓存,正如前面提到的这里。
Cache差制模拟程序如何与机器的缓存层次结构和(可选)分支预测器交互。它模拟一台具有独立一级指令和数据缓存(I1和D1)的机器,由一个统一的二级缓存(L2)支持。这完全符合许多现代机器的配置。
下一段继续为
然而,一些现代机器有三到四个级别的缓存。对于这些机器(在高速缓存可以自动检测高速缓存配置的情况下),缓存器模拟一级和最后级缓存。之所以选择这个选项,是因为最后一级缓存对运行时的影响最大,因为它掩盖了对主存的访问。
然而,当我尝试在我的简单矩阵-矩阵乘法代码上运行val研时,我得到了以下输出。
==6556== Cachegrind, a cache and branch-prediction profiler
==6556== Copyright (C) 2002-2010, and GNU GPL'd, by Nicholas Nethercote et al.
==6556== Using Valgrind-3.6.0.SVN-Debian and LibVEX; rerun with -h for copyright info
==6556== Command: ./a.out
==6556==
--6556-- warning: L3 cache detected but ignored
==6556==
==6556== I refs: 50,986,869
==6556== I1 misses: 1,146
==6556== L2i misses: 1,137
==6556== I1 miss rate: 0.00%
==6556== L2i miss rate: 0.00%
==6556==
==6556== D refs: 20,232,408 (18,893,241 rd + 1,339,167 wr)
==6556== D1 misses: 150,194 ( 144,869 rd + 5,325 wr)
==6556== L2d misses: 10,451 ( 5,506 rd + 4,945 wr)
==6556== D1 miss rate: 0.7% ( 0.7% + 0.3% )
==6556== L2d miss rate: 0.0% ( 0.0% + 0.3% )
==6556==
==6556== L2 refs: 151,340 ( 146,015 rd + 5,325 wr)
==6556== L2 misses: 11,588 ( 6,643 rd + 4,945 wr)
==6556== L2 miss rate: 0.0% ( 0.0% + 0.3% )根据文档,应该使用L1和L3缓存,但是输出表明L3缓存被忽略了。为什么会这样呢?
另外,缓存是否预先假定了L1和最后一级缓存的大小,还是使用了当前运行的CPU的L1和最后一级缓存大小?
发布于 2013-12-31 01:03:47
您正在运行的英特尔CPU,缓存似乎没有完全支持。他们检查cpuid标志,并根据大量不同处理器的case语句确定支持。
这是代码的非官方副本,但是是说明性的- https://github.com/koriakin/valgrind/blob/master/cachegrind/cg-x86-amd64.c。
/* Intel method is truly wretched. We have to do an insane indexing into an
* array of pre-defined configurations for various parts of the memory
* hierarchy.
* According to Intel Processor Identification, App Note 485.
*/
static
Int Intel_cache_info(Int level, cache_t* I1c, cache_t* D1c, cache_t* L2c)
{
...
case 0x22: case 0x23: case 0x25: case 0x29:
case 0x46: case 0x47: case 0x4a: case 0x4b: case 0x4c: case 0x4d:
case 0xe2: case 0xe3: case 0xe4: case 0xea: case 0xeb: case 0xec:
VG_(dmsg)("warning: L3 cache detected but ignored\n");
break;https://stackoverflow.com/questions/20850023
复制相似问题