-
Notifications
You must be signed in to change notification settings - Fork 18
[SPH] reduce alloc in ghost zone find #1465
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 |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| // -------------------------------------------------------// | ||
| // | ||
| // SHAMROCK code for hydrodynamics | ||
| // Copyright (c) 2021-2025 Timothée David--Cléris <tim.shamrock@proton.me> | ||
| // SPDX-License-Identifier: CeCILL Free Software License Agreement v2.1 | ||
| // Shamrock is licensed under the CeCILL 2.1 License, see LICENSE for more information | ||
| // | ||
| // -------------------------------------------------------// | ||
|
|
||
| #pragma once | ||
|
|
||
| /** | ||
| * @file sort_by_keys.hpp | ||
| * @author Timothée David--Cléris (tim.shamrock@proton.me) | ||
| * @brief Sort by keys algorithms | ||
| * | ||
| */ | ||
|
|
||
| #include "shambackends/DeviceBuffer.hpp" | ||
|
|
||
| namespace shamalgs::primitives { | ||
|
|
||
| sham::DeviceBuffer<u32> stream_compact( | ||
| const sham::DeviceScheduler_ptr &sched, sham::DeviceBuffer<u32> && buf_flags, u32 len); | ||
|
|
||
| } // namespace shamalgs::primitives | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,59 @@ | ||||||||||||||
| // -------------------------------------------------------// | ||||||||||||||
| // | ||||||||||||||
| // SHAMROCK code for hydrodynamics | ||||||||||||||
| // Copyright (c) 2021-2025 Timothée David--Cléris <tim.shamrock@proton.me> | ||||||||||||||
| // SPDX-License-Identifier: CeCILL Free Software License Agreement v2.1 | ||||||||||||||
| // Shamrock is licensed under the CeCILL 2.1 License, see LICENSE for more information | ||||||||||||||
| // | ||||||||||||||
| // -------------------------------------------------------// | ||||||||||||||
|
|
||||||||||||||
| /** | ||||||||||||||
| * @file sort_by_keys.hpp | ||||||||||||||
| * @author Timothée David--Cléris (tim.shamrock@proton.me) | ||||||||||||||
| * @brief Sort by keys algorithms | ||||||||||||||
|
Comment on lines
+11
to
+13
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. The documentation in this file header seems to be copied from
Suggested change
|
||||||||||||||
| * | ||||||||||||||
| */ | ||||||||||||||
|
|
||||||||||||||
| #include "shamalgs/primitives/stream_compact.hpp" | ||||||||||||||
| #include "shamalgs/primitives/scan_exclusive_sum_in_place.hpp" | ||||||||||||||
| #include "shambackends/DeviceBuffer.hpp" | ||||||||||||||
| #include "shambackends/kernel_call.hpp" | ||||||||||||||
|
|
||||||||||||||
| namespace shamalgs::primitives { | ||||||||||||||
|
|
||||||||||||||
| sham::DeviceBuffer<u32> stream_compact( | ||||||||||||||
| const sham::DeviceScheduler_ptr &sched, sham::DeviceBuffer<u32> &&buf_flags, u32 len) { | ||||||||||||||
|
|
||||||||||||||
| if (buf_flags.get_size() < len + 1) | ||||||||||||||
| shambase::throw_with_loc<std::invalid_argument>(shambase::format( | ||||||||||||||
| "buf_flags.get_size() < len+1\n buf_flags.get_size() = {}, len = {}", | ||||||||||||||
| buf_flags.get_size(), | ||||||||||||||
| len)); | ||||||||||||||
|
|
||||||||||||||
| shamalgs::primitives::scan_exclusive_sum_in_place(buf_flags, len + 1); | ||||||||||||||
|
|
||||||||||||||
| u32 new_len = buf_flags.get_val_at_idx(len); | ||||||||||||||
|
|
||||||||||||||
| sham::DeviceBuffer<u32> index_map(new_len, sched); | ||||||||||||||
|
|
||||||||||||||
| if (new_len > 0) { | ||||||||||||||
| sham::kernel_call( | ||||||||||||||
| sched->get_queue(), | ||||||||||||||
| sham::MultiRef{buf_flags}, | ||||||||||||||
| sham::MultiRef{index_map}, | ||||||||||||||
| len + 1, | ||||||||||||||
|
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. The kernel is launched with The kernel is intended to process
Suggested change
|
||||||||||||||
| [](u32 idx, const u32 *sum_vals, u32 *new_idx) { | ||||||||||||||
| u32 current_val = sum_vals[idx]; | ||||||||||||||
|
|
||||||||||||||
| bool should_write = (current_val < sum_vals[idx + 1]); | ||||||||||||||
|
|
||||||||||||||
| if (should_write) { | ||||||||||||||
| new_idx[current_val] = idx; | ||||||||||||||
| } | ||||||||||||||
| }); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| return index_map; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| } // namespace shamalgs::primitives | ||||||||||||||
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.
The documentation in this file header appears to be copied from
sort_by_keys.hpp. Please update it to accurately describe the contents ofstream_compact.hppand thestream_compactfunction.