-
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.
Avoid array allocation for moving to equal domain (#25896)
Resolves #25741 `chpl__coerceMove(_array)` already has the ability to omit an array copy when the source and destination arrays refer to the same domain. However, when the domains have equal value but are separate instances, `chpl__coerceMove` would allocate a separate array and then move elements into it from the original array. This leads to unnecessary memory usage in some cases; for example, a recursive function that returns an array and so declares the return type. This commit adds a mechanism for array implementations to provide a way to steal the data buffers from another array which can be used in this scenario. In some ways this is similar to `doiOptimizedSwap`. Note that `doiOptimizedSwap` cannot be used here because we want to avoid allocation for one of the arrays. Future Work: * add an implementation of `doiBuildArrayMoving` for more array types (most notably, Block, Cyclic, and Stencil arrays) * figure out how to get this optimization working for arrays-of-arrays. Currently, they are disabled, because something is going wrong with correctly setting up the domain for the nested arrays. Reviewed by @benharsh - thanks! - [x] primers pass with valgrind - [x] full comm=none testing - [x] full comm=gasnet oversubscribed testing
- Loading branch information
Showing
10 changed files
with
103 additions
and
15 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
4 changes: 2 additions & 2 deletions
4
test/arrays/ferguson/array-initialization-patterns/post-alloc-dists.prediff
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,6 +1,6 @@ | ||
#!/bin/bash | ||
# show only lines containing "alloc int" | ||
# show only lines after "alloc test begins" | ||
# show only lines before "alloc test begins" | ||
# show only lines after "alloc int test begins" | ||
# show only lines before "alloc int test ends" | ||
cat $2 | grep "alloc int" | grep -A 1000 "alloc int test begins" | grep -B 1000 "alloc int test ends" > $2.tmp | ||
mv $2.tmp $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
4 changes: 2 additions & 2 deletions
4
test/arrays/ferguson/array-initialization-patterns/post-alloc.prediff
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,6 +1,6 @@ | ||
#!/bin/bash | ||
# show only lines containing 'alloc int' | ||
# show only lines after "alloc test begins" | ||
# show only lines before "alloc test begins" | ||
# show only lines after "alloc int test begins" | ||
# show only lines before "alloc int test ends" | ||
cat $2 | grep "alloc int" | grep -A 1000 "alloc int test begins" | grep -B 1000 "alloc int test ends" > $2.tmp | ||
mv $2.tmp $2 |
16 changes: 16 additions & 0 deletions
16
test/arrays/ferguson/array-initialization-patterns/return-array-declared-type.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,16 @@ | ||
// this test is intended as a reproducer for the | ||
// problem of too much memory allocated | ||
// shown in issue #25741 | ||
|
||
config const n = 100_000; | ||
|
||
proc myfn(nn: int) : [0..<nn] int { | ||
var ret: [0..<nn] int; | ||
return ret; | ||
} | ||
|
||
proc main() { | ||
writeln("alloc int test begins"); | ||
var x = myfn(n); | ||
writeln("alloc int test ends"); | ||
} |
1 change: 1 addition & 0 deletions
1
test/arrays/ferguson/array-initialization-patterns/return-array-declared-type.compopts
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 @@ | ||
--set debugDefaultDist=true |
4 changes: 4 additions & 0 deletions
4
test/arrays/ferguson/array-initialization-patterns/return-array-declared-type.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 @@ | ||
alloc int test begins | ||
*** DR alloc int(64) 100000 | ||
*** DR calling postalloc int(64) 100000 | ||
alloc int test ends |
6 changes: 6 additions & 0 deletions
6
test/arrays/ferguson/array-initialization-patterns/return-array-declared-type.prediff
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,6 @@ | ||
#!/bin/bash | ||
# show only lines containing 'alloc int' | ||
# show only lines after "alloc int test begins" | ||
# show only lines before "alloc int test ends" | ||
cat $2 | grep "alloc int" | grep -A 1000 "alloc int test begins" | grep -B 1000 "alloc int test ends" > $2.tmp | ||
mv $2.tmp $2 |