第5章アルゴリズムのハードウェアによる実現:コンピューターシステム設計
Locality局所性
Throughout our discussion of the memory hierarchy, we have determined the following:
メモリ階層の説明を通して、次のことがわかった。
• Memory is read in a chunk of consecutive 64 bits which is 8 bytes.
• メモリは、連続する64ビット、つまり8バイトのまとまりで読み出す。
• Whenever there is a cache miss, the cache works to bring a cache block, not the few bytes the processor needs. Most caches now have a cache block of 64 bytes. Those 64 bytes are consecutive bytes brought from the lower-level cache, that come from the even lower cache (i.e., from L3 to L2 to L1). The L3 cache brought the block from memory.
英語のヒント
• キャッシュミスが起きると、キャッシュはプロセッサが必要とする数バイトだけでなく、キャッシュブロックを取り込む。現在のほとんどのキャッシュでは、ブロックは64バイトである。この64バイトは、下位のキャッシュから取り込む連続したバイトであり、さらに下位のキャッシュから来たものである。つまり、L3からL2、L2からL1へと移る。L3キャッシュは、そのブロックをメモリから取り込んでいる。
When a processor repeatedly visits the same memory locales, it has locality. We can surmise that if a program accesses the data in a consecutive manner, it gets better performance, called spatial locality. Also, if we reuse the data as much as possible, we get better performance because the data is available in the cache, and we can increase the cache hits. We call this second criteria temporal locality.
英語のヒント
プロセッサが同じメモリの場所を繰り返し訪れるとき、局所性があるという。プログラムが連続した順序でデータにアクセスすれば、性能がよくなると推測できる。これを空間的局所性という。また、データをできるだけ再利用すれば、データがキャッシュに残っており、キャッシュヒットを増やせるため、性能がよくなる。この第二の性質を、時間的局所性という。
We can get even better performance if the programmer writes efficient code that makes the best use of the underlying hardware. An efficient program has a very important characteristic called locality. For example, if you want to add two arrays together (i.e., A[0] + B[0], A[1] + B[1]), then you get a good performance if you access these two arrays sequentially from element 0 until the end of the arrays which is an example of spatial locality. So, whenever you are writing a program, pay close attention to how you access the data.
英語のヒント
プログラマーが、土台となるハードウェアを最大限に活用する効率のよいコードを書けば、さらに性能を高められる。効率のよいプログラムには、局所性という非常に重要な性質がある。たとえば、二つの配列を足す、つまりA[0] + B[0]、A[1] + B[1]などを計算するなら、要素0から配列の末尾まで順にアクセスすると性能がよくなる。これは空間的局所性の例だ。そのため、プログラムを書くときは、データへのアクセスのしかたによく注意しよう。
Instructions also reside in memory. If we have a for-loop that is executed several thousand times, the instructions in the loop body are reused in every iteration which is an example of temporal locality.
英語のヒント
命令もメモリ内に置かれている。数千回実行するforループがあれば、ループ本体の命令は反復のたびに再利用される。これは時間的局所性の例である。