⚡ Thunderbolt: Softmax — 8x unroll and single-FMA exp approximation#70
⚡ Thunderbolt: Softmax — 8x unroll and single-FMA exp approximation#70bugparty wants to merge 1 commit into
Conversation
Co-authored-by: bugparty <1510776+bugparty@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
📝 WalkthroughWalkthroughAdds a new AVX2 exponential approximation function ChangesSoftmax v6 Kernel Implementation
Estimated code review effort: 3 (Moderate) | ~25 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
ml_kernels/include/ml_kernels/softmax.h (1)
510-510: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueBrace placement deviates from the repo style guideline.
exp256_ps_v3andsoftmax_v6open the function body brace on the declaration line. The guideline requires the opening brace on its own line for function bodies. This matches the surrounding file's existing style, so treat as optional.As per coding guidelines: "Keep braces on their own lines for function bodies".
Also applies to: 540-540
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@ml_kernels/include/ml_kernels/softmax.h` at line 510, The function body braces in exp256_ps_v3 and softmax_v6 should follow the repo’s brace style by placing the opening brace on its own line instead of on the declaration line. Update the function declarations for these symbols so the body starts with a standalone brace, matching the surrounding style in softmax.h and the coding guideline for function bodies.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@ml_kernels/include/ml_kernels/softmax.h`:
- Line 510: The function body braces in exp256_ps_v3 and softmax_v6 should
follow the repo’s brace style by placing the opening brace on its own line
instead of on the declaration line. Update the function declarations for these
symbols so the body starts with a standalone brace, matching the surrounding
style in softmax.h and the coding guideline for function bodies.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: b5e1a571-da4a-4e15-ac11-2c5da4493ee5
📒 Files selected for processing (4)
.jules/thunderbolt.mdml_kernels/include/ml_kernels/softmax.hml_kernels/src/kernel_bench.cppml_kernels/src/test_naive_ops.cpp
💡 What:
Implemented
softmax_v6, a highly optimized AVX2 SIMD kernel that computes softmax. It replaces the exact two-FMA constant representation ofx - n * ln(2)with a single fused-multiply-add using combined constants, and aggressively unrolls the main processing loops 8x instead of 4x.🎯 Why:
In shift-invariant operations like Softmax, transcendental accuracy bounds on
exp256_psare significantly less sensitive to intermediate precision variations (since input elements are shifted bymax_valto avoid overflow). This allows combining the range reduction constants into a single FMA to reduce instruction count and relieve execution port pressure. The remaining FMA latency bottleneck is hidden by scaling up to an 8x unroll scheme (using 8 independent accumulators/horner chains).🏗️ How:
exp256_ps_v3combiningn * ln(2)constants into a single_mm256_fnmadd_ps.softmax_v6performing 64 elements (8 YMM registers) per iteration.📊 Impact:
softmax_v5(4x unroll): ~5.70 GFLOP/s at N=65536softmax_v6(8x unroll + 1-FMA): ~6.29 GFLOP/s at N=65536🖥️ Tested on:
x86_64 CPU (AVX2), GCC 13.3.0, Ubuntu 24.04 Docker Environment
🔬 How to reproduce:
PR created automatically by Jules for task 7445448542612547065 started by @bugparty
Summary by CodeRabbit
New Features
Bug Fixes
Tests
Chores