AMD performances vs Intel on BLAKE3-C-straight, no asm #546

Closed
opened 2021-07-31 10:47:44 -05:00 by fcorbelli · 4 comments
fcorbelli commented 2021-07-31 10:47:44 -05:00 (Migrated from github.com)

Doing some test I find that the "straight" C (no asm, no SSE etc) implementation of BLAKE3 (in C) runs about 50% faster of SHA-256 on very rough benchmark, for older i7 and just old i7 (Windows 10).

But on AMD 5950X runs 3% slower (of SHA-256), at least in my implementation.
Others hash-checksum does not shows this behavior (broadly respect the performance differences, about 1.5x for i7 8700K and about 2.2x for 2600K)

Short version: BLAKE3 runs much faster (on Intel i7) against SHA256, but (a bit) slower on AMD 5950

Anyone have experience on this?
Thanks for any comments

i7 2600K
     SHA-256:   103.15 MB/s (done     1.01 GB)
      BLAKE3:   152.51 MB/s (done     1.49 GB) +1.48x
       SHA-1:   348.43 MB/s (done     3.40 GB)
    XXHASH64:     2.93 GB/s (done    29.30 GB)
        XXH3:     3.11 GB/s (done    31.02 GB)
     CRC-32C:     3.19 GB/s (done    31.89 GB)
      WYHASH:     3.88 GB/s (done    38.75 GB)
      CRC-32:     4.07 GB/s (done    40.63 GB)


i7 8700K
     SHA-256:   182.34 MB/s (done     1.78 GB) 
      BLAKE3:   273.32 MB/s (done     2.67 GB) +1.50x
       SHA-1:   608.21 MB/s (done     5.94 GB)
    XXHASH64:     4.22 GB/s (done    42.16 GB)
        XXH3:     4.43 GB/s (done    44.29 GB)
     CRC-32C:     4.82 GB/s (done    48.13 GB)
      WYHASH:     5.52 GB/s (done    55.16 GB)
      CRC-32:     5.70 GB/s (done    56.95 GB)

AMD 5950X
      BLAKE3:   280.84 MB/s (done     2.74 GB) 1.03x  1.84x -0.97%
     SHA-256:   288.54 MB/s (done     2.82 GB) 1.58x  2.80x
       SHA-1:   912.67 MB/s (done     8.91 GB) 1.50x  2.62x
    XXHASH64:     6.08 GB/s (done    60.67 GB) 1.44x  2.07x
        XXH3:     7.03 GB/s (done    70.19 GB) 1.59x  2.26x
     CRC-32C:     7.25 GB/s (done    72.41 GB) 1.50x  2.27x
      WYHASH:     8.63 GB/s (done    86.22 GB) 1.56x  2.22x
      CRC-32:     9.13 GB/s (done    91.17 GB) 1.60x  2.24x
Doing some test I find that the "straight" C (no asm, no SSE etc) implementation of BLAKE3 (in C) runs about 50% faster of SHA-256 on very rough benchmark, for older i7 and just old i7 (Windows 10). But on AMD 5950X runs 3% slower (of SHA-256), at least in my implementation. Others hash-checksum does not shows this behavior (broadly respect the performance differences, about 1.5x for i7 8700K and about 2.2x for 2600K) Short version: BLAKE3 runs much faster (on Intel i7) against SHA256, but (a bit) slower on AMD 5950 Anyone have experience on this? Thanks for any comments ``` i7 2600K SHA-256: 103.15 MB/s (done 1.01 GB) BLAKE3: 152.51 MB/s (done 1.49 GB) +1.48x SHA-1: 348.43 MB/s (done 3.40 GB) XXHASH64: 2.93 GB/s (done 29.30 GB) XXH3: 3.11 GB/s (done 31.02 GB) CRC-32C: 3.19 GB/s (done 31.89 GB) WYHASH: 3.88 GB/s (done 38.75 GB) CRC-32: 4.07 GB/s (done 40.63 GB) i7 8700K SHA-256: 182.34 MB/s (done 1.78 GB) BLAKE3: 273.32 MB/s (done 2.67 GB) +1.50x SHA-1: 608.21 MB/s (done 5.94 GB) XXHASH64: 4.22 GB/s (done 42.16 GB) XXH3: 4.43 GB/s (done 44.29 GB) CRC-32C: 4.82 GB/s (done 48.13 GB) WYHASH: 5.52 GB/s (done 55.16 GB) CRC-32: 5.70 GB/s (done 56.95 GB) AMD 5950X BLAKE3: 280.84 MB/s (done 2.74 GB) 1.03x 1.84x -0.97% SHA-256: 288.54 MB/s (done 2.82 GB) 1.58x 2.80x SHA-1: 912.67 MB/s (done 8.91 GB) 1.50x 2.62x XXHASH64: 6.08 GB/s (done 60.67 GB) 1.44x 2.07x XXH3: 7.03 GB/s (done 70.19 GB) 1.59x 2.26x CRC-32C: 7.25 GB/s (done 72.41 GB) 1.50x 2.27x WYHASH: 8.63 GB/s (done 86.22 GB) 1.56x 2.22x CRC-32: 9.13 GB/s (done 91.17 GB) 1.60x 2.24x ```
Cyan4973 commented 2021-08-02 09:15:24 -05:00 (Migrated from github.com)

Maybe SHA has been specifically optimized on AMD ?

Maybe `SHA` has been specifically optimized on AMD ?
fcorbelli commented 2021-08-02 09:45:27 -05:00 (Migrated from github.com)

In fact no.
SHA-1 have a rather "smart" implementation with a "cache", but nothing special.
SHA-256 is very straight C++ (in fact there are two SHA-256, the first in C very similar to SHA-1, the second in C++)

You can find here (with BLAKE3, of course)
https://github.com/fcorbelli/zpaqfranz/blob/main/zpaqfranz.cpp

In fact no. SHA-1 have a rather "smart" implementation with a "cache", but nothing special. SHA-256 is very straight C++ (in fact there are two SHA-256, the first in C very similar to SHA-1, the second in C++) You can find here (with BLAKE3, of course) https://github.com/fcorbelli/zpaqfranz/blob/main/zpaqfranz.cpp
Cyan4973 commented 2021-08-02 09:56:11 -05:00 (Migrated from github.com)

That's not what I meant.

When designing a general purpose CPU, engineers have to target a broad range of workloads in order to announce a certain IPC gain. Some workloads get more attention than others. For example, SPECint tends to get a lot of attention. The assumption here is that maybe AMD paid more attention to SHA, or rather to the sequence of instructions that is commonly found in SHA, and ensured their cpu was especially well optimized for this sequence.
This would be consistent SHA getting a x2.8 speed increase while all other algorithms have ~x2.2 or less.

I did not meant that AMD has a special instruction set for SHA, such a thing would bring at least an order of magnitude in speed improvement, but be extremely difficult to deploy, due to the specificity of the instruction set.

That's not what I meant. When designing a general purpose CPU, engineers have to target a broad range of workloads in order to announce a certain IPC gain. Some workloads get more attention than others. For example, SPECint tends to get _a lot_ of attention. The assumption here is that maybe AMD paid more attention to `SHA`, or rather to the sequence of instructions that is commonly found in `SHA`, and ensured their cpu was especially well optimized for this sequence. This would be consistent `SHA` getting a `x2.8` speed increase while all other algorithms have ~x2.2 or less. I did not meant that AMD has a special instruction set for `SHA`, such a thing would bring at least an order of magnitude in speed improvement, but be extremely difficult to deploy, due to the specificity of the instruction set.
fcorbelli commented 2021-08-02 10:07:33 -05:00 (Migrated from github.com)

Sure it is possible, but I think the difference is too great.

On Intel CPU, AND AMD, SHA-1 runs (about) 3 time faster than SHA-256
On Intel CPU, BLAKE3 runs (about) 50% faster than SHA-256
On AMD CPU, BLAKE3 runs (about) as fast as SHA-256

SHA-256 AND SHA-1 on AMD runs (~) 1.5x than older Intel SHA-256 and SHA-1
So the AMD chip is (very rough!) 1,5 times faster than Intel overall (on those CPU-bound algos).

BUT

why BLAKE3 on Intel runs just as fast as AMD (in absolute MB/s)?
AMD (running average ~1.5x faster then Intel) should achieve ~400MB/s (or whatever)

Others lighter algo (xxhash, xxh3, wyhash, even CRC-32) do not exhibit this behavior: the AMD chip is faster everywhere in absolute numbers.
Sometimes 1.4x, sometimes 1.6x, sometimes the RAM latency play a bigger role, sometimes the cache etc, it doesn't matter.

Before implementing BLAKE3 (stripped-C version) in my software all things was (about) as expected. In fact OR BLAKE3 (/the gcc compiler) "loves" Intel, or... "hates" AMD.
I have plenty of Intel CPU (mostly Xeons), but not others AMD to make more comparisons

Sure it is possible, but I think the difference is too great. On Intel CPU, **AND** AMD, SHA-1 runs (about) 3 time faster than SHA-256 On Intel CPU, BLAKE3 runs (about) 50% faster than SHA-256 On AMD CPU, BLAKE3 runs (about) as fast as SHA-256 SHA-256 AND SHA-1 on AMD runs (~) 1.5x than older Intel SHA-256 and SHA-1 So the AMD chip is (very rough!) 1,5 times faster than Intel overall (on those CPU-bound algos). **BUT** why BLAKE3 on Intel runs just as fast as AMD (in absolute MB/s)? AMD (running average ~1.5x faster then Intel) should achieve ~400MB/s (or whatever) Others lighter algo (xxhash, xxh3, wyhash, even CRC-32) do not exhibit this behavior: the AMD chip is faster everywhere in absolute numbers. Sometimes 1.4x, sometimes 1.6x, sometimes the RAM latency play a bigger role, sometimes the cache etc, it doesn't matter. Before implementing BLAKE3 (stripped-C version) in my software all things was (about) as expected. In fact OR BLAKE3 (/the gcc compiler) "loves" Intel, or... "hates" AMD. I have plenty of Intel CPU (mostly Xeons), but not others AMD to make more comparisons
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-Cyan4973/xxHash#546
No description provided.