Skip to content

Commit

Permalink
Stabilize atomic formal and type names (chapel-lang#22859)
Browse files Browse the repository at this point in the history
[Reviewed by @jeremiah-corrado]

Switch the atomic formal `value` to `val` and change the value type from
`T` to `valType`. `valType` was chosen to match syncs and be similar to
`eltType` on arrays and `idxType`. The formal name `val` was then used
to match `valType` and so we could distinguish the stored "value" in the
atomic and the name of the formal more easily. The `value`->`val` formal
renaming is being done without deprecation since we believe named args
are never used with atomics and if we had a way to disable named args we
may have just used that.

Part of Cray/chapel-private#3730
Resolves chapel-lang#20182
  • Loading branch information
ronawho authored Aug 8, 2023
2 parents de1b56d + 075ad27 commit 7f74d67
Show file tree
Hide file tree
Showing 11 changed files with 352 additions and 330 deletions.
293 changes: 149 additions & 144 deletions modules/internal/Atomics.chpl

Large diffs are not rendered by default.

185 changes: 94 additions & 91 deletions modules/internal/NetworkAtomics.chpl

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion modules/internal/fixInternalDocs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ file="./Atomics.rst"
removePrefixFunctions $file

replace "record:: AtomicBool" "type:: atomic \(bool\)" $file
replace "record:: AtomicT" "type:: atomic \(T\)" $file
replace "record:: AtomicT" "type:: atomic \(valType\)" $file

removeTitle $file
removeUsage $file
Expand Down
24 changes: 12 additions & 12 deletions modules/packages/PeekPoke.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -56,37 +56,37 @@ module PeekPoke {
}

/*
Non-atomically writes `value`.
Non-atomically writes `val`.
*/
inline proc AtomicBool.poke(value:bool): void {
this.write(value, order=memoryOrder.relaxed);
inline proc AtomicBool.poke(val:bool): void {
this.write(val, order=memoryOrder.relaxed);
}
@chpldoc.nodoc
inline proc RAtomicBool.poke(value:bool): void {
_v = value:int(64);
inline proc RAtomicBool.poke(val:bool): void {
_v = val:int(64);
}


/*
Non-atomically reads the stored value.
*/
inline proc const AtomicT.peek(): T {
inline proc const AtomicT.peek(): valType {
return this.read(order=memoryOrder.relaxed);
}
@chpldoc.nodoc
inline proc const RAtomicT.peek(): T {
inline proc const RAtomicT.peek(): valType {
return _v;
}


/*
Non-atomically writes `value`.
Non-atomically writes `val`.
*/
inline proc AtomicT.poke(value:T): void {
this.write(value, order=memoryOrder.relaxed);
inline proc AtomicT.poke(val:valType): void {
this.write(val, order=memoryOrder.relaxed);
}
@chpldoc.nodoc
inline proc RAtomicT.poke(value:T): void {
_v = value;
inline proc RAtomicT.poke(val:valType): void {
_v = val;
}
}
74 changes: 37 additions & 37 deletions modules/packages/UnorderedAtomics.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -79,77 +79,77 @@
*/
module UnorderedAtomics {

private proc externFunc(param s: string, type T) param {
if isInt(T) then return "chpl_comm_atomic_" + s + "_int" + numBits(T):string;
if isUint(T) then return "chpl_comm_atomic_" + s + "_uint" + numBits(T):string;
if isReal(T) then return "chpl_comm_atomic_" + s + "_real" + numBits(T):string;
private proc externFunc(param s: string, type valType) param {
if isInt(valType) then return "chpl_comm_atomic_" + s + "_int" + numBits(valType):string;
if isUint(valType) then return "chpl_comm_atomic_" + s + "_uint" + numBits(valType):string;
if isReal(valType) then return "chpl_comm_atomic_" + s + "_real" + numBits(valType):string;
}

/* Unordered atomic add. */
inline proc AtomicT.unorderedAdd(value:T): void {
this.add(value);
inline proc AtomicT.unorderedAdd(val:valType): void {
this.add(val);
}
@chpldoc.nodoc
inline proc RAtomicT.unorderedAdd(value:T): void {
pragma "insert line file info" extern externFunc("add_unordered", T)
proc atomic_add_unordered(ref op:T, l:int(32), obj:c_ptr(void)): void;
inline proc RAtomicT.unorderedAdd(val:valType): void {
pragma "insert line file info" extern externFunc("add_unordered", valType)
proc atomic_add_unordered(ref op:valType, l:int(32), obj:c_ptr(void)): void;

var v = value;
var v = val;
atomic_add_unordered(v, _localeid(), _addr());
}

/* Unordered atomic sub. */
inline proc AtomicT.unorderedSub(value:T): void {
this.sub(value);
inline proc AtomicT.unorderedSub(val:valType): void {
this.sub(val);
}
@chpldoc.nodoc
inline proc RAtomicT.unorderedSub(value:T): void {
pragma "insert line file info" extern externFunc("sub_unordered", T)
proc atomic_sub_unordered(ref op:T, l:int(32), obj:c_ptr(void)): void;
inline proc RAtomicT.unorderedSub(val:valType): void {
pragma "insert line file info" extern externFunc("sub_unordered", valType)
proc atomic_sub_unordered(ref op:valType, l:int(32), obj:c_ptr(void)): void;

var v = value;
var v = val;
atomic_sub_unordered(v, _localeid(), _addr());
}

/* Unordered atomic or. */
inline proc AtomicT.unorderedOr(value:T): void {
this.or(value);
inline proc AtomicT.unorderedOr(val:valType): void {
this.or(val);
}
@chpldoc.nodoc
inline proc RAtomicT.unorderedOr(value:T): void {
if !isIntegral(T) then compilerError("or is only defined for integer atomic types");
pragma "insert line file info" extern externFunc("or_unordered", T)
proc atomic_or_unordered(ref op:T, l:int(32), obj:c_ptr(void)): void;
inline proc RAtomicT.unorderedOr(val:valType): void {
if !isIntegral(valType) then compilerError("or is only defined for integer atomic types");
pragma "insert line file info" extern externFunc("or_unordered", valType)
proc atomic_or_unordered(ref op:valType, l:int(32), obj:c_ptr(void)): void;

var v = value;
var v = val;
atomic_or_unordered(v, _localeid(), _addr());
}

/* Unordered atomic and. */
inline proc AtomicT.unorderedAnd(value:T): void {
this.and(value);
inline proc AtomicT.unorderedAnd(val:valType): void {
this.and(val);
}
@chpldoc.nodoc
inline proc RAtomicT.unorderedAnd(value:T): void {
if !isIntegral(T) then compilerError("and is only defined for integer atomic types");
pragma "insert line file info" extern externFunc("and_unordered", T)
proc atomic_and_unordered(ref op:T, l:int(32), obj:c_ptr(void)): void;
inline proc RAtomicT.unorderedAnd(val:valType): void {
if !isIntegral(valType) then compilerError("and is only defined for integer atomic types");
pragma "insert line file info" extern externFunc("and_unordered", valType)
proc atomic_and_unordered(ref op:valType, l:int(32), obj:c_ptr(void)): void;

var v = value;
var v = val;
atomic_and_unordered(v, _localeid(), _addr());
}

/* Unordered atomic xor. */
inline proc AtomicT.unorderedXor(value:T): void {
this.xor(value);
inline proc AtomicT.unorderedXor(val:valType): void {
this.xor(val);
}
@chpldoc.nodoc
inline proc RAtomicT.unorderedXor(value:T): void {
if !isIntegral(T) then compilerError("xor is only defined for integer atomic types");
pragma "insert line file info" extern externFunc("xor_unordered", T)
proc atomic_xor_unordered(ref op:T, l:int(32), obj:c_ptr(void)): void;
inline proc RAtomicT.unorderedXor(val:valType): void {
if !isIntegral(valType) then compilerError("xor is only defined for integer atomic types");
pragma "insert line file info" extern externFunc("xor_unordered", valType)
proc atomic_xor_unordered(ref op:valType, l:int(32), obj:c_ptr(void)): void;

var v = value;
var v = val;
atomic_xor_unordered(v, _localeid(), _addr());
}

Expand Down
2 changes: 1 addition & 1 deletion test/compflags/vass/callstack-internal-modules.d+s+.good
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
$CHPL_HOME/modules/internal/Atomics.chpl:nnnn: In function 'chpl__atomicType':
$CHPL_HOME/modules/internal/Atomics.chpl:nnnn: error: Unsupported atomic type: string
callstack-internal-modules.chpl:28: called as chpl__atomicType(type T = string) from function 'foo'
callstack-internal-modules.chpl:28: called as chpl__atomicType(type valType = string) from function 'foo'
callstack-internal-modules.chpl:24: called as foo() from function 'bar'
callstack-internal-modules.chpl:20: called as bar() from function 'main'
48 changes: 31 additions & 17 deletions test/runtime/configMatters/comm/AtomicsAPI.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ proc asyncSet(a) { begin { a.write(true); } }
proc testAtomicBool(a, ref i, ref b) {
param t = true, f = false;

writeln("Testing 'atomic bool':");
writeln("Testing '", a.type:string, "':");
writea ("init ", a);
var initval : a.type = true; writeai ("init= ", a, initval);
var initval2 : a.type = initval; writeai ("init=(v)", a, initval2);
var initval3 = initval; writeai ("init=(v)", a, initval3);
assert(initval3.type == atomic bool);
assert(a.valType == bool);
assert(a.type.valType == bool);
i = a.read(); writeai ("read ", a, i);
a.write(t); writea ("write ", a);
i = a.exchange(f); writeai ("xchg ", a, i);
Expand All @@ -45,12 +47,14 @@ proc testAtomicBool(a, ref i, ref b) {
proc testOrderAtomicBool(a, ref i, ref b, param o: memoryOrder) {
param t = true, f = false;

writeln("Testing 'atomic bool' with order '", o, "':");
writeln("Testing '", a.type:string, "' with order '", o, "':");
writea ("init ", a);
var initval : a.type = true; writeai ("init= ", a, initval);
var initval2 : a.type = initval; writeai ("init=(v)", a, initval2);
var initval3 = initval; writeai ("init=(v)", a, initval3);
assert(initval3.type == atomic bool);
assert(a.valType == bool);
assert(a.type.valType == bool);
i = a.read(o); writeai ("read ", a, i);
a.write(t, o); writea ("write ", a);
i = a.exchange(f, o); writeai ("xchg ", a, i);
Expand All @@ -72,22 +76,26 @@ proc testOrderAtomicBool(a, ref i, ref b, param o: memoryOrder) {
}

proc asyncAdd(a) { begin { a.add(1); } }
proc testAtomicT(a, ref i, ref b, type basetype) {
param isInt = isIntegral(basetype);
type xType = if isArray(a) then [a.domain] basetype else basetype;
proc testAtomicT(a, ref i, ref b) {
type eltType = if isArray(a) then a.eltType else a.type;
type valType = eltType.valType;
param isInt = isIntegral(valType);
type xType = if isArray(a) then [a.domain] valType else valType;

writeln("Testing 'atomic ", basetype:string, "':");
writeln("Testing '", eltType:string, "':");
writea ("init ", a);
if isArray(a) == false {
var initval : a.type = 1; writeai ("init= ", a, initval);
var initval2 : a.type = initval; writeai ("init=(v)", a, initval2);
var initval3 = initval; writeai ("init=(v)", a, initval3);
assert(initval3.type == atomic basetype);
assert(initval3.type == atomic valType);
assert(a.valType == valType);
assert(a.type.valType == valType);
}
i = a.read(); writeai ("read ", a, i);
a.write(1); writea ("write ", a);
i = a.exchange(2); writeai ("xchg ", a, i);
var x: xType = 3:basetype; writex ("expected", x);
var x: xType = 3:valType; writex ("expected", x);
b = a.compareExchange(x, 4); writeabx("cmpxchg ", a, b, x);
b = a.compareExchange(x, 4); writeabx("cmpxchg ", a, b, x);
b = a.compareExchangeWeak(x, 2); writeabx("cmpxchgW", a, b, x);
Expand All @@ -108,22 +116,26 @@ proc testAtomicT(a, ref i, ref b, type basetype) {
writeln();
}

proc testOrderAtomicT(a, ref i, ref b, type basetype, param o: memoryOrder) {
param isInt = isIntegral(basetype);
type xType = if isArray(a) then [a.domain] basetype else basetype;
proc testOrderAtomicT(a, ref i, ref b, param o: memoryOrder) {
type eltType = if isArray(a) then a.eltType else a.type;
type valType = eltType.valType;
param isInt = isIntegral(valType);
type xType = if isArray(a) then [a.domain] valType else valType;

writeln("Testing 'atomic ", basetype:string, "' with order '", o, "':");
writeln("Testing '", eltType:string, "' with order '", o, "':");
writea ("init ", a);
if isArray(a) == false {
var initval : a.type = 1; writeai ("init= ", a, initval);
var initval2 : a.type = initval; writeai ("init=(v)", a, initval2);
var initval3 = initval; writeai ("init=(v)", a, initval3);
assert(initval3.type == atomic basetype);
assert(initval3.type == atomic valType);
assert(a.valType == valType);
assert(a.type.valType == valType);
}
i = a.read(o); writeai ("read ", a, i);
a.write(1, o); writea ("write ", a);
i = a.exchange(2, o); writeai ("xchg ", a, i);
var x: xType = 3:basetype; writex ("expected", x);
var x: xType = 3:valType; writex ("expected", x);
b = a.compareExchange(x, 4, o); writeabx("cmpxchg ", a, b, x);
b = a.compareExchange(x, 4, o); writeabx("cmpxchg ", a, b, x);
b = a.compareExchange(x, 2, o, o); writeabx("cmpxchg ", a, b, x);
Expand All @@ -148,12 +160,14 @@ proc testOrderAtomicT(a, ref i, ref b, type basetype, param o: memoryOrder) {
writeln();
}

proc testUnorderedAtomicT(a, ref i, ref b, type basetype) {
proc testUnorderedAtomicT(a, ref i, ref b) {
type eltType = if isArray(a) then a.eltType else a.type;
type valType = eltType.valType;
use UnorderedAtomics;
inline proc fence() { unorderedAtomicTaskFence(); }
param isInt = isIntegral(basetype);
param isInt = isIntegral(valType);

writeln("Testing 'atomic ", basetype:string, "':");
writeln("Testing '", eltType:string, "':");
writea ("init ", a);
a.unorderedAdd(8); fence(); writea ("add ", a);
a.unorderedSub(1); fence(); writea ("sub ", a);
Expand Down
16 changes: 8 additions & 8 deletions test/runtime/configMatters/comm/atomic-stress.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -35,33 +35,33 @@ proc testAddSub(type t) {
}

enum ExchangeType {cmpxchg, cmpxchgW, cas};
inline proc AtomicT.loopAdd(value: T, param exchangeType: ExchangeType) {
inline proc AtomicT.loopAdd(val: valType, param exchangeType: ExchangeType) {
var oldValue = this.read();
select (exchangeType) {
when ExchangeType.cmpxchgW {
while !this.compareExchangeWeak(oldValue, oldValue + value) { }
while !this.compareExchangeWeak(oldValue, oldValue + val) { }
}
when ExchangeType.cmpxchg {
while !this.compareExchange(oldValue, oldValue + value) { }
while !this.compareExchange(oldValue, oldValue + val) { }
}
when ExchangeType.cas {
while !this.compareAndSwap(oldValue, oldValue + value) {
while !this.compareAndSwap(oldValue, oldValue + val) {
oldValue = this.read();
}
}
}
}
inline proc RAtomicT.loopAdd(value: T, param exchangeType: ExchangeType) {
inline proc RAtomicT.loopAdd(val: valType, param exchangeType: ExchangeType) {
var oldValue = this.read();
select (exchangeType) {
when ExchangeType.cmpxchgW {
while !this.compareExchangeWeak(oldValue, oldValue + value) { }
while !this.compareExchangeWeak(oldValue, oldValue + val) { }
}
when ExchangeType.cmpxchg {
while !this.compareExchange(oldValue, oldValue + value) { }
while !this.compareExchange(oldValue, oldValue + val) { }
}
when ExchangeType.cas {
while !this.compareAndSwap(oldValue, oldValue + value) {
while !this.compareAndSwap(oldValue, oldValue + val) {
oldValue = this.read();
}
}
Expand Down
14 changes: 7 additions & 7 deletions test/runtime/configMatters/comm/atomics-api-on.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ proc declareAndTestAtomicBool() {
}
}

proc declareAndTestAtomicT(type basetype) {
var a, a2: atomic basetype;
var i: basetype;
proc declareAndTestAtomicT(type valType) {
var a, a2: atomic valType;
var i: valType;
var b: bool;
on Locales[onLocale] {
testAtomicT(a, i, b, basetype);
testOrderAtomicT(a2, i, b, basetype, memoryOrder.seqCst);
testAtomicT(a, i, b);
testOrderAtomicT(a2, i, b, memoryOrder.seqCst);
}
}

Expand Down Expand Up @@ -48,7 +48,7 @@ var IInt: [1..3] int;
var BInt: [1..3] bool;
on Locales[onLocale] {
write("Promotion -- ");
testAtomicT(AInt, IInt, BInt, int);
testOrderAtomicT(AInt2, IInt, BInt, int, memoryOrder.seqCst);
testAtomicT(AInt, IInt, BInt);
testOrderAtomicT(AInt2, IInt, BInt, memoryOrder.seqCst);
}

14 changes: 7 additions & 7 deletions test/runtime/configMatters/comm/atomics-api.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ proc declareAndTestAtomicBool() {
testOrderAtomicBool(a2, i, b, memoryOrder.seqCst);
}

proc declareAndTestAtomicT(type basetype) {
var a, a2: atomic basetype;
var i: basetype;
proc declareAndTestAtomicT(type valType) {
var a, a2: atomic valType;
var i: valType;
var b: bool;
testAtomicT(a, i, b, basetype);
testOrderAtomicT(a2, i, b, basetype, memoryOrder.seqCst);
testAtomicT(a, i, b);
testOrderAtomicT(a2, i, b, memoryOrder.seqCst);
}

/* Test full API for all types */
Expand All @@ -40,5 +40,5 @@ var AInt, AInt2: [1..3] atomic int;
var IInt: [1..3] int;
var BInt: [1..3] bool;
write("Promotion -- ");
testAtomicT(AInt, IInt, BInt, int);
testOrderAtomicT(AInt2, IInt, BInt, int, memoryOrder.seqCst);
testAtomicT(AInt, IInt, BInt);
testOrderAtomicT(AInt2, IInt, BInt, memoryOrder.seqCst);
Loading

0 comments on commit 7f74d67

Please sign in to comment.