Skip to content

Commit

Permalink
Add ChplConfig.compiledForSingleLocale() query (#22730)
Browse files Browse the repository at this point in the history
Adds the `compiledForSingleLocale()` query to the `ChplConfig` module,
which return true if the program is being compiled for a single locale.

This result is controlled by the `--[no-]local` flag, and if that is not
present then by `CHPL_COMM`. The output of the query is identical to the
compiler-provided `_local` variable, and many uses of `_local` in
modules are replaced by the query in this PR.

Resolves Cray/chapel-private#5019.

[reviewed by @jeremiah-corrado , thanks!]

Testing:
- [x] local paratest
- [x] gasnet paratest
- [x] tests pass (and skip as appropriate) for all combinations of
`CHPL_COMM` and `--[no-]local`
  • Loading branch information
riftEmber authored Jul 20, 2023
2 parents e0ecd65 + 296fad3 commit 9b1d3db
Show file tree
Hide file tree
Showing 23 changed files with 166 additions and 111 deletions.
7 changes: 4 additions & 3 deletions modules/dists/PrivateDist.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
* limitations under the License.
*/

use ChplConfig only compiledForSingleLocale;

//
// Private Distribution, Domain, and Array
// Defines PrivateSpace, an instance of PrivateDom
Expand Down Expand Up @@ -169,7 +171,6 @@ private proc checkCanMakeDefaultValue(type eltType) param {
}

class PrivateArr: BaseRectangularArr {

var dom: unmanaged PrivateDom(rank, idxType, strides);

// may be initialized separately
Expand Down Expand Up @@ -241,7 +242,7 @@ override proc PrivateArr.dsiDestroyArr(deinitElts:bool) {
param needsDestroy = __primitive("needs auto destroy", eltType);

if needsDestroy {
if _local {
if compiledForSingleLocale() {
chpl__autoDestroy(data);
} else {
const pid = this.pid;
Expand All @@ -267,7 +268,7 @@ proc PrivateArr.dsiPrivatize(privatizeData) {
}

proc PrivateArr.dsiAccess(i: idxType) ref {
if _local then
if compiledForSingleLocale() then
return data;
else if i == here.id then
return data;
Expand Down
7 changes: 4 additions & 3 deletions modules/internal/ByteBufferHelpers.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module ByteBufferHelpers {
private use ChapelStandard;
private use CTypes;
private use OS.POSIX;
private use ChplConfig only compiledForSingleLocale;

@chpldoc.nodoc
type byteType = uint(8);
Expand Down Expand Up @@ -106,7 +107,7 @@ module ByteBufferHelpers {
}

inline proc bufferCopy(buf: bufferType, off: int, len: int, loc: locIdType) {
if !_local && loc != chpl_nodeID {
if !compiledForSingleLocale() && loc != chpl_nodeID {
var newBuf = bufferCopyRemote(loc, buf+off, len);
return (newBuf, len);
}
Expand All @@ -118,7 +119,7 @@ module ByteBufferHelpers {
//dst must be local
inline proc bufferMemcpy(dst: bufferType, src_loc: int(64), src: bufferType,
len: int, dst_off: int=0, src_off: int=0) {
if !_local && src_loc != chpl_nodeID {
if !compiledForSingleLocale() && src_loc != chpl_nodeID {
chpl_string_comm_get(dst+dst_off, src_loc, src+src_off, len);
}
else {
Expand All @@ -137,7 +138,7 @@ module ByteBufferHelpers {
}

inline proc bufferGetByte(buf: bufferType, off: int, loc: locIdType) {
if !_local && loc != chpl_nodeID {
if !compiledForSingleLocale() && loc != chpl_nodeID {
const newBuf = bufferCopyRemote(src_loc_id=loc, src_addr=buf+off, len=1);
const ret = newBuf[0];
bufferFree(newBuf);
Expand Down
3 changes: 2 additions & 1 deletion modules/internal/Bytes.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ module Bytes {
private use ByteBufferHelpers;
private use BytesStringCommon;
private use CTypes;
private use ChplConfig only compiledForSingleLocale;

public use BytesCasts;
public use BytesStringCommon only decodePolicy; // expose decodePolicy
Expand Down Expand Up @@ -505,7 +506,7 @@ module Bytes {
current locale, otherwise a deep copy is performed.
*/
inline proc bytes.localize() : bytes {
if _local || this.locale_id == chpl_nodeID {
if compiledForSingleLocale() || this.locale_id == chpl_nodeID {
return bytes.createBorrowingBuffer(this);
} else {
const x:bytes = this; // assignment makes it local
Expand Down
9 changes: 5 additions & 4 deletions modules/internal/BytesStringCommon.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module BytesStringCommon {
private use CTypes;
private use ByteBufferHelpers;
private use String.NVStringFactory;
private use ChplConfig only compiledForSingleLocale;

extern const CHPL_SHORT_STRING_SIZE : c_int;

Expand Down Expand Up @@ -88,7 +89,7 @@ module BytesStringCommon {
// issue (#448 chapel-private)
inline proc getCStr(const ref x: ?t): c_string {
assertArgType(t, "getCStr");
if _local == false && x.locale_id != chpl_nodeID then
if !compiledForSingleLocale() && x.locale_id != chpl_nodeID then
halt("Cannot call .c_str() on a remote " + t:string);

var buff: bufferType = x.buff;
Expand Down Expand Up @@ -323,7 +324,7 @@ module BytesStringCommon {

if otherLen > 0 {
x.buffLen = otherLen;
if !_local && otherRemote {
if !compiledForSingleLocale() && otherRemote {
// if s is remote, copy and own the buffer
x.buff = bufferCopyRemote(other.locale_id, other.buff, otherLen);
x.buffSize = otherLen+1;
Expand Down Expand Up @@ -1137,7 +1138,7 @@ module BytesStringCommon {
assertArgType(t, "doAssign");

inline proc helpMe(ref lhs: t, rhs: t) {
if _local || rhs.locale_id == chpl_nodeID {
if compiledForSingleLocale() || rhs.locale_id == chpl_nodeID {
if t == string {
reinitWithNewBuffer(lhs, rhs.buff, rhs.buffLen, rhs.buffSize,
rhs.numCodepoints);
Expand All @@ -1160,7 +1161,7 @@ module BytesStringCommon {
}
}

if _local || lhs.locale_id == chpl_nodeID then {
if compiledForSingleLocale() || lhs.locale_id == chpl_nodeID then {
helpMe(lhs, rhs);
}
else {
Expand Down
7 changes: 4 additions & 3 deletions modules/internal/ChapelArray.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ module ChapelArray {
use ChapelDebugPrint;
use CTypes;
use ChapelPrivatization;
use ChplConfig only compiledForSingleLocale;
public use ChapelDomain;

// Explicitly use a processor atomic, as most calls to this function are
Expand Down Expand Up @@ -80,9 +81,9 @@ module ChapelArray {
config param logAllArrEltAccess = false;

proc _isPrivatized(value) param do
return !_local && ((_privatization && value!.dsiSupportsPrivatization()) ||
value!.dsiRequiresPrivatization());
// Note - _local=true means --local / single locale
return !compiledForSingleLocale() &&
((_privatization && value!.dsiSupportsPrivatization()) ||
value!.dsiRequiresPrivatization());
// _privatization is controlled by --[no-]privatization
// privatization required, not optional, for PrivateDist

Expand Down
7 changes: 4 additions & 3 deletions modules/internal/String.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ module String {
use CTypes;
use ByteBufferHelpers;
use BytesStringCommon;
use ChplConfig only compiledForSingleLocale;
import OS.{errorCode};

use CString;
Expand Down Expand Up @@ -922,7 +923,7 @@ module String {
// assumes that 'this' is already localized
proc _cpIndexLenHelpNoAdjustment(ref start: int) {
if boundsChecking {
if !_local && this.locale_id != chpl_nodeID {
if !compiledForSingleLocale() && this.locale_id != chpl_nodeID {
halt("internal error -- method requires localized string");
}
}
Expand Down Expand Up @@ -1009,7 +1010,7 @@ module String {
const splitCount: int, const noSplits: bool,
const limitSplits: bool, const iEnd: byteIndex) {
if boundsChecking {
if !_local && this.locale_id != chpl_nodeID {
if !compiledForSingleLocale() && this.locale_id != chpl_nodeID {
halt("internal error -- method requires localized string");
}
}
Expand Down Expand Up @@ -1272,7 +1273,7 @@ module String {
current locale, otherwise a deep copy is performed.
*/
inline proc string.localize() : string {
if _local || this.locale_id == chpl_nodeID {
if compiledForSingleLocale() || this.locale_id == chpl_nodeID {
return string.createBorrowingBuffer(this);
} else {
const x:string = this; // assignment makes it local
Expand Down
12 changes: 6 additions & 6 deletions modules/packages/AtomicObjects.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ prototype module AtomicObjects {
// faster compression method so we need to decompress it in the same way...
var locId = descr >> compressedLocIdOffset;
var addr = descr & compressedAddrMask;
if _local || locId == here.id then return castToObj(objType, addr);
if compiledForSingleLocale() || locId == here.id then return castToObj(objType, addr);

// We've created the wide pointer, but unfortunately Chapel does not support
// the ability to cast it to the actual object, so we have to do some
Expand Down Expand Up @@ -464,7 +464,7 @@ prototype module AtomicObjects {
param hasGlobalSupport : bool;
var atomicVar : if hasABASupport then _ddata(_ABAInternal(objType?)) else atomic uint(64);

proc init(type objType, param hasABASupport = false, param hasGlobalSupport = !_local) {
proc init(type objType, param hasABASupport = false, param hasGlobalSupport = !compiledForSingleLocale()) {
if !isUnmanagedClass(objType) {
compilerError ("LocalAtomicObject must take a 'unmanaged' type, not ", objType : string);
}
Expand All @@ -481,7 +481,7 @@ prototype module AtomicObjects {
}
}

proc init(type objType, defaultValue : objType, param hasABASupport = false, param hasGlobalSupport = !_local) {
proc init(type objType, defaultValue : objType, param hasABASupport = false, param hasGlobalSupport = !compiledForSingleLocale()) {
init(objType, hasABASupport, hasGlobalSupport);
var ptr : uint(64);
if hasGlobalSupport {
Expand Down Expand Up @@ -522,9 +522,9 @@ prototype module AtomicObjects {
return compress(obj);
} else {
// Check if an object is non-local when 'hasGlobalSupport' is false
// Note: Both `_local` and `boundsChecking` are compile-time constants
// and will compile this away.
if !_local && boundsChecking {
// Note: Both `compiledForSingleLocale()` and `boundsChecking` are
// compile-time constants and will compile this away.
if !compiledForSingleLocale() && boundsChecking {
localityCheck(obj);
}
return getAddr(obj);
Expand Down
Loading

0 comments on commit 9b1d3db

Please sign in to comment.