the issue is that because CPUs want to maintain backwards-compatibility, they end up messing with your machine code
Backwards compatibility is a reason, but not the only reason. If you were to design an ISA today, you'd still hide a lot of the underlying uArch details from the programmer's perspective, and the end result probably wouldn't be terribly different from x86.
As it turns out, the processor has a lot of runtime information that a compiler cannot determine ahead of time. Attempts try to and expose more of the underlying pipeline, like Intel's Itanium, generally haven't proven to be that successful.
I'd say Itanium had great potential, but then you have to wonder if it's usually worth it to get so close to the metal. It gets really complicated, and you might as well go the ASIC route if you want something really optimized. I've worked on some TI high performance chips, the documentation was about the size of the 8086 (being RISC helps) but still not something most people would want to write assembly for when they give you a compiler that does a pretty good job and they also give you hints to let the compiler help you.
There was a whole section showing how to optimize a loop (with the generated code) and in the end, if you let the compiler do its job you get the same result with no headache. Seriously, I don't want to remember if my variable is in ALU A or ALU B (one didn't have some of the less used operations).
You're assuming here unpredictable memory access latencies and a C-like memory semantics. Now, imagine an architecture without implicit caches, using an explicit scratchpad memory instead. Imagine it being managed by a minion CPU, exchanging messages with the main CPU core. Do you still need a dynamic OoO under these assumptions? Can you do more scheduling in software in runtime instead?
For example, message-passing based LSUs are in vogue now in GPUs. Yet, with C semantics it's hard to get the most out of this model.
You don't have to imagine it - this is what the Playstation 3's Cell CPU used - 7 DSP-like cores sitting on a ring with scratchpad memory on each one.
Also, message-passing based LSUs are used in pretty much every CPU at this point; every time something crosses a block boundary, it's pumped into a message queue.
Scheduling in software becomes an issue, because of the amount of time it takes to load the extra instructions to manage it from memory. I$ is still limited, and the limiting factor for most CPUs is that they're memory-bound. If you can put all of the memory on an SOC (unlikely because of heat and power constraints), then you no longer need to worry about driving the lines, rise times and matching voltages, and can up the speed - but without that, you quickly dwarf your throughput with all the extra work.
There's a case for doing it with extremely large workloads of contiguous data, where you're doing lots of the same operations on something. This is something that GPUs excel at (as do DSPs), because it's effectively a long pipe with little to no temporal coherence except a synchronization point at the end, and lots of repeated operations, so you can structure the code well enough to hide memory management work among the actual useful work.
But for general use? It's not that good. It's the same problem as branch prediction - branch prediction is great when you're in an inner loop and are iterating over a long list with a terminal value. If you're branching on random data (e.g. for compression or spatial partitioning data sets), it's counterproductive as it'll typically mispredict 50% of the time.
You can get around some of this by speculatively executing work (without side effects) and discarding it from the pipeline, but most software engineers value clean, understandable, debuggable code vs. highly optimized but nonintuitive code that exploits the architecture.
So, TL;DR: For long sequential repetitive workloads with few branches, sure. For any other workload, you're shooting yourself in the foot.
Of course - I designed such systems, along with low level languages tailored for this model. It's a pretty standard approach now.
Also, message-passing based LSUs are used in pretty much every CPU at this point
I'm talking about explicit message passing - see the AMD GCN ISA for example, with separate load and wait instructions.
and the limiting factor for most CPUs is that they're memory-bound
There is a huge class of SRAM-only embedded devices though.
But for general use? It's not that good.
Define the "general use". Also, if we want to break the performance ceiling, we must stop caring about some average "general" use. Systems must become domain-specific on all levels.
You can get around some of this by speculatively executing work (without side effects) and discarding it from the pipeline
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.
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.
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.
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.
11
u/YumiYumiYumi May 02 '18
Backwards compatibility is a reason, but not the only reason. If you were to design an ISA today, you'd still hide a lot of the underlying uArch details from the programmer's perspective, and the end result probably wouldn't be terribly different from x86.
As it turns out, the processor has a lot of runtime information that a compiler cannot determine ahead of time.
Attempts try to and expose more of the underlying pipeline, like Intel's Itanium, generally haven't proven to be that successful.