-
Notifications
You must be signed in to change notification settings - Fork 419
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add/improve errors for
.localAccess()
calls to non-local elements (#…
…25754) [reviewed by @e-kayrakli ] This PR adds and improves errors for `.localAccess()` calls that access remote elements. The original motivation for the PR was to fix the case noted in issue #25747 in which `.localAccess()` on a default rectangular array would always pass, whether that array was stored locally or on a remote locale (captured in `test/arrays/locality/localAccess/localAccess.chpl`). It also improves the error message for `.localAccess()` violations on block arrays by expressing the error as a locality error rather than a simple out-of-bounds error, as before (also reported in #25747, captured in `test/arrays/locality/localAccess/localAccess-block*.chpl`). These new tests make sure that these errors are generated for read and write cases as well as for POD vs. non-POD arrays, since our modules have distinct dsiAccess overloads for these cases. The check itself is implemented as an additional/optional check in `checkAccess()` which is called for all array accesses when checking is on. It now takes an optional `ensureLocal` param that is false by default, but set to true for all `.localAccess()` code paths to enable the bounds checking. The logic itself generates different error messages depending on whether the array is completely local to a single (remote) locale, distributed but the current locale owns nothing, or distributed but the index is outside the current locale's bounds. The implementation approach I originally pursued to determine whether an access was in-bounds was to use the array's `localSubdomains()` call to check that the localAccess's indices were in-bounds. However, this caused problems for the Stencil distribution since its localSubdomain(s) (correctly) only refer to the indices that the locale truly owns, but not ones that are part of its "fluff" (cached ghost cells). Yet, we also want that fluff to be accessible using localAccess() since that's how we get performance when the compiler can't optimize them automatically, requiring a slightly more sophisticated approach described in the next paragraph. New test `test/distributions/stencil/localAccess.chpl` locks in a very simple case of this Stencil distribution pattern, with some accesses passing due to true ownership, some due to fluff ownership, and one generating an error due to a remote access. The Stencil distribution challenge led to the approach taken here, which is to introduce a new internal iterator called `chpl__localStoredSubdomains` whose purpose is to yield a locale's subdomains, including indices that it doesn't truly own, like the fluff of the stencil distribution. This is implemented using an optional call on the array, `doiLocalStoredSubdomains()`, and if not supported, we fall back to using the `localSubdomains()` call instead. I then implemented `doiLocalStoredSubdomains()` on Stencil distributions. Along the way, I found that `dsiLocalSubdomains()` calls weren't implemented for Block, Cyclic, and Stencil, so added those as well. Then, while testing this, I found that our current tests that lock in support for using oversubscribed block/cyclic/stencil distributions (that is, ones in which a single locale appears in targetLocales multiple times) were getting away with using `.localAccess()` to access elements that weren't actually local, so I updated them to only update local array elements. The reason for this is that the `dsiAccess()` routine on these distributions simply falls back to a normal `dsiAccess()` in the event of oversubscription—meaning that we're also losing some performance there in addition to not actually doing a local access... I also found that the stencil variant of this test was never set up to run with multiple locales, so updated it to do so. Note that much of the code in this effort may not be optimal performance-wise (e.g., iterating over local subdomains when the common case is that a locale only has a single subdomain), but that this seemed acceptable—at least for the time being—since this code is only called when checks are on. Two bad files `test/expressions/if-expr/*.bad` had to be updated due to shifting IDs in the AST… :( Resolves #25747.
- Loading branch information
Showing
39 changed files
with
321 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
CHPL_COMM==none | ||
COMPOPTS <= --no-local |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-sPOD=true --checks | ||
-sPOD=false --checks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use BlockDist; | ||
config param POD = true; | ||
config const read = true; | ||
|
||
var Arr = createArray(); | ||
|
||
on Locales[numLocales-1] { | ||
local { if read then writeln(Arr.localAccess[0]); else Arr.localAccess[0] += 1; } | ||
} | ||
|
||
proc createArray() { | ||
const D = {0..2} dmapped new blockDist({0..99}); | ||
var A: [D] if POD then int else R; | ||
if POD then | ||
A = [1, 2, 3]; | ||
else | ||
A = [new R(1), new R(2), new R(3)]; | ||
return A; | ||
} | ||
|
||
record R { | ||
var x: int; | ||
|
||
operator +(ref lhs: R, rhs: int) { | ||
lhs.x += rhs; | ||
return lhs; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--read=true | ||
--read=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
localAccess-block.chpl:8: error: halt reached - Call to .localAccess() from locale 1 is illegal because it has no local array elements |
29 changes: 29 additions & 0 deletions
29
test/arrays/locality/localAccess/localAccess-block2-2D.chpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use BlockDist; | ||
config param POD = true; | ||
config const read = true; | ||
|
||
var Arr = createArray(); | ||
|
||
on Locales[numLocales-1] { | ||
local { if read then writeln(Arr.localAccess[0,0]); else Arr.localAccess[0,0] += 1; } | ||
} | ||
|
||
proc createArray() { | ||
const D = {0..99 by 50, 0..99 by 50} dmapped new blockDist({0..99, 0..99}); | ||
var A: [D] if POD then int else R; | ||
if POD then | ||
A = reshape([1, 2, 3, 4], A.domain); | ||
else | ||
A = reshape([new R(1), new R(2), new R(3), new R(4)], A.domain); | ||
return A; | ||
} | ||
|
||
record R { | ||
var x: int; | ||
|
||
operator +(ref lhs: R, rhs: int) { | ||
lhs.x += rhs; | ||
return lhs; | ||
} | ||
} | ||
|
2 changes: 2 additions & 0 deletions
2
test/arrays/locality/localAccess/localAccess-block2-2D.execopts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--read=true | ||
--read=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
localAccess-block2-2D.chpl:8: error: halt reached - Call to .localAccess(0, 0) from locale 1 refers to remote data (local indices are: {50..99 by 50, 0..99 by 50}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use BlockDist; | ||
config param POD = true; | ||
config const read = true; | ||
|
||
var Arr = createArray(); | ||
|
||
on Locales[numLocales-1] { | ||
local { if read then writeln(Arr.localAccess[0]); else Arr.localAccess[0] += 1;} | ||
} | ||
|
||
proc createArray() { | ||
const D = {0..99 by 34} dmapped new blockDist({0..99}); | ||
var A: [D] if POD then int else R; | ||
if POD then | ||
A = [1, 2, 3]; | ||
else | ||
A = [new R(1), new R(2), new R(3)]; | ||
return A; | ||
} | ||
|
||
record R { | ||
var x: int; | ||
|
||
operator +(ref lhs: R, rhs: int) { | ||
lhs.x += rhs; | ||
return lhs; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--read=true | ||
--read=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
localAccess-block2.chpl:8: error: halt reached - Call to .localAccess(0) from locale 1 refers to remote data (local indices are: {50..99 by 34 align 0}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
config param POD = true; | ||
|
||
config const read = true; | ||
|
||
var Arr = createArray(); | ||
|
||
on Locales[numLocales-1] { | ||
if read then writeln(Arr.localAccess[0]); else Arr.localAccess[0] += 1; | ||
} | ||
|
||
proc createArray() { | ||
if POD then | ||
return [1, 2, 3]; | ||
else | ||
return [new R(1), new R(2), new R(3)]; | ||
} | ||
|
||
record R { | ||
var x: int; | ||
|
||
operator +(ref lhs: R, rhs: int) { | ||
lhs.x += rhs; | ||
return lhs; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--read=true | ||
--read=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
localAccess.chpl:8: error: halt reached - Cannot use .localAccess() from locale 1 on a remote array stored on locale 0 |
4 changes: 4 additions & 0 deletions
4
test/distributions/block/duplicateTargetLocales.allow.comm-none.good
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
1 0 0 0 0 0 0 0 0 10 | ||
1 0 0 0 0 0 7 0 0 0 | ||
1 3 6 10 15 21 28 36 45 55 | ||
1 2 3 4 5 6 7 8 9 -10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
1 0 0 0 0 0 0 0 0 10 | ||
1 0 0 0 0 0 0 0 0 10 | ||
1 0 0 0 0 0 7 0 0 0 | ||
1 3 6 10 15 21 28 36 45 55 | ||
duplicateTargetLocales.chpl:26: error: halt reached - Call to .localAccess(10) from locale 0 refers to remote data (local indices are: {1..2} {6..7}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
-sBlockDist.allowDuplicateTargetLocales=false # duplicateTargetLocales.noallow.good | ||
-sBlockDist.allowDuplicateTargetLocales # duplicateTargetLocales.allow.good | ||
--checks -sBlockDist.allowDuplicateTargetLocales=false # duplicateTargetLocales.noallow.good | ||
--checks -sBlockDist.allowDuplicateTargetLocales # duplicateTargetLocales.allow.good |
5 changes: 5 additions & 0 deletions
5
test/distributions/cyclic/duplicateTargetLocales.allow.comm-none.good
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
duplicateTargetLocales.chpl:23: warning: scan has been serialized (see issue #12482) | ||
1 0 0 0 0 0 0 0 0 10 | ||
1 0 0 0 0 0 0 0 9 0 | ||
1 3 6 10 15 21 28 36 45 55 | ||
1 2 3 4 5 6 7 8 9 -10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
duplicateTargetLocales.chpl:23: warning: scan has been serialized (see issue #12482) | ||
1 0 0 0 0 0 0 0 0 10 | ||
1 0 0 0 0 0 0 0 0 10 | ||
1 0 0 0 0 0 0 0 9 0 | ||
1 3 6 10 15 21 28 36 45 55 | ||
duplicateTargetLocales.chpl:26: error: halt reached - Call to .localAccess(10) from locale 0 refers to remote data (local indices are: {1..10 by 8} {1..10 by 8 align 5}) |
Oops, something went wrong.