-
Notifications
You must be signed in to change notification settings - Fork 0
⚡ Thunderbolt: softmax_v6 — 8x Unrolling and FMA-optimized exp256 #77
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -332,6 +332,17 @@ class SoftmaxV5Benchmark : public SoftmaxBenchmark { | |
| }; | ||
| REGISTER_BENCHMARK(SoftmaxV5Benchmark); | ||
|
|
||
| class SoftmaxV6Benchmark : public SoftmaxBenchmark { | ||
| public: | ||
| const char *name() const override { return "softmax_v6"; } | ||
|
|
||
| void run() override { | ||
| ml_kernels::softmax_v6(inputs_[current_idx_].data(), outputs_[current_idx_].data(), inputs_[0].size()); | ||
| current_idx_ = (current_idx_ + 1) % pool_size_; | ||
| } | ||
| }; | ||
| REGISTER_BENCHMARK(SoftmaxV6Benchmark); | ||
|
Comment on lines
+335
to
+344
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Align benchmark verification with the This class inherits the base verifier's 🤖 Prompt for AI Agents |
||
|
|
||
| } // namespace | ||
|
|
||
| int main(int argc, char **argv) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -181,11 +181,46 @@ void test_softmax_v5() { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| std::cout << "test_softmax_v5 passed!" << std::endl; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| void test_softmax_v6() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| std::cout << "Running test_softmax_v6..." << std::endl; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Input size > 72 to cover 8x unrolled loop, 4x fallback, and 1x fallback | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| std::vector<float> input = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -2.0f, -0.5f, 1.0f, 3.0f, 0.0f, 0.0f, 0.0f, 0.0f, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100.0f, 100.0f, -100.0f, -100.0f, 5.0f, -5.0f, 2.0f, -2.0f, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1.1f, 1.2f, 1.3f, 1.4f, -1.1f, -1.2f, -1.3f, -1.4f, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10.0f, 20.0f, 30.0f, 40.0f, -10.0f, -20.0f, -30.0f, -40.0f, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.6f, 0.7f, 0.8f, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -0.1f, -0.2f, -0.3f, -0.4f, -0.5f, -0.6f, -0.7f, -0.8f, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -1.0f, -2.0f, -3.0f, -4.0f, -5.0f, -6.0f, -7.0f, -8.0f, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10.0f, 10.0f, 10.0f, 10.0f, 10.0f, 10.0f, 10.0f, 10.0f, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -10.0f, -10.0f | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+186
to
+200
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Exercise the 32-element fallback as claimed. This vector has 82 elements, so execution is Proposed fix- // Input size > 72 to cover 8x unrolled loop, 4x fallback, and 1x fallback
+ // 105 elements cover the 64, 32, 8, and scalar paths.
std::vector<float> input = {
...
};
+ input.resize(105, 0.0f);📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| std::vector<float> output_naive(input.size(), 0.0f); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| std::vector<float> output_v6(input.size(), 0.0f); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ml_kernels::softmax_naive(input.data(), output_naive.data(), input.size()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ml_kernels::softmax_v6(input.data(), output_v6.data(), input.size()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| float sum = 0.0f; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for (std::size_t i = 0; i < input.size(); ++i) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert(std::fabs(output_naive[i] - output_v6[i]) < 1e-4f); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sum += output_v6[i]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert(std::fabs(sum - 1.0f) < 1e-4f); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| std::cout << "test_softmax_v6 passed!" << std::endl; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| int main() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| test_relu_naive(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| test_max_naive(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| test_softmax_v3(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| test_softmax_v4(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| test_softmax_v5(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| test_softmax_v6(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| std::cout << "All tests passed successfully!" << std::endl; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Reconcile the conflicting benchmark figures.
The PR objective reports about 5.50 GFLOP/s at
N=16384in Fixed Memory mode, while this note claims 5.7–6.0. Align the result or document the differing command and environment.🤖 Prompt for AI Agents