News for hackers. Stuff that matters.
Re:Optimising Memset and Memcpy by easytiger on Sunday November 28, 2021 @07:17AM (#29368323)
Half the benchmarks i see posted here are done on AWS instances or the authors laptop with power stepping/cstates, unisolated cores etc etc likely all enabled too, let alone basic rigour around hardware specifics.

We are very much entering the age where mechanical sympathy is waning

Re:Optimising Memset and Memcpy by astrobe_ on Sunday November 28, 2021 @08:11AM (#29368638)
CPU makers add so many complicated features to let users optimize their programs that it takes too much knowledge for mere mortals to optimize their programs - That you have to rely on heuristics and measures, as it is usually and wisely advised, is a bit unsatisfying. That's sort of ironic, in a way.

I used to do assembly and count cycles, but now I wouldn't dare; it's hardcore compiler and library makers stuff. It's like "don't do your own crypto (optimization)".

Everyone knows why it is so, though - we cannot solve the problem by throwing more Gigahertz at it.

Re:Optimising Memset and Memcpy by cout on Sunday November 28, 2021 @08:40AM (#29368814)
I have hand-written asm for use in production code, and I would do it again. I also knew exactly what cpu my code would be running on. If I were publishing the code to run on a variety of hardware, I would be very cautious.

Writing your own crypto is very different; the stakes are higher if you get it wrong.

Re:Optimising Memset and Memcpy by pjmlp on Monday November 29, 2021 @10:12AM (#29380743)
Including the microcode version currently installed into the CPU and gone through the release notes, alongside a profile like V-Tune?
Re:Optimising Memset and Memcpy by kierank on Sunday November 28, 2021 @04:57PM (#29373452)
This is definitely not correct. For many SIMDable workloads it's possible to achieve order of magnitude improvements over the compiler.
Re:Optimising Memset and Memcpy by WalterBright on Sunday November 28, 2021 @01:09PM (#29371221)
A good heuristic is simply minimize the number of instructions.
Re:Optimising Memset and Memcpy by mhh__ on Sunday November 28, 2021 @01:30PM (#29371453)
I doubt it'd be an issue for memcpy but minimizing the size of a loop body can lead to very counterintuitive speedups now processors have LSDs (loop stream detectors).
Re:Optimising Memset and Memcpy by jeffbee on Sunday November 28, 2021 @04:20PM (#29373157)
If you make them too small it can lead to counterintuitive slowdowns.
Re:Optimising Memset and Memcpy by nadav256 on Sunday November 28, 2021 @07:45AM (#29368505)
I guess that you are referring to other projects because the benchmarks in this repo use a stable seed, turbo disabled, physical machine, both random and stable sizes, etc.
Re:Optimising Memset and Memcpy by eternalban on Sunday November 28, 2021 @09:37AM (#29369211)
What’s the story with the spikes for folly and your code in memcpy plots? They get chopped off and it’s not clear what number they hit. (Nice work, btw)
Re:Optimising Memset and Memcpy by ungamed on Sunday November 28, 2021 @10:00AM (#29369367)
Havn't read the article, but c-states and p-states are different to turbo disabled.
Re:Optimising Memset and Memcpy by gpderetta on Sunday November 28, 2021 @07:28AM (#29368394)
Also the benchmark do not seem to use the same set of sizes for all benchmarks (nor use a fixed random seed) so repeatability and comparability seem questionable.

I guess if you run it often enough it could still give useful numbers, but I understand the author is picking the best run.

Also I don't see to be any attempt at avoiding compiler optimisations.

Benchmarking is hard

Re:Optimising Memset and Memcpy by nadav256 on Sunday November 28, 2021 @07:53AM (#29368544)
Grep the code for rand_reset. The code uses a fixed seed, fixed sizes for all programs, stable nop baseline, etc. also the pointer indirection blocks compiler optimizations.
Re:Optimising Memset and Memcpy by gpderetta on Sunday November 28, 2021 @12:12PM (#29370631)
Indeed. i looked at the benchmark itself, but not the RNG.
Re:Optimising Memset and Memcpy by dietr1ch on Sunday November 28, 2021 @12:39PM (#29370934)
IMO there's too many things to get right and no easy standard way of doing it.

Is there at least a checklist? It should ideally be automated. IIRC there's some library, maybe BLAS, that at compile time computes some machine-specific constants and also refuses to do it if a few things are not right.