r/programming • • May 01 '18

C Is Not a Low-level Language - ACM Queue

https://queue.acm.org/detail.cfm?id=3212479
152 Upvotes

303 comments sorted by

View all comments

Show parent comments

3

u/YumiYumiYumi May 02 '18

C-like memory semantics

I think that's a key problem - we can't really move away from this easily, and explicit notion of different memory tiers isn't support by C or any higher level language (C#, Javascript etc). We do have NUMA, but that typically isn't as fine grained as something small enough to fit on a CPU.

Can compilers automatically make use of explicit tiers? I don't know, but I'd guess that the CPU would do a better job at it.

The other issue would be the overhead of having the manage the tiers (e.g. transfer to/from) and whether or not this scratchpad memory has a fixed size (which limits processor flexibility) or can be different on different CPUs (more flexible, but is extra complexity the programmer/compiler has to deal with). There's also the case of needing to worry about transfer latencies, which could likely vary from chip to chip, and context switching could be an interesting problem.
In some way, cache can be somewhat controlled via prefetch and eviction instructions, but I rarely see it used as it bloats instruction size and often ends up being less efficient than the processor automatically managing cache.

I really don't know whether scratchpad memory is a good idea, but my gut feeling is that caching probably ends up being better for most cases.

Do you still need a dynamic OoO under these assumptions?

It isn't just memory accesses which are hard to predict. Branching is another issue I can think of, off the top of my head.

1

u/[deleted] May 03 '18

Can compilers automatically make use of explicit tiers?

Nope. Definitely not for C, with its very sloppy notion of aliasing.

but my gut feeling is that caching probably ends up being better for most cases.

We've already hit the performance ceiling. If we want to break through it, we should stop caring about "most cases" and start designing bespoke systems for all the special cases.

1

u/YumiYumiYumi May 03 '18

start designing bespoke systems for all the special cases

What special cases do you see benefiting from scratchpad memory over what we can currently do managing a cache?

Another thing to point out is that optimising for specific cases can't really come at the expense of general case performance.

1

u/[deleted] May 03 '18

What special cases do you see benefiting from scratchpad memory over what we can currently do managing a cache?

Pretty much any particular case have a particular memory access pattern which most likely will not be well aligned with a dumb cache. For specifics, see pretty much any case where local memory is used in a GPU code (on architectures where local memory is actually a proper scratchpad memory, GCN for example).

at the expense of general case performance

Again, we should forget about the "general case". There is no way through the ceiling for any "general case" now.

1

u/YumiYumiYumi May 04 '18

Well I don't know any, which is why I asked, but anyway...

Again, we should forget about the "general case". There is no way through the ceiling for any "general case" now.

Nice idea, except that, statistically speaking, no-one's going to buy a CPU that sucks at the general case. You can optimise for specific cases, but it can't come at the expense of the general case.

1

u/[deleted] May 04 '18

Quite the opposite. Nobody cares about some abstract "general case". Everyone's only interest is their particular kind of load.