-
Notifications
You must be signed in to change notification settings - Fork 1
feat: implement SAXPY kernel #4
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?
Conversation
add saxpy (y = a*x + y) with bounds check update host for scalar a and vectors x, y update readme with saxpy example
Summary of ChangesHello @bniladridas, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces the SAXPY (Single-precision A*X + Y) operation as a Metal compute kernel, significantly enhancing the project's capability for parallelized linear algebra on Apple Silicon GPUs. The change moves from a basic vector addition to a more versatile and widely used mathematical function, with corresponding updates to the host application and documentation to demonstrate its usage and benefits. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
|
✅ SPDX check passed — all changed files include the required license header. |
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.
Code Review
This pull request successfully implements the SAXPY (Y = a*X + Y) compute kernel, replacing the previous vector addition functionality. The changes are well-contained, updating the Metal kernel, the Swift host code, and the README. My main feedback is to remove some leftover content from the previous implementation in the README and to consider an optimization in the Swift host code by not embedding the Metal shader as a string, which will improve maintainability.
| Elapsed (s): 0.001 | ||
| Sample results: |
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.
| let source = """ | ||
| #include <metal_stdlib> | ||
| using namespace metal; | ||
| kernel void vector_add( | ||
| device const float* A [[buffer(0)]], | ||
| device const float* B [[buffer(1)]], | ||
| device float* C [[buffer(2)]], | ||
| kernel void saxpy( | ||
| constant float &a [[buffer(0)]], | ||
| device const float* X [[buffer(1)]], | ||
| device float* Y [[buffer(2)]], | ||
| constant uint &count [[buffer(3)]], | ||
| uint id [[thread_position_in_grid]] | ||
| ) { | ||
| if (id >= count) return; | ||
| C[id] = A[id] + B[id]; | ||
| Y[id] = a * X[id] + Y[id]; | ||
| } | ||
| """ |
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.
Embedding the Metal shader source code directly as a string inside the Swift file can make it harder to maintain, especially as the kernel gets more complex. It also misses out on features like syntax highlighting and static analysis in an IDE. It's better practice to keep the Metal code in its own .metal file and load it at runtime. This also aligns with how kernel.metal is already present in the repository.
Description
Implement SAXPY (Single-precision A*X + Y) compute kernel with bounds check, optimal dispatch sizing, and timing measurement. Update host code for scalar a and vectors X, Y. Update README with SAXPY example and output. Merged test-spdx-bot branch for latest SPDX compliance fixes.
Type of Change
Checklist
swiftc main.swift -framework Metal -o saxpyxcrun metal kernel.metalScreenshots (if applicable)
N/A - Kernel execution verified locally.