feat(tensor): add TensorLayout enum and DN layout support#242
feat(tensor): add TensorLayout enum and DN layout support#242ChaoZheng109 wants to merge 1 commit intohw-native-sys:mainfrom
Conversation
Summary of ChangesHello, 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 a Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
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
|
There was a problem hiding this comment.
Code Review
This pull request introduces a TensorLayout enum to support different dimension mappings (ND and DN) for handling tensors with varied memory layouts. However, the implementation in the view() method contains a critical stack-based buffer overflow vulnerability due to a lack of bounds checking for ndims against the fixed-size reversed_offsets array. Additionally, the review includes a suggestion to correct a minor typo and a refactoring proposal for the view() method to enhance code readability and maintainability.
fc0f0a5 to
753f2fe
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a TensorLayout enum to support different memory layouts for tensors, specifically for row-major (ND) and a mixed-layout (DN) where the last two dimensions are column-major. While the changes correctly propagate the new layout property and update methods like view() and factory functions make_tensor_external and make_tensor, the implementation introduces several stack-based buffer overflows. These vulnerabilities arise because the code lacks validation for the number of dimensions (ndims) against the fixed-size arrays (RUNTIME_MAX_TENSOR_DIMS) in view, make_tensor_external, and make_tensor. Additionally, there's an opportunity to refactor duplicated and verbose code in the factory functions for improved maintainability and readability.
Add TensorLayout enum to distinguish row-major (ND) and column-major (DN) memory layouts. DN layout swaps the last two dimensions between logical (shapes) and physical (raw_shapes) storage. Changes: - Add TensorLayout enum (ND=row-major, DN=col-major for last 2 dims) - Add layout field to Tensor struct - Update constructors and factory functions to accept layout parameter - view(): auto-swap last 2 offset dimensions for DN layout - make_tensor/make_tensor_external: auto-swap last 2 raw_shapes dims for DN - Update documentation with DN layout examples DN invariant: layout=DN implies raw_shapes has last two dims swapped vs shapes Example: shapes=[M,N], layout=DN → raw_shapes=[N,M] (column-major)
753f2fe to
58c9e2f
Compare
Add TensorLayout enum to distinguish row-major (ND) and column-major (DN)
memory layouts. DN layout swaps the last two dimensions between logical
(shapes) and physical (raw_shapes) storage.
Changes:
DN invariant: layout=DN implies raw_shapes has last two dims swapped vs shapes
Example: shapes=[M,N], layout=DN → raw_shapes=[N,M] (column-major)