42 points · by DanielRibeiro · 13y ago · 18 comments
I guess this is true, but it's sort of misleading. Adding some details as I understand them:
1) On Sandy Bridge, a read from cache takes the same amount of time whether you are reading a single byte or a 32 byte AVX vector. That said, it is often faster though to read integers individually than to read them as a vector and split them.
2) While the L2 latency is comparable to taking a single square root, if using an XMM register, you can also take 4 square roots in the same number of cycles. Viewed this way, if you can use SIMD, you could consider each square root to be comparable to an L1 hit.
3) For DDR3-1600 10-10-10 (current fast standard) a read from main memory will take 12.5 ns to start returning data. At 4GHz, this is 50 CPU cycles. DDR3-1333 10-10-10 is 15 ns --- about 60 cycles. This is about twice as long as a read from L3: longer, but not "far, far longer".
[Note to author: s/26 bytes/26 cycles/]
Is there a good introductory resource for learning about low-level details like the ones discussed in the post?
http://www.akkadia.org/drepper/cpumemory.pdf
Slightly dated but still excellent introduction.
http://www.amazon.com/Computer-Organization-Design-Fourth-Ed...
https://en.wikipedia.org/wiki/Strassen%27s_algorithm
Constant factor improvements are great, but asymptotic improvements are better.
"Earlier authors had estimated that Strassen's algorithm is faster for matrices with widths from 32 to 128 for optimized implementations. However, it has been observed that this crossover point has been increasing in recent years, and a 2010 study found that even a single step of Strassen's algorithm is often not beneficial on current architectures, compared to a highly optimized traditional multiplication, until matrix sizes exceed 1000 or more, and even for matrix sizes of several thousand the benefit is typically marginal at best (around 10% or less)."
I am not going to deny that hardware matters, but it is important to know where it matters. Hardware matters in terms of constant factors. For sufficiently large problem sizes, hardware might give you a 10x improvement if you use it correctly -- but that is 10x no matter how large the problem size becomes. An algorithmic improvement will become increasingly beneficial as the problem size increases; that is why we speak of things like "crossing points," where an asymptotically faster algorithm begins to dominate. Even very poor use of hardware features (terrible locality of reference, etc.) will eventually be irrelevant for an asymptotically better algorithm; a large number of really good uses of the hardware is still slower than a small number of really bad uses.
That is not true. Asymptotic analysis assumes that memory loads/stores have uniform cost, not that they have no cost at all. You do not see loads/stores included explicitly in algorithmic analysis because typically a load/store will appear in conjunction with some other operation, so the cost is just rolled together as part of the constant factor.
"Strassen seems to be using more memory bandwidth than the naive multiplication so it's likely to be even slower."
Only for small problem sizes. As the problem size increases, Strassen's algorithm will dominate. The Wikipedia article suggests that the "crossing point" is somewhere in the thousands range (i.e., an NxN matrix where N is several thousand), and after that Strassen's algorithm becomes increasingly faster. To put it another way, a small number of expensive operations will still be faster than a large number of cheap operations (for some value of "small" and "large," but the difference will increase as the problem size increases).
>Only for small problem sizes. As the problem size increases
This is the difference between software engineering and computer science. The real problems do not grow in size quite often. If I am writing a 3D engine I do not expect my matrices suddenly grow. Ditto if I am solving some linear system derived from a real model - it's unlikely that the model properties are going to change any time soon.
https://en.wikipedia.org/wiki/Coppersmith-Winograd_algorithm
Strassen's algorithm is certainly used in practice.