| |
| Posted by Walter Bright in reply to Bruce Carneal | PermalinkReply |
|
Walter Bright
Posted in reply to Bruce Carneal
| On 6/7/2022 2:23 AM, Bruce Carneal wrote:
> On Tuesday, 7 June 2022 at 07:05:04 UTC, Walter Bright wrote:
>> dmd doesn't do autovectorization.
>>
>> However, you can write vector code using vector types if you wish.
>
> vector types are a great feature. That said, for readability I'm migrating my __vector code base to autovectorization for the CPU-only deployments and autovec+SIMT/dcompute for the rest.
>
> Fortunately the recent autovectorizer code performance equals or exceeds the "manual" code in many instances (more aggressive unrolling and better/finer-grain handling of intermediate lengths). OTOH, if perf drops,and SIMT is not available, __vector it is!
>
I've never much liked autovectorization:
1. you never know if it is going to vectorize or not. The vector instruction sets vary all over the place, and whether they line up with your loops or not is not determinable in general - you have to look at the assembler dump.
2. when autovectorization doesn't happen, the compiler reverts to non-vectorized slow code. Often, you're not aware this has happened, and the expected performance doesn't happen. You can usually refactor the loop so it will autovectorize, but that's something only an expert programmer can accomplish, but he can't do it if he doesn't *realize* the autovectorization didn't happen. You said it yourself: "if perf drops"!
3. it's fundamentally a backwards thing. The programmer writes low level code (explicit loops) and the compiler tries to work backwards to create high level code (vectors) for it! This is completely backwards to how compilers normally work - specify a high level construct, and the compiler converts it into low level.
4. with vector code, the compiler will tell you when the instruction set won't map onto it, so you have a chance to refactor it so it will.
|