Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AVX2 version of adler32 #2024

Merged
merged 7 commits into from
Feb 28, 2022
Merged

Add AVX2 version of adler32 #2024

merged 7 commits into from
Feb 28, 2022

Conversation

brianpopow
Copy link
Collaborator

Prerequisites

  • I have written a descriptive pull-request title
  • I have verified that there are no overlapping pull-requests open
  • I have verified that I am following the existing coding patterns and practice as demonstrated in the repository. These follow strict Stylecop rules 👮.
  • I have provided test coverage for my change (where applicable)

Description

This PR adds a AVX2 version of adler method.

Benchmark results:

BenchmarkDotNet=v0.13.1, OS=Windows 10.0.19043.1526 (21H1/May2021Update)
Intel Core i7-6700K CPU 4.00GHz (Skylake), 1 CPU, 8 logical and 4 physical cores
.NET SDK=6.0.200
  [Host]     : .NET 5.0.14 (5.0.1422.5710), X64 RyuJIT
  DefaultJob : .NET 5.0.14 (5.0.1422.5710), X64 RyuJIT


|      Method |       Mean |   Error |  StdDev |
|------------ |-----------:|--------:|--------:|
|    AdlerSse |   160.4 ns | 1.10 ns | 0.92 ns |
|    AdlerAvx |   109.6 ns | 0.52 ns | 0.49 ns |
| AdlerScalar | 1,557.8 ns | 4.71 ns | 4.40 ns |

@JimBobSquarePants
Copy link
Member

I kept meaning to migrate this across.

https://github.com/SixLabors/ZlibStream/blob/main/src/ZlibStream/Adler32.cs

Compression is currently broken in that repo (to a point I’m going to have to start again from the beginning of my fork and re-optimize with better tests) but Decompression works well and benchmarked faster at times than the runtime implementation. There’s some fast code in there.

@brianpopow
Copy link
Collaborator Author

I kept meaning to migrate this across.

https://github.com/SixLabors/ZlibStream/blob/main/src/ZlibStream/Adler32.cs

Compression is currently broken in that repo (to a point I’m going to have to start again from the beginning of my fork and re-optimize with better tests) but Decompression works well and benchmarked faster at times than the runtime implementation. There’s some fast code in there.

Ok, I was not aware of this. Will close this PR then.

@brianpopow brianpopow closed this Feb 21, 2022
@JimBobSquarePants
Copy link
Member

I’d still compare performance though. Your Adler might still be faster!

@brianpopow
Copy link
Collaborator Author

brianpopow commented Feb 22, 2022

I’d still compare performance though. Your Adler might still be faster!

The implementation from SixlaborsZlib is faster:

|      Method |        Mean |    Error |   StdDev |
|------------ |------------:|---------:|---------:|
|   AdlerSse2 |   167.95 ns | 1.974 ns | 1.750 ns |
|  AdlerSsse3 |    87.87 ns | 1.716 ns | 3.051 ns |
|    AdlerAvx |   111.50 ns | 0.761 ns | 0.712 ns |
| AdlerScalar | 1,566.36 ns | 5.335 ns | 4.730 ns |

AdlerSsse3 is the SixLabors/ZlibStream version.

After sleeping one night over it, I thought it might be still worth considering merging the AVX version of this PR to ImageSharp until we can make use of https://github.com/SixLabors/ZlibStream/blob/main/src/ZlibStream/Adler32.cs. I think it will take some time until we can make SixLabors/ZlibStream production ready. @JimBobSquarePants what do you think?

@JimBobSquarePants
Copy link
Member

I don’t know when I’ll get time to work exclusively on ZlibStream. It’s a minimum of a few weeks full time work to incrementally implement the optimisations again unless someone can spot the issue. So yeah, merge ahead if it’s easier to do so

@brianpopow
Copy link
Collaborator Author

Ok then I think reopening this again makes sense.

@brianpopow brianpopow reopened this Feb 22, 2022
Copy link
Member

@JimBobSquarePants JimBobSquarePants left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@brianpopow
Copy link
Collaborator Author

LGTM 👍

ok lets wait for this to be merged when 2.0.1 is done. I think only hotfixes should go into 2.0.1

src/ImageSharp/Compression/Zlib/Adler32.cs Outdated Show resolved Hide resolved
src/ImageSharp/Compression/Zlib/Adler32.cs Outdated Show resolved Hide resolved
@brianpopow
Copy link
Collaborator Author

@JimBobSquarePants since we are skipping 2.0.1, this can now also get merged into the main branch, right?

@JimBobSquarePants
Copy link
Member

Yeah, merge away 👍

@brianpopow brianpopow merged commit 47a759e into main Feb 28, 2022
@brianpopow brianpopow deleted the bp/adleravx branch February 28, 2022 21:59
@brianpopow
Copy link
Collaborator Author

I kept meaning to migrate this across.

https://github.com/SixLabors/ZlibStream/blob/main/src/ZlibStream/Adler32.cs

Compression is currently broken in that repo ...

@JimBobSquarePants: The tests in this repo seem to pass and there are encode tests. How did you notice its not working as it should?

@JimBobSquarePants
Copy link
Member

JimBobSquarePants commented Mar 31, 2022

Let me check my local copy and push failing tests. It’s definitely broken though and the tests are not adequate. Not related to adler though!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants