Skip to content

Improve performance by fusing kernels - #57

Open
au2001 wants to merge 6 commits into
1inch:masterfrom
codesensus-org:perf/fuse-kernels-and-align
Open

Improve performance by fusing kernels#57
au2001 wants to merge 6 commits into
1inch:masterfrom
codesensus-org:perf/fuse-kernels-and-align

Conversation

@au2001

@au2001 au2001 commented Jul 26, 2026

Copy link
Copy Markdown

Change Summary

What does this PR change?

It improves performance by 8-12% with these compounding changes:

  • aligning mp_number to 2x 16 bytes instead of 8x 4 bytes; and
  • merging kernels for iterating/transforming/scoring into a single one

(profanity_inverse is untouched in this PR, so there are still 2 launches total, down from 3-4)

Testing & Verification

How was this tested?

  • Unit tests
  • Integration tests
  • Manual testing (describe steps)
  • Verified on staging

I ran the --leading 0 scoring method on different GPUs with the base and head codebase.
For each resulting address, I ran an external verification script which found no mistake.
Here are the results for "70" variant of each NVIDIA generation:

GPU VRAM base head inverse-multiple gain
RTX 5070 12 GB 787 MH/s 876 MH/s -I 393216 +11.3%
RTX 4070 12 GB 659 MH/s 712 MH/s -I 393216 +8.0%
RTX 3070 8 GB 487 MH/s 536 MH/s -I 262144 +10.1%
RTX 2070 8 GB 328 MH/s 359 MH/s -I 16384 +9.4%
GTX 1070 8 GB 201 MH/s 225 MH/s -I 196608 +12.2%

Edit: Previous results used --benchmark, for which the compiler optimized the kernel by deleting the keccak + scoring. A patch has been added to prevent this from happening.

Notes:
During benchmarks, when reaching speeds of 2-3ms per round, the millisecond clock precision was insufficient.
I thus bumped it to microseconds for increased accuracy.

A bug also prevented from enabling profiling: clCreateCommandQueueWithProperties on OpenCL 2.0+ expects a zero terminated list of name/value pairs, not a bitfield like 1.2 – 0 just so happened to be interpreted as an empty list.

Risk Assessment

Risk Level:

  • Low - Minor changes, no operational impact
  • Medium - Moderate changes, limited impact, standard rollback available
  • High - Significant changes, potential operational impact, complex rollback

Risks & Impact

Fully backwards-compatible with no user-facing changes.
But changes how the kernels work in a non-trivial way.
Requires clearing the cache to see changes (and to rollback).

Disclaimer: this PR was assisted by Claude Opus 5 for code exploration & benchmark scripts.
However, all code being submitted has been hand-written – and I'm a human :)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant