Offload safe mutable args with Region and PartitioningStrategy - #158076
Offload safe mutable args with Region and PartitioningStrategy#158076Sa4dUs wants to merge 3 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 comment has been minimized.
This comment has been minimized.
| } | ||
|
|
||
| /// 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
| /// # Safety | ||
| /// | ||
| /// Implementations must guarantee that generated views are disjoint. | ||
| #[unstable(feature = "offload", issue = "124509")] |
6a662ec to
400b615
Compare
|
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. |
|
Next round. I think we should actually refuse all cases (for now) where we have a Region within any ADT/struct/slice, etc. not just &Region. Most of them would be transfered incorrectly, and I don't think we gain much. The other direction is something like |
| where | ||
| Ty<'tcx>: TyAbiInterface<'tcx, C>, | ||
| { | ||
| if let Some(elem_ty) = region_element_ty(tcx, ty) { |
There was a problem hiding this comment.
I think this is only correct by default, not under -Zrandomize-layout, so you should either mark Region as repr(C), or properly look up the order. I'd to the later, just out of principle so we give fewer guarantees to the user.
| #[unstable(feature = "offload", issue = "131513")] | ||
| #[rustc_diagnostic_item = "offload_region"] | ||
| pub struct Region<'a, T, S: PartitioningStrategy> { | ||
| ptr: *mut T, |
There was a problem hiding this comment.
It should be safe to promise NonNull<T> here and below.
Now
Regionare lang items and mapped as slices.needs #156620 to workr? @ZuseZ4