contributed by < heathcliffYang
>
因為背景知識的不足,所以我決定先試著硬讀一遍,把不懂的都標注起來(有些不懂的在論文後面會接著說明),去查完所有不懂的東西之後,再讀一遍。
在整個 memory hierarchy 中,是相對小、快的 memory,只由硬體機制來掌控。
CPU 在真正需要用到該資料/指令之前,就先提出要求,藉由減少等待指令或資料的時間,讓 CPU 可以加速執行程式。
當資料/指令被要求時,會先被放置在 cache 裡,這會比從 memory 拿還快;此外, prefetching 可以掩蓋 memory access latency (從 request 直到 CPU 拿到資料的時間),也就可以拉近記憶體存取速度與處理器運算速度之間的落差。
這項技術也會是分支預測的一部分。
Prefetch 的種類
Prefetch metrics
Cache prefetching
利用先將預測可能會用到的 instruction / data 先從存取速度較慢的記憶體 fetch 到存取速度較快的 local memory。
Consider a for loop where each iteration takes 12 cycles to execute and the 'prefetch' operation takes 3 cycles. This implies that for the prefetched data to be useful, we must start the prefetch 12/3=4 iterations prior to its usage to maintain timeliness.
不懂維基百科上為何會這樣算?
因為是論文的關係,所以有很多藏在文章裡的描述與細節,如果是一篇好的分析,應該條列式列出每個實驗的主要探討因素。
Performance counter stats for './main_naive' (100 runs):
19,098,020 cache-misses # 96.506 % of all cache refs ( +- 0.04% )
19,789,367 cache-references ( +- 0.13% )
2,187,809,082 instructions # 1.29 insns per cycle ( +- 0.49% )
1,690,332,635 cycles ( +- 0.41% )
0.593995654 seconds time elapsed ( +- 0.66% )
Performance counter stats for './main_sse' (100 runs):
6,963,624 cache-misses # 81.878 % of all cache refs ( +- 0.08% )
8,504,869 cache-references ( +- 0.15% )
2,602,566,869 instructions # 1.49 insns per cycle ( +- 0.28% )
1,750,195,508 cycles ( +- 0.38% )
0.617119812 seconds time elapsed ( +- 0.65% )
Performance counter stats for './main_sse_prefetch' (100 runs):
7,058,261 cache-misses # 91.616 % of all cache refs ( +- 0.08% )
7,704,204 cache-references ( +- 0.17% )
2,013,680,676 instructions # 1.72 insns per cycle ( +- 0.06% )
1,172,678,900 cycles ( +- 0.31% )
0.420111002 seconds time elapsed ( +- 0.77% )