什么是“缓存中间结果”意思? [英] What does "an intermediate result is being cached" mean?

查看:176
本文介绍了什么是“缓存中间结果”意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组 n 向量存储在 3 x n 矩阵 z 中。我使用 np.einsum 找到外部产品。当我使用时间计时:

I have a set of n vectors stored in the 3 x n matrix z. I find the outer product using np.einsum. When I timed it using:

%timeit v=np.einsum('i...,j...->ij...',z,z)

我得到了结果:

The slowest run took 7.23 times longer than the fastest. This could mean that an
intermediate result is being cached 
100000 loops, best of 3: 2.9 µs per loop

这里发生了什么,可以避免吗?最好的3是2.9us,但最慢可能更典型。

What is happening here and can it be avoided? The best 3 is 2.9us, but the slowest maybe more typical.

推荐答案

消息中间结果被缓存只是%timeit报告的固定消息中的盲目猜测。它可能是也可能不是,你不应该认为它是正确的。

The message "intermediate result is being cached" is just a blind guess in the canned message reported by %timeit. It may or may not be true, and you should not assume it is correct.

特别是,第一次运行最慢的最常见原因之一是数组仅在首次运行后位于 CPU缓存中。

In particular, one of the most common reasons for the first run being slowest is that the array is in the CPU cache only after the first run.

CPU自动缓存内容;你无法避免这种情况,你真的不想避免它。但是,优化算法以便CPU缓存可以最佳地工作,这是高性能计算需要考虑的瓶颈之一。

CPUs cache things automatically; you cannot avoid this, and you don't really want to avoid it. However, optimizing algorithms so that CPU caches can work optimally is nowadays one of the bottlenecks that high-performance computing needs to take into account.

这篇关于什么是“缓存中间结果”意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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