Skip to content

Conversation

@tdavidcl
Copy link
Member

No description provided.

@github-actions
Copy link

Thanks @tdavidcl for opening this PR!

You can do multiple things directly here:
1 - Comment pre-commit.ci run to run pre-commit checks.
2 - Comment pre-commit.ci autofix to apply fixes.
3 - Add label autofix.ci to fix authorship & pre-commit for every commit made.
4 - Add label light-ci to only trigger a reduced & faster version of the CI (need the full one before merge).
5 - Add label trigger-ci to create an empty commit to trigger the CI.

Once the workflow completes a message will appear displaying informations related to the run.

Also the PR gets automatically reviewed by gemini, you can:
1 - Comment /gemini review to trigger a review
2 - Comment /gemini summary for a summary
3 - Tag it using @gemini-code-assist either in the PR or in review comments on files

@gemini-code-assist
Copy link

Summary of Changes

Hello @tdavidcl, 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 new stream_compact primitive algorithm and integrates it into the SPH ghost zone finding mechanism. The primary goal is to optimize memory allocation and potentially improve performance within the BasicSPHGhosts module by replacing a combined filtering and indexing operation with a more granular approach involving a mask generation followed by stream compaction.

Highlights

  • New Primitive: stream_compact: A new device-side primitive for stream compaction has been introduced. This primitive efficiently filters elements based on a flag buffer, returning a new buffer containing the indices of the selected elements.
  • Refactored Ghost Zone Finding: The gen_id_table_interfaces function within BasicSPHGhosts.cpp has been refactored to leverage the newly added stream_compact primitive. This change replaces a combined filtering and indexing operation with a more granular, two-step process.
  • Reduced Memory Allocations: The primary goal of this refactoring is to reduce memory allocations during the ghost zone finding process. By separating the masking and compaction steps, the new approach is expected to be more memory-efficient and potentially improve performance.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions
Copy link

Workflow report

workflow report corresponding to commit 0dc5d22
Commiter email is timothee.davidcleris@proton.me

Light CI is enabled. This will only run the basic tests and not the full tests.
Merging a PR require the job "on PR / all" to pass which is disabled in this case.

Pre-commit check report

Some failures were detected in base source checks checks.
Check the On PR / Linting / Base source checks (pull_request) job in the tests for more detailled output

❌ Check doxygen headers

The pre-commit checks have found some files without or with a wrong doxygen file header

A properly formed doxygen header should be like and placed just below #pragma once in headers or below the license in source files:

/**
 * @file <filename>
 * @author <Author name> (<email>)
 * @brief <Description of the file content>
 *
 */

This test is triggered if the doxygen header is missing or with the wrong file name

At some point we will refer to a guide in the doc about this

List of files with errors :

  • /src/shamalgs/include/shamalgs/primitives/stream_compact.hpp
  • /src/shamalgs/src/primitives/stream_compact.cpp

Suggested changes

Detailed changes :
diff --git a/src/shamalgs/include/shamalgs/primitives/stream_compact.hpp b/src/shamalgs/include/shamalgs/primitives/stream_compact.hpp
index b0814898..7d779e62 100644
--- a/src/shamalgs/include/shamalgs/primitives/stream_compact.hpp
+++ b/src/shamalgs/include/shamalgs/primitives/stream_compact.hpp
@@ -10,7 +10,7 @@
 #pragma once
 
 /**
- * @file sort_by_keys.hpp
+ * @file stream_compact.hpp
  * @author Timothée David--Cléris (tim.shamrock@proton.me)
  * @brief Sort by keys algorithms
  *
@@ -21,6 +21,6 @@
 namespace shamalgs::primitives {
 
     sham::DeviceBuffer<u32> stream_compact(
-        const sham::DeviceScheduler_ptr &sched, sham::DeviceBuffer<u32> && buf_flags, u32 len);
+        const sham::DeviceScheduler_ptr &sched, sham::DeviceBuffer<u32> &&buf_flags, u32 len);
 
 } // namespace shamalgs::primitives
diff --git a/src/shamalgs/src/primitives/stream_compact.cpp b/src/shamalgs/src/primitives/stream_compact.cpp
index a3b39d6e..e2e13f28 100644
--- a/src/shamalgs/src/primitives/stream_compact.cpp
+++ b/src/shamalgs/src/primitives/stream_compact.cpp
@@ -8,7 +8,7 @@
 // -------------------------------------------------------//
 
 /**
- * @file sort_by_keys.hpp
+ * @file stream_compact.cpp
  * @author Timothée David--Cléris (tim.shamrock@proton.me)
  * @brief Sort by keys algorithms
  *

Copy link

@gemini-code-assist gemini-code-assist bot left a 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 refactors the ghost zone finding logic to improve performance by restructuring kernel launches. A new stream_compact primitive is introduced. The changes in BasicSPHGhosts.cpp batch the mask generation kernels, which is a good optimization pattern for GPUs.

My review has identified a critical out-of-bounds memory access in the new stream_compact implementation, which needs to be fixed. I've also found some minor documentation issues (copy-paste errors) in the new files. Please see the detailed comments.

sched->get_queue(),
sham::MultiRef{buf_flags},
sham::MultiRef{index_map},
len + 1,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The kernel is launched with len + 1 work items, which can lead to an out-of-bounds memory access. The loop variable idx will range from 0 to len. When idx is len, the expression sum_vals[idx + 1] on line 48 will attempt to access sum_vals[len + 1]. However, buf_flags (which sum_vals points to) is guaranteed to have a size of at least len + 1, meaning valid indices are from 0 to len. Accessing index len + 1 is out of bounds.

The kernel is intended to process len flags, so it should be launched with len work items. This will make idx range from 0 to len - 1, and the maximum index accessed will be sum_vals[len], which is within the buffer's bounds.

Suggested change
len + 1,
len,

Comment on lines +13 to +15
* @file sort_by_keys.hpp
* @author Timothée David--Cléris (tim.shamrock@proton.me)
* @brief Sort by keys algorithms

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The documentation in this file header appears to be copied from sort_by_keys.hpp. Please update it to accurately describe the contents of stream_compact.hpp and the stream_compact function.

 * @file stream_compact.hpp
 * @author Timothée David--Cléris (tim.shamrock@proton.me)
 * @brief Stream compaction primitive

Comment on lines +11 to +13
* @file sort_by_keys.hpp
* @author Timothée David--Cléris (tim.shamrock@proton.me)
* @brief Sort by keys algorithms

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The documentation in this file header seems to be copied from sort_by_keys.hpp. Please update it to describe the stream_compact implementation in this file.

Suggested change
* @file sort_by_keys.hpp
* @author Timothée David--Cléris (tim.shamrock@proton.me)
* @brief Sort by keys algorithms
* @file stream_compact.cpp
* @author Timothée David--Cléris (tim.shamrock@proton.me)
* @brief Implementation of the stream compaction primitive

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant