-
Notifications
You must be signed in to change notification settings - Fork 0
⚡ Thunderbolt: softmax_v6 — 8x unrolled Max and Normalization passes #89
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -181,11 +181,48 @@ 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 must be > 64 elements to test 8x unrolled loop (64 elements) + boundary/remainder loops. | ||||||
| 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.9f, 1.0f, 1.1f, 1.2f, 1.3f, 1.4f, 1.5f, 1.6f, | ||||||
| -0.1f, -0.2f, -0.3f, -0.4f, -0.5f, -0.6f, -0.7f, -0.8f, | ||||||
| -0.9f, -1.0f, -1.1f, -1.2f, -1.3f, -1.4f, -1.5f, -1.6f, | ||||||
| 0.01f, 0.02f, 0.03f, 0.04f, 0.05f, 0.06f, 0.07f, 0.08f // 72 elements total | ||||||
| }; | ||||||
|
|
||||||
| 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(); | ||||||
|
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. 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win Use 4-space indentation. Line 226 has 8 leading spaces. Align this call with the other calls in Proposed fix- test_softmax_v6();
+ test_softmax_v6();As per coding guidelines, "Use 4-space indentation." 📝 Committable suggestion
Suggested change
🤖 Prompt for AI AgentsSource: Coding guidelines |
||||||
| 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
Move function opening braces to their own lines.
ml_kernels/include/ml_kernels/softmax.h#L510-L510: Place thesoftmax_v6opening brace on the next line.ml_kernels/src/kernel_bench.cpp#L339-L339: Place theSoftmaxV6Benchmark::runopening brace on the next line.ml_kernels/src/test_naive_ops.cpp#L185-L185: Place thetest_softmax_v6opening brace on the next line.ml_kernels/src/test_naive_ops.cpp#L220-L220: Place themainopening brace on the next line.As per coding guidelines, "Keep braces on their own lines for function bodies."
📍 Affects 3 files
ml_kernels/include/ml_kernels/softmax.h#L510-L510(this comment)ml_kernels/src/kernel_bench.cpp#L339-L339ml_kernels/src/test_naive_ops.cpp#L185-L185ml_kernels/src/test_naive_ops.cpp#L220-L220🤖 Prompt for AI Agents
Source: Coding guidelines