Skip to content

Offload safe mutable args with Region and PartitioningStrategy - #158076

Open
Sa4dUs wants to merge 2 commits into
rust-lang:mainfrom
Sa4dUs:offload-region
Open

Offload safe mutable args with Region and PartitioningStrategy#158076
Sa4dUs wants to merge 2 commits into
rust-lang:mainfrom
Sa4dUs:offload-region

Conversation

@Sa4dUs

@Sa4dUs Sa4dUs commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Now Region are lang items and mapped as slices.
needs #156620 to work

r? @ZuseZ4

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jun 18, 2026
@rust-log-analyzer

This comment has been minimized.

@Sa4dUs
Sa4dUs force-pushed the offload-region branch 2 times, most recently from c075a56 to 2a627bf Compare August 13, 2026 14:05
@rust-log-analyzer

This comment has been minimized.

@Sa4dUs Sa4dUs changed the title offload region Offload safe mutable args with Region and PartitioningStrategy Aug 13, 2026
@Sa4dUs
Sa4dUs marked this pull request as ready for review August 13, 2026 16:21
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 13, 2026
@rust-bors

This comment has been minimized.

@rustbot

rustbot commented Aug 14, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

}

/// A memory region bound to a partitioning strategy.
#[derive(Copy, Clone, Debug)]

@ZuseZ4 ZuseZ4 Sep 2, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think copy/clone are sound here. After all we intentionally made the members private to prevent this:

#[offload_kernel]
   fn k(mut a: Region<f32, Linear1D>) {
       let mut b = a;                                   // Copy
       if let (Some(x), Some(y)) = (a.get_mut(), b.get_mut()) { *x = 1.0; *y = 2.0; }  // two live &mut f32 to the same element
   }

We also don't really need or use them that way anywhere. Can you drop them and add a test to make sure it doesn't compile?
For convenience you can instead probably add something like
fn reborrow(&mut self) -> Region<'_, T, S> to reuse it accross launches

View changes since the review

[1, 1, 1],
[1, 1, 1],
0,
(Region::<f32, Dummy>::new(&mut x as &mut [f32]),),

@ZuseZ4 ZuseZ4 Sep 2, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you add a test for when we try to pass &Region? I think I did that accidentally when writing some of our benchmarks and iirc it didn't get caught anywhere but resulted in a buggy runtime.
A tuple element isn't a location where Rust auto-dereferences, and I don't think there's value in teaching our mapper to look through &Region, so we should just nudge users to pass it by value by rejecting this.

View changes since the review

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also, can you add a test to show that the borrowchecker rejects writing into x here while the Region is alive? Similar to the preload test here (which I need to clean up too) main...ZuseZ4:rust:offload-explicit-datatransfer3#diff-f828186e6b7ed6e21e5a04161c08c8aa3d03f107a62d728e516c5741b6d6a21a

/// # Safety
///
/// Implementations must guarantee that generated views are disjoint.
#[unstable(feature = "offload", issue = "124509")]

@ZuseZ4 ZuseZ4 Sep 2, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

lol

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

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants