Are your memory-bound benchmarking timings normally distributed?
lemire.me
lemire.me
Some of my assumptions about latency were wrong. One thing I didn't realize is it takes about half the latency to main memory to get miss through L1, L2, and L3. Also that you need to have around 2x the memory references pending to keep the memory system busy. It makes sense in retrospect, you want 16 pending memory references to keep 8 memory channels busy, otherwise a memory channel will return a cache line, and there won't be any L3 cache misses pending for that channel.
Generally I like to keep a small histogram of cycle counters to make sure I'm seeing the distribution I expect, seeing an unusual distribution is key for tracking down something you didn't account for.
Maybe it could never have been then, but maybe it can be now, or soon.
For instance a borrow checker might be a very good way to help decide how and when to move working memory between processors and main memory. But what do you do with all of the existing C code? I think for backward compatibility you'd need to implement virtual memory at the working memory layer. It wouldn't be the fastest code, but it would work.
Early AMD epycs had multiple chiplets, each with it's own memory controller. However that means that even on a single socket different chiplets would see different memory latencies and some apps/benchmarks people cared about handled it poorly.
The newest AMD Epycs have a unified memory controller per socket, so all chiplets see the same memory latency. But now Intel entered the chiplet game, and now has one memory controller per chiplet again.
There's plenty of support for NUMA support in the kernel and various language runtimes. Apps and OSs can pin processes to cores, allocate local ram, and migrate non-local ram to local or migrate processes to cores that are memory local. Generally the automatic stuff works reasonably, but numactl and various NUMA related calls let you override those decisions as needed.
64k of memory was not really enough to do useful things and it occupied so much of your design. But 4GB is a pretty big leap from 64k. There's lots of interesting things a person can do with 10, 30, 100MB of memory, without having to treat every piece of data like it sits in a perfectly flat data plane. And with 64 bit addressing you have ample, ample space to use some bits as metadata that lets you know things about the memory without dereferencing it first.
Your ideas remind me of the Sun MAJC CPU. Claimed to be designed to run Java well, be aware of Java Objects, enabling prefetch of objects, speculative execution without side effects, and other pointer magic related to assuming JVM+Java instead of C/C++. Sounded really promising, sadly died shortly afterwards. An expert I talked with later mentioned that it was all marketing and it was just a normal CPU for it's time. Sad. Does seem like today's new languages could result in a CPU with significantly more freedom for speculation, optimization, and efficiency if it assumed a particular language runtime.
Probably not a coincidence. It was memory of some Sun product data sheets that got me ruminating on this line of thought, though I don't think it was MAJC. 4MB per core, 4 cores per daughter card, if memory serves. Those product lines were probably a big reason why Java had to solve the NUMA memory problem, and then other languages just copied what they did.
It has the capabilities the GP wants, but it doesn't export them in a way you could tune into that NUMA machine.
Sure you can't hide metadata in the unused bits of a pointer, but that didn't seem particularly critical for making good use of a NUMA machine.
Fast memory, addressable by the core.
The one that is there, but can only used by accessing the slow memory.
I think ultimately what I'm asking for means a much, much tighter bound on worst case performance, but at the cost of best case performance. That most of us never see anyway. For certain workloads, that could end up being a net positive. And there's probably some way to expose CPU metadata that gives some of that difference back.
[1] https://en.m.wikipedia.org/wiki/Cell_(processor)#Synergistic...
Just? The chips we've got have between 32kb and 64kb -- maybe 128kb in some really big chips, and it's been that way for forty years! Everything else has to swap or cache through messaging layers (L2, L3) with real latency because we can't "just" put a bunch of memory on a chip.
I mean, I like thinking about star-trek computers too, but "just" isn't the word I would use for something like this... What would you possibly do with so much memory in a circuit?
> But what do you do with all of the existing C code? I think for backward compatibility you'd need to implement virtual memory at the working memory layer.
People rewrote almost everything in Java. And are doing it again with Rust. Programmers want to program, and if they can't come up with anything else to do, they'll just rewrite what someone else did. I don't think you should valuate existing C code the way its owners do, but by how their competition will valuate it; If someone can use FutureLang to outperform their business-competition who uses C, this problem will solve itself.
Programmung those is so different that you need to dressing specifically for the chip and unless there is no great consolidation, they stay niche.
[0] https://www.tomshardware.com/news/movidiud-myriad2-vpu-visio...
[1] https://www.nec.com/en/global/techrep/journal/g06/n05/pdf/t0...
Statistical fallacies are rampant in performance eval, even in academic settings. When designing statistical tests for performance, the keyword you want to use here is non-parametric. I.e., a U-test is a non-parametric analog to the t-test. It just looks at the rank statistics of results instead of their value, thus eliminating dependence on the underling distribution.
Another issue that pops up is sample independence. Statistical tests are often predicated on each sample being independent and identically distributed (i.i.d.), but in reality this is often not the case. For instance, running all the tests of one group and then all the tests of the other could heat the CPU and cause reduced performance in the second trial.
[1] https://clickhouse.com/blog/testing-the-performance-of-click...
NIST has some nice simple descriptions and example experimental designs:
https://www.itl.nist.gov/div898/handbook/pmd/pmd.htmhttps://en.wikipedia.org/wiki/Gamma_distribution#Occurrence_...
Why is the exponential distribution of waiting times a reasonable assumption in this case?
In the case of memory-bound code benchmarking? Because memory access in NUMA architectures with tiered caches are approximately exponential: L1 vs L2 vs L3 vs main memory vs swap are all exponential increases in latencies. It's obviously more of a step function than a continuous function but the relationship is definitely exponential.
The pages for the exponential distribution and poisson distribution are also informative and interesting.
https://en.wikipedia.org/wiki/Exponential_distribution#Occur...
https://en.wikipedia.org/wiki/Poisson_distribution#Occurrenc...
When I go through the process of finding an appropriate distribution, I usually first look through wikipedia to see if I can find conceptual parallels, just like this. That doesn't mean I settle on it..I'll usually test the distribution fit with functions like those found in fitdistr plus, as well as test to see if residuals are roughly normally distributed.
One hard and fast rule that I use though is that I never use an unbounded distribution to model a bounded process. For compute times, you can't have negative latencies, and you can't have zero latencies, but you can have infinite latencies. Therefore, I would only consider using distributions in the space of (0,infinity). The log normal distribution fits this and is probably adequate here, but the gamma distribution might be a smidge better.
https://cran.r-project.org/web/packages/fitdistrplus/vignett...
A concrete example of this: Exponential backoff where each attempt has a 1/2 probability of succeeding independently of other attempts, and you double the time between each attempt.
If you try to benchmark this process, you'll find that no matter how big your sample size is you'll never get consistent results.
Then I would run the same bench on my laptop and (with turbo disabled) ands its pretty much always consistent.
I can only guess why... turbo on the host cpu? Other transient tenants competing for the same cache? Something to do with VMs? Also I am not sure if AWS has this issue.
Bare metal ia OK if you must test NUMA and such, but you are still at the mercy of turbo behavior, where you can completely control that in a local machine.
("If your result depends on statistics then you need a better experiment.” Oft quoted remark attributed to Rutherford.)
s/experiment/optimization/
I'm happy with min, max and average. max is actually often the most important.
On the other hand the point of view in this paper is interesting:
"Violating the normality assumption may be the lesser of two evils" (1)
If you really feel the urge to do statistical tests then do it.
(I do not work in medicine or anything dangerous at all)
https://link.springer.com/article/10.3758/s13428-021-01587-5 (1)
The article questions the normal distribution assumption for benchmark timings.
It says that this assumption would be important for the "standard error of the mean":
"Your error should go down as the square root of the number of measures."
Standard distribution is not even necessary for this:
https://en.wikipedia.org/wiki/Standard_error
However, normal distributions actually behave benignly and are a prerequisite for some statistical tests.
This is where my first comment gets in, that for my benchmarking statistical tests are not necessary at all ...
---
The author writes that he only measures minimum and average, but the maximum values are of course also important and worth to measure.
The author's key point is that without a normal distribution, the maximum values can be highly scattered. I agree and basically it is always nice to know the distribution of the random variable.
> The typical assumption is that we get a normal distribution, and so we should therefore report the average time.
That "assumption" is asking a lot and is not justified. Actually, the main source of normal distributions is from the central limit theorem where get the distribution from adding lots of random variables.
> ... therefore report the average time
There are good reasons to consider averages for any distribution, "normal" or not.
Of course, as in a classic paper by Halmos and Savage, there is the topic of sufficient statistics that for the normal distribution is a bit amazing. Gee, maybe the OP (original post) was thinking about sufficient statistics. But for the normal distribution, the sufficient statistics are the pair of sample average and sample standard deviation.
> If you have normal distributions, you can mathematically increase the accuracy of the measure by taking more samples.
This is justified by the law of large numbers, both the strong and weak versions, where need not assume a normal distribution. Texts where the law of large numbers is proven in great detail and generality are by authors Loeve, Chung, Neveu, and Breiman, among others.
> It is not possible, in a normal distribution, to be multiple times the standard deviation away from the mean.
Sorry, with the normal distribution, there is positive probability of samples positive or negative with finite absolute value as large as please.
Is "possible" supposed to be "probable" there?
The other point he makes is that the mean is not very representative in this wide log-normal scenario, and optimizing for the difference between min and mean is more relevant.
My 2 cents.
Also to nitpick on the article:
"It is not possible, in a normal distribution, to be multiple times the standard deviation away from the mean."
I guess he meant probable :)