Skip to content

Commit 478347f

Browse files
Sean Pollardswelch
authored andcommitted
prov/cxi: Added collectives logical operators
Signed-off-by: Sean Pollard <[email protected]>
1 parent 19f453d commit 478347f

File tree

2 files changed

+105
-0
lines changed

2 files changed

+105
-0
lines changed

prov/cxi/src/cxip_coll.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,9 @@ void _dump_red_pkt(struct red_pkt *pkt, char *dir)
353353
#define COLL_OPCODE_BIT_AND 0x01
354354
#define COLL_OPCODE_BIT_OR 0x02
355355
#define COLL_OPCODE_BIT_XOR 0x03
356+
#define COLL_OPCODE_LOG_AND 0x04
357+
#define COLL_OPCODE_LOG_OR 0x05
358+
#define COLL_OPCODE_LOG_XOR 0x06
356359
#define COLL_OPCODE_INT_MIN 0x10
357360
#define COLL_OPCODE_INT_MAX 0x11
358361
#define COLL_OPCODE_INT_MINMAXLOC 0x12
@@ -401,11 +404,17 @@ void cxip_coll_populate_opcodes(void)
401404
_int8_16_32_op_to_opcode[FI_BOR] = COLL_OPCODE_BIT_OR;
402405
_int8_16_32_op_to_opcode[FI_BAND] = COLL_OPCODE_BIT_AND;
403406
_int8_16_32_op_to_opcode[FI_BXOR] = COLL_OPCODE_BIT_XOR;
407+
_int8_16_32_op_to_opcode[FI_LOR] = COLL_OPCODE_LOG_OR;
408+
_int8_16_32_op_to_opcode[FI_LAND] = COLL_OPCODE_LOG_AND;
409+
_int8_16_32_op_to_opcode[FI_LXOR] = COLL_OPCODE_LOG_XOR;
404410

405411
/* operations supported by 32, 16, and 8 bit unsigned int operands */
406412
_uint8_16_32_op_to_opcode[FI_BOR] = COLL_OPCODE_BIT_OR;
407413
_uint8_16_32_op_to_opcode[FI_BAND] = COLL_OPCODE_BIT_AND;
408414
_uint8_16_32_op_to_opcode[FI_BXOR] = COLL_OPCODE_BIT_XOR;
415+
_uint8_16_32_op_to_opcode[FI_LOR] = COLL_OPCODE_LOG_OR;
416+
_uint8_16_32_op_to_opcode[FI_LAND] = COLL_OPCODE_LOG_AND;
417+
_uint8_16_32_op_to_opcode[FI_LXOR] = COLL_OPCODE_LOG_XOR;
409418

410419
/* operations supported by 64 bit signed int operands */
411420
_int64_op_to_opcode[FI_MIN] = COLL_OPCODE_INT_MIN;
@@ -417,6 +426,9 @@ void cxip_coll_populate_opcodes(void)
417426
_uint64_op_to_opcode[FI_BOR] = COLL_OPCODE_BIT_OR;
418427
_uint64_op_to_opcode[FI_BAND] = COLL_OPCODE_BIT_AND;
419428
_uint64_op_to_opcode[FI_BXOR] = COLL_OPCODE_BIT_XOR;
429+
_uint64_op_to_opcode[FI_LOR] = COLL_OPCODE_LOG_OR;
430+
_uint64_op_to_opcode[FI_LAND] = COLL_OPCODE_LOG_AND;
431+
_uint64_op_to_opcode[FI_LXOR] = COLL_OPCODE_LOG_XOR;
420432

421433
/* operations supported by 64 bit double operands */
422434
_flt_op_to_opcode[FI_MIN] = COLL_OPCODE_FLT_MINNUM;
@@ -429,6 +441,9 @@ void cxip_coll_populate_opcodes(void)
429441
_cxi_op_to_redtype[COLL_OPCODE_BIT_OR] = REDTYPE_INT;
430442
_cxi_op_to_redtype[COLL_OPCODE_BIT_AND] = REDTYPE_INT;
431443
_cxi_op_to_redtype[COLL_OPCODE_BIT_XOR] = REDTYPE_INT;
444+
_cxi_op_to_redtype[COLL_OPCODE_LOG_OR] = REDTYPE_INT;
445+
_cxi_op_to_redtype[COLL_OPCODE_LOG_AND] = REDTYPE_INT;
446+
_cxi_op_to_redtype[COLL_OPCODE_LOG_XOR] = REDTYPE_INT;
432447
_cxi_op_to_redtype[COLL_OPCODE_INT_MIN] = REDTYPE_INT;
433448
_cxi_op_to_redtype[COLL_OPCODE_INT_MAX] = REDTYPE_INT;
434449
_cxi_op_to_redtype[COLL_OPCODE_INT_SUM] = REDTYPE_INT;
@@ -1502,6 +1517,26 @@ static void _reduce(struct cxip_coll_data *accum,
15021517
accum->intval.ival[i] ^= coll_data->intval.ival[i];
15031518
/* overflow not possible */
15041519
break;
1520+
case COLL_OPCODE_LOG_AND:
1521+
for (i = 0; i < 4; i++)
1522+
accum->intval.ival[i] = (accum->intval.ival[i] &&
1523+
coll_data->intval.ival[i]);
1524+
/* overflow not possible */
1525+
break;
1526+
case COLL_OPCODE_LOG_OR:
1527+
for (i = 0; i < 4; i++)
1528+
accum->intval.ival[i] = (accum->intval.ival[i] ||
1529+
coll_data->intval.ival[i]);
1530+
/* overflow not possible */
1531+
break;
1532+
case COLL_OPCODE_LOG_XOR:
1533+
for (i = 0; i < 4; i++)
1534+
accum->intval.ival[i] = ((accum->intval.ival[i] &&
1535+
!coll_data->intval.ival[i])
1536+
|| (!accum->intval.ival[i] &&
1537+
coll_data->intval.ival[i]));
1538+
/* overflow not possible */
1539+
break;
15051540
case COLL_OPCODE_INT_MIN:
15061541
for (i = 0; i < 4; i++)
15071542
if (accum->intval.ival[i] > coll_data->intval.ival[i])

prov/cxi/test/coll.c

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1869,6 +1869,76 @@ Test(coll_reduce_ops, bxor)
18691869
STDCLEANUP
18701870
}
18711871

1872+
/* Test logical OR */
1873+
Test(coll_reduce_ops, lor)
1874+
{
1875+
STDINTSETUP
1876+
/* max nodes == 32 under NETSIM */
1877+
for (i = 0; i < nodes; i++) {
1878+
data[i].ival[0] = 1 << i;
1879+
data[i].ival[1] = i << 2*i;
1880+
data[i].ival[2] = i;
1881+
data[i].ival[3] = 2*i;
1882+
}
1883+
memcpy(&check, &data[0], sizeof(check));
1884+
for (i = 1; i < nodes; i++)
1885+
for (j = 0; j < 4; j++)
1886+
check.ival[j] = (check.ival[j] || data[i].ival[j]);
1887+
1888+
ret = _allreduceop(FI_LOR, FI_UINT64, 0L, data, rslt, 4, context);
1889+
cr_assert(!ret, "_allreduceop() failed\n");
1890+
ret = _check_ival(nodes, rslt, &check);
1891+
cr_assert(!ret, "compare failed\n");
1892+
STDCLEANUP
1893+
}
1894+
1895+
/* Test logical AND */
1896+
Test(coll_reduce_ops, land)
1897+
{
1898+
STDINTSETUP
1899+
/* max nodes == 32 under NETSIM */
1900+
for (i = 0; i < nodes; i++) {
1901+
data[i].ival[0] = ~(1 << i);
1902+
data[i].ival[1] = ~(i << 2*i);
1903+
data[i].ival[2] = ~i;
1904+
data[i].ival[3] = ~(2*i);
1905+
}
1906+
memcpy(&check, &data[0], sizeof(check));
1907+
for (i = 1; i < nodes; i++)
1908+
for (j = 0; j < 4; j++)
1909+
check.ival[j] = (check.ival[j] && data[i].ival[j]);
1910+
1911+
ret = _allreduceop(FI_LAND, FI_UINT64, 0L, data, rslt, 4, context);
1912+
cr_assert(!ret, "_allreduceop() failed = %d\n", ret);
1913+
ret = _check_ival(nodes, rslt, &check);
1914+
cr_assert(!ret, "compare failed\n");
1915+
STDCLEANUP
1916+
}
1917+
1918+
/* Test logical XOR */
1919+
Test(coll_reduce_ops, lxor)
1920+
{
1921+
STDINTSETUP
1922+
/* max nodes == 32 under NETSIM */
1923+
for (i = 0; i < nodes; i++) {
1924+
data[i].ival[0] = 1 << i;
1925+
data[i].ival[1] = ~(i << i);
1926+
data[i].ival[2] = i;
1927+
data[i].ival[3] = ~i;
1928+
}
1929+
memcpy(&check, &data[0], sizeof(check));
1930+
for (i = 1; i < nodes; i++)
1931+
for (j = 0; j < 4; j++)
1932+
check.ival[j] = ((check.ival[j] && !data[i].ival[j]) ||
1933+
(!check.ival[j] && data[i].ival[j]));
1934+
1935+
ret = _allreduceop(FI_LXOR, FI_UINT64, 0L, data, rslt, 4, context);
1936+
cr_assert(!ret, "_allreduceop() failed\n");
1937+
ret = _check_ival(nodes, rslt, &check);
1938+
cr_assert(!ret, "compare failed\n");
1939+
STDCLEANUP
1940+
}
1941+
18721942
/* Tests int64 minimum */
18731943
Test(coll_reduce_ops, imin)
18741944
{

0 commit comments

Comments
 (0)