-
Notifications
You must be signed in to change notification settings - Fork 0
⚡ Thunderbolt: softmax_v6 — FMA-fused exp range reduction and 8x max unroll #37
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_; | ||
| } | ||
| }; | ||
|
Comment on lines
+335
to
+343
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. 🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win Update new benchmark methods to the mandated brace style. The new class methods use same-line opening braces; please move function-body braces to their own lines for consistency with project C/C++ rules. As per coding guidelines, "Keep braces on their own lines for function bodies". 🤖 Prompt for AI Agents |
||
| REGISTER_BENCHMARK(SoftmaxV6Benchmark); | ||
|
|
||
| } // namespace | ||
|
|
||
| int main(int argc, char **argv) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -152,6 +152,28 @@ void test_softmax_v4() { | |
| std::cout << "test_softmax_v4 passed!" << std::endl; | ||
| } | ||
|
|
||
| void test_softmax_v6() { | ||
| std::cout << "Running test_softmax_v6..." << std::endl; | ||
| for (std::size_t n : {1, 2, 7, 8, 15, 16, 31, 32, 63, 64, 100}) { | ||
| std::vector<float> input(n); | ||
| for (std::size_t i = 0; i < n; ++i) input[i] = static_cast<float>(i); | ||
|
|
||
| std::vector<float> output_ref(n); | ||
| ml_kernels::softmax_naive(input.data(), output_ref.data(), n); | ||
|
|
||
| std::vector<float> output(n, 0.0f); | ||
| ml_kernels::softmax_v6(input.data(), output.data(), n); | ||
|
|
||
| for (std::size_t i = 0; i < n; ++i) { | ||
| if (std::abs(output[i] - output_ref[i]) > 1e-4f) { | ||
| std::cerr << "Mismatch at " << i << ": " << output[i] << " vs " << output_ref[i] << std::endl; | ||
| assert(false); | ||
| } | ||
| } | ||
| } | ||
| std::cout << "test_softmax_v6 passed!" << std::endl; | ||
| } | ||
|
Comment on lines
+155
to
+175
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. 🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win Use required function brace style in the new test function. Please move the opening brace for As per coding guidelines, "Keep braces on their own lines for function bodies". 🤖 Prompt for AI Agents |
||
|
|
||
| void test_softmax_v5() { | ||
| std::cout << "Running test_softmax_v5..." << std::endl; | ||
| std::vector<float> input = { | ||
|
|
@@ -187,5 +209,6 @@ int main() { | |
| 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.
🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win
Align new function definitions with brace-placement rule.
New function bodies place
{on the same line as the signature; this file’s C/C++ style requires function braces on their own lines.As per coding guidelines, "Keep braces on their own lines for function bodies".
Also applies to: 541-541
🤖 Prompt for AI Agents