迫使L1高速缓存一些数据 [英] force some data on L1 cache

查看:97
本文介绍了迫使L1高速缓存一些数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个简单的问题道歉。与这里的一些记忆的概念还在挣扎。问题是:假设我有,我想重复访问pre-计算数组A。有没有办法告诉C程序,以保持这个数组尽可能接近到CPU缓存最​​快的访问?谢谢。

Apologies about this simple question. Still struggling with some of the memory concepts here. Question is: Suppose I have a pre-computed array A that I want to access repeatedly. Is there a way to tell a C program to keep this array as close as possible to the CPU cache for fastest access? Thanks.

推荐答案

有没有办法强制阵列在大多数架构L1 / L2高速缓存;不需要它通常,如果访问它经常是不太可能被从高速缓存中驱逐出去。

There is no way to force an array to L1/L2 cache on most architectures; it is not needed usually, if you access it frequently it is unlikely to be evicted from cache.

在某些架构中有一组指令,让你给处理器的一个暗示,存储位置很快就会被需要,以便它可以启动它初装到L1 / L2高速缓存 - 这被称为prefetching,例如见_mm_ prefetch指令(<一个href=\"http://msdn.microsoft.com/en-us/library/84szxsww(v=vs.80).aspx\">http://msdn.microsoft.com/en-us/library/84szxsww(v=vs.80).aspx )。还是这是不可能的,如果你访问一个小阵被需要。

On some architectures there is a set of instructions that allows you to give the processor a hint that the memory location will soon be needed, so that it can start loading it to L1/L2 cache early - this is called prefetching, see _mm_prefetch instruction for example ( http://msdn.microsoft.com/en-us/library/84szxsww(v=vs.80).aspx ). Still this is unlikely to be needed if you're accessing a small array.

一般的建议是 - 使你的数据结构的缓存效率第一(放相关的数据一起,包数据等),请稍后再试prefetching如果分析器告诉你,你仍然在高速缓存未命中花时间你不能改善的数据布局进一步。

The general advice is - make your data structures cache-efficient first (put related data together, pack data, etc.), try prefetching later if the profiler tells you that you're still spending time on cache misses and you can't improve the data layout any further.

这篇关于迫使L1高速缓存一些数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆