Perf: Use typed memoryviews in sqrtsolve (10 to 20% speedup)#11
Open
jberg5 wants to merge 2 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Typed memoryviews are a nifty cython feature that let you pinky promise the compiler that your arrays have a particular layout in memory, unlocking vectorization: https://cython.readthedocs.io/en/latest/src/userguide/memoryviews.html#typed-memoryviews.
We can achieve a 10-20% speedup this way (hardware dependent, as always), which should stack on #8.
Also made a related change to pull the np.empty()s out of the loop, and just allocate a reusable workspace that's big enough once.
I asked Claude to walk through the step by step, which is great because otherwise I am not fluent in NEON assembly:
Some numbers (kernel-level speedup on cython_block_sqrtsolve_rank1)
Normally I try to minimize noisy neighbors on my macbook, but today I had other stuff running and didn't bother turning it off, so take the M3 results with a grain of salt.
Apple M3 Pro / Accelerate / clang 17
Intel Cascade Lake / OpenBLAS / gcc 12.2 (GCP
c2-standard-4)Intel Emerald Rapids (Xeon Platinum 8581C) / OpenBLAS / gcc 12.2 (GCP
c4-standard-8)AMD EPYC 7B13 (Zen3) / OpenBLAS / gcc 12.2 (GCP
c2d-standard-8)Confirmed results are bitwise identical.