Offload safe mutable args with Region and PartitioningStrategy - #158076
Offload safe mutable args with Region and PartitioningStrategy#158076Sa4dUs wants to merge 2 commits into
Region and PartitioningStrategy#158076Conversation
This comment has been minimized.
This comment has been minimized.
c075a56 to
2a627bf
Compare
This comment has been minimized.
This comment has been minimized.
Region and PartitioningStrategy
This comment has been minimized.
This comment has been minimized.
|
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)] |
There was a problem hiding this comment.
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
| [1, 1, 1], | ||
| [1, 1, 1], | ||
| 0, | ||
| (Region::<f32, Dummy>::new(&mut x as &mut [f32]),), |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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")] |
Now
Regionare lang items and mapped as slices.needs #156620 to workr? @ZuseZ4