Skip to content

Commit 56eb68b

Browse files
authored
Add extended team tests (#207)
Create teams in the functional test that are not a duplicate of the ROCSHMEM_TEAM_WORLD. THis commit contains only infra-tests to make sure that n_pes and my_pe on the new teams is indeed correct. [ROCm/rocshmem commit: e953609]
1 parent 3986f25 commit 56eb68b

File tree

7 files changed

+188
-34
lines changed

7 files changed

+188
-34
lines changed

projects/rocshmem/scripts/functional_tests/driver.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ declare -A TEST_NUMBERS=(
106106
["teamwavebarrier"]="70"
107107
["wavesync"]="71"
108108
["wgsync"]="72"
109+
["teamctxsingleinfra"]="73"
110+
["teamctxblockinfra"]="74"
111+
["teamctxoddeveninfra"]="75"
109112
)
110113

111114
ExecTest() {
@@ -422,7 +425,12 @@ TestOther() {
422425

423426
# This test requires more contexts than workgroups
424427
export ROCSHMEM_MAX_NUM_CONTEXTS=1024
425-
ExecTest "teamctxinfra" 2 1 1
428+
ExecTest "teamctxinfra" 2 1 1
429+
ExecTest "teamctxsingleinfra" 2 1 1
430+
ExecTest "teamctxblockinfra" 4 1 1
431+
ExecTest "teamctxblockinfra" 5 1 1
432+
ExecTest "teamctxoddeveninfra" 4 1 1
433+
ExecTest "teamctxoddeveninfra" 5 1 1
426434
unset ROCSHMEM_MAX_NUM_CONTEXTS
427435
}
428436

projects/rocshmem/tests/functional_tests/team_ctx_infra_tester.cpp

Lines changed: 134 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,35 @@ rocshmem_team_t team_world_dup[NUM_TEAMS];
3939
/******************************************************************************
4040
* DEVICE TEST KERNEL
4141
*****************************************************************************/
42-
__global__ void TeamCtxInfraTest(ShmemContextType ctx_type,
42+
__global__ void TeamCtxInfraSimpleTest(ShmemContextType ctx_type,
43+
rocshmem_team_t team,
44+
int expected_pe, int expected_n_pes) {
45+
__shared__ rocshmem_ctx_t ctx;
46+
47+
rocshmem_wg_init();
48+
rocshmem_wg_team_create_ctx(team, ctx_type, &ctx);
49+
50+
int num_pes = rocshmem_ctx_n_pes(ctx);
51+
int my_pe = rocshmem_ctx_my_pe(ctx);
52+
53+
if (my_pe != expected_pe) {
54+
printf("PE doesn't match. Expected %d got %d\n", expected_pe, my_pe);
55+
abort();
56+
}
57+
58+
if (num_pes != expected_n_pes) {
59+
printf("Team size doesn't match. Expected %d got %d\n", expected_n_pes, num_pes);
60+
abort();
61+
}
62+
63+
__syncthreads();
64+
65+
rocshmem_ctx_quiet(ctx);
66+
rocshmem_wg_ctx_destroy(&ctx);
67+
rocshmem_wg_finalize();
68+
}
69+
70+
__global__ void TeamCtxInfraTest(ShmemContextType ctx_type,
4371
rocshmem_team_t *team) {
4472
__shared__ rocshmem_ctx_t ctx1, ctx2, ctx3;
4573
__shared__ rocshmem_ctx_t ctx[NUM_TEAMS];
@@ -109,42 +137,105 @@ __global__ void TeamCtxInfraTest(ShmemContextType ctx_type,
109137
/******************************************************************************
110138
* HOST TESTER CLASS METHODS
111139
*****************************************************************************/
112-
TeamCtxInfraTester::TeamCtxInfraTester(TesterArguments args) : Tester(args) {}
140+
TeamCtxInfraTester::TeamCtxInfraTester(TesterArguments args) : Tester(args) {
141+
_splitType = args.team_type;
142+
}
113143

114144
TeamCtxInfraTester::~TeamCtxInfraTester() {}
115145

116146
void TeamCtxInfraTester::resetBuffers(size_t size) {}
117147

118148
void TeamCtxInfraTester::preLaunchKernel() {
119-
int n_pes = rocshmem_team_n_pes(ROCSHMEM_TEAM_WORLD);
120-
121-
// validate we can run the test
122-
if (auto maximum_num_contexts_str = getenv("ROCSHMEM_MAX_NUM_CONTEXTS")) {
123-
int max_ctx = atoi(maximum_num_contexts_str);
124-
if (max_ctx <= NUM_TEAMS) {
125-
printf("ROCSHMEM_MAX_NUM_CONTEXTS=%d is smaller than NUM_TEAMS %d, invalid test setup!\n", max_ctx, NUM_TEAMS);
126-
assert(max_ctx > NUM_TEAMS);
149+
int n_pes = rocshmem_team_n_pes(_parentTeam);
150+
int my_pe = rocshmem_team_my_pe(_parentTeam);
151+
152+
if (_splitType == ROCSHMEM_TEST_TEAM_DUP) {
153+
// validate we can run the test
154+
if (auto maximum_num_contexts_str = getenv("ROCSHMEM_MAX_NUM_CONTEXTS")) {
155+
int max_ctx = atoi(maximum_num_contexts_str);
156+
if (max_ctx <= NUM_TEAMS) {
157+
printf("ROCSHMEM_MAX_NUM_CONTEXTS=%d is smaller than NUM_TEAMS %d, invalid test setup!\n", max_ctx, NUM_TEAMS);
158+
assert(max_ctx > NUM_TEAMS);
159+
abort();
160+
}
161+
}
162+
163+
for (int team_i = 0; team_i < NUM_TEAMS; team_i++) {
164+
team_world_dup[team_i] = ROCSHMEM_TEAM_INVALID;
165+
rocshmem_team_split_strided(_parentTeam, 0, 1, n_pes, nullptr, 0,
166+
&team_world_dup[team_i]);
167+
if (team_world_dup[team_i] == ROCSHMEM_TEAM_INVALID) {
168+
printf("Created team %d is invalid!\n", team_i);
169+
abort();
170+
}
171+
}
172+
173+
/* Assert the failure of a new team creation. */
174+
rocshmem_team_t new_team = ROCSHMEM_TEAM_INVALID;
175+
rocshmem_team_split_strided(_parentTeam, 0, 1, n_pes, nullptr, 0,
176+
&new_team);
177+
if (new_team != ROCSHMEM_TEAM_INVALID) {
178+
printf("Created new team should have been invalid!\n");
127179
abort();
128180
}
129181
}
182+
else if (_splitType == ROCSHMEM_TEST_TEAM_SINGLE) {
183+
rocshmem_team_split_strided(_parentTeam, my_pe, 1, 1, nullptr, 0,
184+
&team_world_dup[0]);
185+
_expected_pe = rocshmem_team_my_pe(team_world_dup[0]);
186+
_expected_n_pes = rocshmem_team_n_pes(team_world_dup[0]);
187+
188+
if (_expected_n_pes != 1) {
189+
printf("ROCSHMEM_TEST_TEAM_SINGLE: n_pes %d expected: 1\n", _expected_n_pes);
190+
abort();
191+
}
130192

131-
for (int team_i = 0; team_i < NUM_TEAMS; team_i++) {
132-
team_world_dup[team_i] = ROCSHMEM_TEAM_INVALID;
133-
rocshmem_team_split_strided(ROCSHMEM_TEAM_WORLD, 0, 1, n_pes, nullptr, 0,
134-
&team_world_dup[team_i]);
135-
if (team_world_dup[team_i] == ROCSHMEM_TEAM_INVALID) {
136-
printf("Created team %d is invalid!\n", team_i);
193+
if (_expected_pe != 0) {
194+
printf("ROCSHMEM_TEST_TEAM_SINGLE: my_pe %d expected: 0\n", _expected_pe);
195+
abort();
196+
}
197+
} else if (_splitType == ROCSHMEM_TEST_TEAM_BLOCK) {
198+
int mid_pe = n_pes / 2; // integer division
199+
int start_pe = my_pe < mid_pe ? 0 : mid_pe;
200+
int end_pe = my_pe < mid_pe ? (mid_pe - 1) : (n_pes - 1);
201+
int num_pes = end_pe - start_pe + 1;
202+
int new_pe = my_pe < mid_pe ? my_pe : (my_pe - start_pe);
203+
204+
rocshmem_team_split_strided(_parentTeam, start_pe, 1, num_pes, nullptr, 0,
205+
&team_world_dup[0]);
206+
_expected_pe = rocshmem_team_my_pe(team_world_dup[0]);
207+
_expected_n_pes = rocshmem_team_n_pes(team_world_dup[0]);
208+
209+
if (_expected_n_pes != num_pes) {
210+
printf("ROCSHMEM_TEST_TEAM_BLOCK: n_pes %d expected: %d\n", _expected_n_pes, num_pes);
137211
abort();
138212
}
139-
}
140213

141-
/* Assert the failure of a new team creation. */
142-
rocshmem_team_t new_team = ROCSHMEM_TEAM_INVALID;
143-
rocshmem_team_split_strided(ROCSHMEM_TEAM_WORLD, 0, 1, n_pes, nullptr, 0,
144-
&new_team);
145-
if (new_team != ROCSHMEM_TEAM_INVALID) {
146-
printf("Created new team should have been invalid!\n");
147-
abort();
214+
if (_expected_pe != new_pe) {
215+
printf("ROCSHMEM_TEST_TEAM_BLOCK: my_pe %d expected: %d\n", _expected_pe, new_pe);
216+
abort();
217+
}
218+
} else if (_splitType == ROCSHMEM_TEST_TEAM_ODDEVEN) {
219+
int start_pe = (my_pe % 2) == 0 ? 0 : 1;
220+
int num_pes = n_pes / 2;
221+
if (((n_pes % 2) != 0) && ((my_pe % 2) == 0))
222+
num_pes++;
223+
int new_pe = (my_pe / 2);
224+
225+
rocshmem_team_split_strided(_parentTeam, start_pe, 2, num_pes, nullptr, 0,
226+
&team_world_dup[0]);
227+
_expected_pe = rocshmem_team_my_pe(team_world_dup[0]);
228+
_expected_n_pes = rocshmem_team_n_pes(team_world_dup[0]);
229+
230+
if (_expected_n_pes != num_pes) {
231+
printf("ROCSHMEM_TEST_TEAM_ODDEVEN: n_pes %d expected: %d\n", _expected_n_pes, num_pes);
232+
abort();
233+
}
234+
235+
if (_expected_pe != new_pe) {
236+
printf("ROCSHMEM_TEST_TEAM_ODDEVEN: my_pe %d expected: %d\n", _expected_pe, new_pe);
237+
abort();
238+
}
148239
}
149240
}
150241

@@ -154,18 +245,31 @@ void TeamCtxInfraTester::launchKernel(dim3 gridSize, dim3 blockSize, int loop,
154245

155246
/* Copy array of teams to device */
156247
rocshmem_team_t *teams_on_device;
157-
CHECK_HIP(hipMalloc(&teams_on_device, sizeof(rocshmem_team_t) * NUM_TEAMS));
158-
CHECK_HIP(hipMemcpy(teams_on_device, team_world_dup,
159-
sizeof(rocshmem_team_t) * NUM_TEAMS, hipMemcpyHostToDevice));
160248

161-
hipLaunchKernelGGL(TeamCtxInfraTest, gridSize, blockSize, shared_bytes,
162-
stream, _shmem_context, teams_on_device);
249+
if (_splitType == ROCSHMEM_TEST_TEAM_DUP) {
250+
CHECK_HIP(hipMalloc(&teams_on_device, sizeof(rocshmem_team_t) * NUM_TEAMS));
251+
CHECK_HIP(hipMemcpy(teams_on_device, team_world_dup,
252+
sizeof(rocshmem_team_t) * NUM_TEAMS, hipMemcpyHostToDevice));
253+
254+
hipLaunchKernelGGL(TeamCtxInfraTest, gridSize, blockSize, shared_bytes,
255+
stream, _shmem_context, teams_on_device);
256+
} else if (_splitType == ROCSHMEM_TEST_TEAM_SINGLE ||
257+
_splitType == ROCSHMEM_TEST_TEAM_BLOCK ||
258+
_splitType == ROCSHMEM_TEST_TEAM_ODDEVEN ) {
259+
CHECK_HIP(hipMalloc(&teams_on_device, sizeof(rocshmem_team_t)));
260+
CHECK_HIP(hipMemcpy(teams_on_device, team_world_dup,
261+
sizeof(rocshmem_team_t), hipMemcpyHostToDevice));
262+
263+
hipLaunchKernelGGL(TeamCtxInfraSimpleTest, gridSize, blockSize, shared_bytes,
264+
stream, _shmem_context, teams_on_device[0], _expected_pe, _expected_n_pes);
265+
}
163266

164267
CHECK_HIP(hipFree(teams_on_device));
165268
}
166269

167270
void TeamCtxInfraTester::postLaunchKernel() {
168-
for (int team_i = 0; team_i < NUM_TEAMS; team_i++) {
271+
int num_teams = _splitType == ROCSHMEM_TEST_TEAM_DUP ? NUM_TEAMS : 1;
272+
for (int team_i = 0; team_i < num_teams; team_i++) {
169273
rocshmem_team_destroy(team_world_dup[team_i]);
170274
}
171275
}

projects/rocshmem/tests/functional_tests/team_ctx_infra_tester.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ class TeamCtxInfraTester : public Tester {
4949

5050
char *s_buf = nullptr;
5151
char *r_buf = nullptr;
52+
53+
TeamSplitType _splitType;
54+
rocshmem::rocshmem_team_t _parentTeam = rocshmem::ROCSHMEM_TEAM_WORLD;
55+
int _expected_pe;
56+
int _expected_n_pes;
5257
};
5358

5459
#endif

projects/rocshmem/tests/functional_tests/tester.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,21 @@ std::vector<Tester*> Tester::create(TesterArguments args) {
150150
if (rank == 0) std::cout << "Team Ctx Infra test ###" << std::endl;
151151
testers.push_back(new TeamCtxInfraTester(args));
152152
return testers;
153+
case TeamCtxInfraTestSingleType:
154+
if (rank == 0) std::cout << "Team Ctx Infra Single test ###" << std::endl;
155+
args.team_type = ROCSHMEM_TEST_TEAM_SINGLE;
156+
testers.push_back(new TeamCtxInfraTester(args));
157+
return testers;
158+
case TeamCtxInfraTestBlockType:
159+
if (rank == 0) std::cout << "Team Ctx Infra Block test ###" << std::endl;
160+
args.team_type = ROCSHMEM_TEST_TEAM_BLOCK;
161+
testers.push_back(new TeamCtxInfraTester(args));
162+
return testers;
163+
case TeamCtxInfraTestOddEvenType:
164+
if (rank == 0) std::cout << "Team Ctx Infra Odd-Even test ###" << std::endl;
165+
args.team_type = ROCSHMEM_TEST_TEAM_ODDEVEN;
166+
testers.push_back(new TeamCtxInfraTester(args));
167+
return testers;
153168
case TeamCtxGetTestType:
154169
if (rank == 0) std::cout << "Blocking Team Ctx Gets ###" << std::endl;
155170
testers.push_back(new TeamCtxPrimitiveTester(args));
@@ -527,7 +542,10 @@ void Tester::execute() {
527542

528543
barrier();
529544

530-
if (_type != TeamCtxInfraTestType) {
545+
if (_type != TeamCtxInfraTestType &&
546+
_type != TeamCtxInfraTestSingleType &&
547+
_type != TeamCtxInfraTestBlockType &&
548+
_type != TeamCtxInfraTestOddEvenType ) {
531549
print(size);
532550
}
533551
}
@@ -546,6 +564,8 @@ bool Tester::peLaunchesKernel() {
546564
*/
547565
is_launcher = is_launcher || (_type == TeamReductionTestType) ||
548566
(_type == TeamBroadcastTestType) || (_type == TeamCtxInfraTestType) ||
567+
(_type == TeamCtxInfraTestSingleType) || (_type == TeamCtxInfraTestBlockType) ||
568+
(_type == TeamCtxInfraTestOddEvenType) ||
549569
(_type == TeamAllToAllTestType) || (_type == TeamFCollectTestType) ||
550570
(_type == PingPongTestType) || (_type == BarrierAllTestType) ||
551571
(_type == WAVEBarrierAllTestType) || (_type == WGBarrierAllTestType) ||

projects/rocshmem/tests/functional_tests/tester.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ enum TestType {
110110
TeamWAVEBarrierTestType = 70,
111111
WAVESyncTestType = 71,
112112
WGSyncTestType = 72,
113+
TeamCtxInfraTestSingleType = 73,
114+
TeamCtxInfraTestBlockType = 74,
115+
TeamCtxInfraTestOddEvenType = 75,
113116
};
114117

115118
enum OpType { PutType = 0, GetType = 1 };

projects/rocshmem/tests/functional_tests/tester_arguments.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ TesterArguments::TesterArguments(int argc, char *argv[]) {
113113
min_msg_size = 8;
114114
break;
115115
case TeamCtxInfraTestType:
116+
case TeamCtxInfraTestSingleType:
117+
case TeamCtxInfraTestBlockType:
118+
case TeamCtxInfraTestOddEvenType:
116119
max_msg_size = min_msg_size;
117120
break;
118121
case PutNBIMRTestType:
@@ -149,7 +152,8 @@ void TesterArguments::get_rocshmem_arguments() {
149152
(type != TeamFCollectTestType) && (type != TeamReductionTestType) &&
150153
(type != TeamBroadcastTestType) && (type != PingAllTestType) &&
151154
(type != TeamBarrierTestType) && (type != TeamWAVEBarrierTestType) &&
152-
(type != TeamWGBarrierTestType)) {
155+
(type != TeamWGBarrierTestType) && (type != TeamCtxInfraTestBlockType) &&
156+
(type != TeamCtxInfraTestOddEvenType)) {
153157
if (numprocs != 2) {
154158
if (myid == 0) {
155159
std::cerr << "This test requires exactly two processes, we have "

projects/rocshmem/tests/functional_tests/tester_arguments.hpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@
3131
#include <string>
3232
#include <iostream>
3333

34+
35+
enum TeamSplitType {
36+
ROCSHMEM_TEST_TEAM_DUP = 0, // Dup parent team
37+
ROCSHMEM_TEST_TEAM_SINGLE, // each PE will be its own team
38+
ROCSHMEM_TEST_TEAM_BLOCK, // split parent into two halfs
39+
ROCSHMEM_TEST_TEAM_ODDEVEN, // odd-even splitting
40+
};
41+
3442
class TesterArguments {
3543
public:
3644
TesterArguments(int argc, char *argv[]);
@@ -47,7 +55,7 @@ class TesterArguments {
4755
*/
4856
static void show_usage(std::string executable_name);
4957

50-
public:
58+
public:
5159
/**
5260
* Arguments obtained from command line
5361
*/
@@ -75,6 +83,8 @@ class TesterArguments {
7583
int skip = 10;
7684
int loop_large = 10;
7785
size_t large_message_size = 32768;
86+
87+
TeamSplitType team_type = ROCSHMEM_TEST_TEAM_DUP;
7888
};
7989

8090
#endif

0 commit comments

Comments
 (0)