Skip to content

Commit

Permalink
Closes #2790: Convert non sym entry array creations to new throwing i…
Browse files Browse the repository at this point in the history
…nterface (#2791)

* Finish first pass of conversion

* Add throws and fix some errors

* Building after rebase

* Switch domains to generic

* Convert some missed allocations

* Convert init expressions

* Add initExpr overloads to compat modules

* Undo atomic conversion, which didn't make sense
  • Loading branch information
bmcdonald3 authored Sep 29, 2023
1 parent ec2b34d commit 466f165
Show file tree
Hide file tree
Showing 28 changed files with 258 additions and 216 deletions.
23 changes: 12 additions & 11 deletions src/ArgSortMsg.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,13 @@ module ArgSortMsg
*/
proc incrementalArgSort(g: GenSymEntry, iv: [?aD] int): [] int throws {
// Store the incremental permutation to be applied on top of the initial perm
var deltaIV: [aD] int;
var deltaIV = makeDistArray(aD, int);
// Discover the dtype of the entry holding the keys array
select g.dtype {
when DType.Int64 {
var e = toSymEntry(g, int);
// Permute the keys array with the initial iv
var newa: [e.a.domain] int;
var newa = makeDistArray(e.a.domain, int);
ref olda = e.a;
// Effectively: newa = olda[iv]
forall (newai, idx) in zip(newa, iv) with (var agg = newSrcAggregator(int)) {
Expand All @@ -139,7 +139,7 @@ module ArgSortMsg
when DType.UInt64 {
var e = toSymEntry(g, uint);
// Permute the keys array with the initial iv
var newa: [e.a.domain] uint;
var newa = makeDistArray(e.a.domain, uint);
ref olda = e.a;
// Effectively: newa = olda[iv]
forall (newai, idx) in zip(newa, iv) with (var agg = newSrcAggregator(uint)) {
Expand All @@ -150,7 +150,7 @@ module ArgSortMsg
}
when DType.Float64 {
var e = toSymEntry(g, real);
var newa: [e.a.domain] real;
var newa = makeDistArray(e.a.domain, real);
ref olda = e.a;
forall (newai, idx) in zip(newa, iv) with (var agg = newSrcAggregator(real)) {
agg.copy(newai, olda[idx]);
Expand All @@ -160,7 +160,7 @@ module ArgSortMsg
when DType.Bool {
var e = toSymEntry(g, bool);
// Permute the keys array with the initial iv
var newa: [e.a.domain] int;
var newa = makeDistArray(e.a.domain, int);
ref olda = e.a;
// Effectively: newa = olda[iv]
forall (newai, idx) in zip(newa, iv) with (var agg = newSrcAggregator(int)) {
Expand All @@ -179,7 +179,7 @@ module ArgSortMsg
}
}
// The output permutation is the composition of the initial and incremental permutations
var newIV: [aD] int;
var newIV = makeDistArray(aD, int);
// Effectively: newIV = iv[deltaIV]
forall (newIVi, idx) in zip(newIV, deltaIV) with (var agg = newSrcAggregator(int)) {
agg.copy(newIVi, iv[idx]);
Expand All @@ -189,14 +189,14 @@ module ArgSortMsg

proc incrementalArgSort(s: SegString, iv: [?aD] int): [] int throws {
var hashes = s.siphash();
var newHashes: [aD] 2*uint;
var newHashes = makeDistArray(aD, 2*uint);
forall (nh, idx) in zip(newHashes, iv) with (var agg = newSrcAggregator((2*uint))) {
agg.copy(nh, hashes[idx]);
}
var deltaIV = argsortDefault(newHashes);
// var (newOffsets, newVals) = s[iv];
// var deltaIV = newStr.argGroup();
var newIV: [aD] int;
var newIV = makeDistArray(aD, int);
forall (newIVi, idx) in zip(newIV, deltaIV) with (var agg = newSrcAggregator(int)) {
agg.copy(newIVi, iv[idx]);
}
Expand Down Expand Up @@ -311,10 +311,11 @@ module ArgSortMsg

proc argsortDefault(A:[?D] ?t, algorithm:SortingAlgorithm=defaultSortAlgorithm):[D] int throws {
var t1 = Time.timeSinceEpoch().totalSeconds();
var iv: [D] int;
var iv = makeDistArray(D, int);
select algorithm {
when SortingAlgorithm.TwoArrayRadixSort {
var AI = [(a, i) in zip(A, D)] (a, i);
var AI = makeDistArray(D, (t,int));
AI = [(a, i) in zip(A, D)] (a, i);
Sort.TwoArrayRadixSort.twoArrayRadixSort(AI, comparator=myDefaultComparator);
iv = [(a, i) in AI] i;
}
Expand Down Expand Up @@ -386,7 +387,7 @@ module ArgSortMsg
}
when (DType.Bool) {
var e = toSymEntry(gEnt,bool);
var int_ea = e.a:int;
var int_ea = makeDistArray(e.a:int);
var iv = argsortDefault(int_ea, algorithm=algorithm);
st.addEntry(ivname, createSymEntry(iv));
}
Expand Down
2 changes: 1 addition & 1 deletion src/BigIntMsg.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ module BigIntMsg {
var retList: list(string);
// default to false because we want to do first loop whether or not tmp is all_zero
var all_zero = false;
var low: [tmp.domain] uint;
var low = makeDistArray(tmp.domain, uint);
const ushift = 64:uint;
while !all_zero {
low = tmp:uint;
Expand Down
24 changes: 12 additions & 12 deletions src/Broadcast.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module Broadcast {
// domain by forming the full derivative and integrating it

// Compute the sparse derivative (in segment domain) of values
var diffs: [sD] t;
var diffs = makeDistArray(sD, t);
forall (i, d, v) in zip(sD, diffs, vals) {
if i == sD.low {
d = v;
Expand All @@ -36,7 +36,7 @@ module Broadcast {
}
}
// Convert to the dense derivative (in full domain) of values
var expandedVals: [D] t;
var expandedVals = makeDistArray(D, t);
forall (s, d) in zip(segs, diffs) with (var agg = newDstAggregator(t)) {
agg.copy(expandedVals[s], d);
}
Expand All @@ -48,7 +48,7 @@ module Broadcast {
// Integrate to recover full values
expandedVals = (+ scan expandedVals);
// Permute to the original array order
var permutedVals: [D] t;
var permutedVals = makeDistArray(D, t);
forall (i, v) in zip(perm, expandedVals) with (var agg = newDstAggregator(t)) {
agg.copy(permutedVals[i], v);
}
Expand All @@ -69,7 +69,7 @@ module Broadcast {

// Compute the sparse derivative (in segment domain) of values
// Treat booleans as integers
var diffs: [sD] int(8);
var diffs = makeDistArray(sD, int(8));
forall (i, d, v) in zip(sD, diffs, vals) {
if i == sD.low {
d = v:int(8);
Expand All @@ -78,7 +78,7 @@ module Broadcast {
}
}
// Convert to the dense derivative (in full domain) of values
var expandedVals: [D] int(8);
var expandedVals = makeDistArray(D, int(8));
forall (s, d) in zip(segs, diffs) with (var agg = newDstAggregator(int(8))) {
agg.copy(expandedVals[s], d);
}
Expand All @@ -87,7 +87,7 @@ module Broadcast {
// Integrate to recover full values
expandedVals = (+ scan expandedVals);
// Permute to the original array order and convert back to bool
var permutedVals: [D] bool;
var permutedVals = makeDistArray(D, bool);
forall (i, v) in zip(perm, expandedVals) with (var agg = newDstAggregator(bool)) {
agg.copy(permutedVals[i], v == 1);
}
Expand All @@ -99,8 +99,8 @@ module Broadcast {
ref vals = segString.values.a;
const size = perm.size;
const high = sD.high;
var strLens: [sD] int;
var segLens: [sD] int;
var strLens = makeDistArray(sD, int);
var segLens = makeDistArray(sD, int);
var expandedLen: int;

forall (i, off, str_len, seg, seg_len) in zip (sD, offs, strLens, segs, segLens) with (+ reduce expandedLen) {
Expand Down Expand Up @@ -138,7 +138,7 @@ module Broadcast {
// domain by forming the full derivative and integrating it

// Compute the sparse derivative (in segment domain) of values
var diffs: [sD] t;
var diffs = makeDistArray(sD, t);
forall (i, d, v) in zip(sD, diffs, vals) {
if i == sD.low {
d = v;
Expand Down Expand Up @@ -167,7 +167,7 @@ module Broadcast {

// Compute the sparse derivative (in segment domain) of values
// Treat booleans as integers
var diffs: [sD] int(8);
var diffs = makeDistArray(sD, int(8));
forall (i, d, v) in zip(sD, diffs, vals) {
if i == sD.low {
d = v:int(8);
Expand All @@ -191,8 +191,8 @@ module Broadcast {
ref offs = segString.offsets.a;
ref vals = segString.values.a;
const high = sD.high;
var strLens: [sD] int;
var segLens: [sD] int;
var strLens = makeDistArray(sD, int);
var segLens = makeDistArray(sD, int);
var expandedLen: int;

forall (i, off, str_len, seg, seg_len) in zip (sD, offs, strLens, segs, segLens) with (+ reduce expandedLen) {
Expand Down
2 changes: 1 addition & 1 deletion src/CSVMsg.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ module CSVMsg {
proc generate_subdoms(filenames: [?D] string, row_counts: [D] int, validFiles: [D] bool) throws {
var skips = new set(string);
var offsets = (+ scan row_counts) - row_counts;
var subdoms: [D] domain(1);
var subdoms = makeDistArray(D, domain(1));
for (i, fname, off, ct, vf) in zip(D, filenames, offsets, row_counts, validFiles) {
if (!vf) {
skips.add(fname);
Expand Down
2 changes: 1 addition & 1 deletion src/Cast.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ module Cast {
const before = toSymEntry(gse, fromType);
const oname = st.nextName();
var segments = st.addEntry(oname, before.size, int);
var strings: [before.a.domain] string;
var strings = makeDistArray(before.a.domain, string);
if fromType == real {
try {
forall (s, v) in zip(strings, before.a) {
Expand Down
2 changes: 1 addition & 1 deletion src/DataFrameIndexingMsg.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
}
}

var rvals: [0..#(+ reduce lens)] t;
var rvals = makeDistArray(+ reduce lens, t);
var rsegs = (+ scan lens) - lens;

forall(i, rs, os, l) in zip(orig_segs.domain, rsegs, orig_segs, lens){
Expand Down
22 changes: 12 additions & 10 deletions src/EfuncMsg.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,15 @@ module EfuncMsg
select efunc
{
when "cumsum" {
var ia: [e.a.domain] int = (e.a:int); // make a copy of bools as ints blah!
var ia = makeDistArray(e.a.domain, int); // make a copy of bools as ints blah!
ia = e.a:int;
// check there's enough room to create a copy for scan and throw if creating a copy would go over memory limit
overMemLimit(numBytes(int) * ia.size);
st.addEntry(rname, new shared SymEntry(+ scan ia));
}
when "cumprod" {
var ia: [e.a.domain] int = (e.a:int); // make a copy of bools as ints blah!
var ia = makeDistArray(e.a.domain, int); // make a copy of bools as ints blah!
ia = e.a:int;
// check there's enough room to create a copy for scan and throw if creating a copy would go over memory limit
overMemLimit(numBytes(int) * ia.size);
st.addEntry(rname, new shared SymEntry(* scan ia));
Expand Down Expand Up @@ -1181,8 +1183,8 @@ module EfuncMsg
:arg kind:
:type kind: param
*/
proc where_helper(cond:[?D] bool, A:[D] ?t, B:[D] t, param kind):[D] t where (kind == 0) {
var C:[D] t;
proc where_helper(cond:[?D] bool, A:[D] ?t, B:[D] t, param kind):[D] t throws where (kind == 0) {
var C = makeDistArray(D, t);
forall (ch, a, b, c) in zip(cond, A, B, C) {
c = if ch then a else b;
}
Expand All @@ -1203,8 +1205,8 @@ module EfuncMsg
:arg kind:
:type kind: param
*/
proc where_helper(cond:[?D] bool, A:[D] ?t, b:t, param kind):[D] t where (kind == 1) {
var C:[D] t;
proc where_helper(cond:[?D] bool, A:[D] ?t, b:t, param kind):[D] t throws where (kind == 1) {
var C = makeDistArray(D, t);
forall (ch, a, c) in zip(cond, A, C) {
c = if ch then a else b;
}
Expand All @@ -1225,8 +1227,8 @@ module EfuncMsg
:arg kind:
:type kind: param
*/
proc where_helper(cond:[?D] bool, a:?t, B:[D] t, param kind):[D] t where (kind == 2) {
var C:[D] t;
proc where_helper(cond:[?D] bool, a:?t, B:[D] t, param kind):[D] t throws where (kind == 2) {
var C = makeDistArray(D, t);
forall (ch, b, c) in zip(cond, B, C) {
c = if ch then a else b;
}
Expand All @@ -1247,8 +1249,8 @@ module EfuncMsg
:arg kind:
:type kind: param
*/
proc where_helper(cond:[?D] bool, a:?t, b:t, param kind):[D] t where (kind == 3) {
var C:[D] t;
proc where_helper(cond:[?D] bool, a:?t, b:t, param kind):[D] t throws where (kind == 3) {
var C = makeDistArray(D, t);
forall (ch, c) in zip(cond, C) {
c = if ch then a else b;
}
Expand Down
2 changes: 1 addition & 1 deletion src/EncodingMsg.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ module EncodingMsg {
}

proc getBufLengths(segments: [?D] int, ref values: [?vD] ?t, toEncoding: string, fromEncoding: string) throws {
var res: [D] int;
var res = makeDistArray(D, int);
if (D.size == 0) {
return res;
}
Expand Down
Loading

0 comments on commit 466f165

Please sign in to comment.