Skip to content

Commit 2b62065

Browse files
committed
Allow pseudo-multi-device tests to work in a multi-device environment.
1 parent b410c0d commit 2b62065

File tree

3 files changed

+40
-23
lines changed

3 files changed

+40
-23
lines changed

unified-runtime/test/conformance/enqueue/helpers.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,15 @@ struct urMultiQueueMultiDeviceTestWithParam
203203
urContextCreate(devices.size(), devices.data(), nullptr, &context));
204204

205205
// Duplicate our devices until we hit the minimum size specified.
206-
auto srcDevices = devices;
206+
std::vector<ur_device_handle_t> srcDevices;
207+
// If the test actually only wants one device duplicated a bunch of times
208+
// we take devices[0] and discard any other devices that were discovered.
209+
if (trueMultiDevice) {
210+
srcDevices = devices;
211+
} else {
212+
srcDevices.push_back(devices[0]);
213+
devices.clear();
214+
}
207215
while (devices.size() < minDevices) {
208216
devices.insert(devices.end(), srcDevices.begin(), srcDevices.end());
209217
}
@@ -224,6 +232,7 @@ struct urMultiQueueMultiDeviceTestWithParam
224232

225233
ur_context_handle_t context;
226234
std::vector<ur_queue_handle_t> queues;
235+
bool trueMultiDevice = true;
227236
};
228237

229238
} // namespace uur

unified-runtime/test/conformance/enqueue/urEnqueueKernelLaunch.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -565,10 +565,8 @@ UUR_INSTANTIATE_PLATFORM_TEST_SUITE(urEnqueueKernelLaunchMultiDeviceTest);
565565
// TODO: rewrite this test, right now it only works for a single queue
566566
// (the context is only created for one device)
567567
TEST_P(urEnqueueKernelLaunchMultiDeviceTest, KernelLaunchReadDifferentQueues) {
568-
UUR_KNOWN_FAILURE_ON(uur::LevelZero{}, uur::LevelZeroV2{});
569-
if (devices.size() > 1) {
570-
UUR_KNOWN_FAILURE_ON(uur::CUDA{});
571-
}
568+
UUR_KNOWN_FAILURE_ON(uur::CUDA{}, uur::LevelZero{}, uur::LevelZeroV2{});
569+
572570
uur::KernelLaunchHelper helper =
573571
uur::KernelLaunchHelper{platform, context, kernel, queues[0]};
574572

unified-runtime/test/conformance/enqueue/urEnqueueKernelLaunchAndMemcpyInOrder.cpp

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,14 @@ struct urEnqueueKernelLaunchIncrementTest
155155

156156
using Param = uur::BoolTestParam;
157157

158-
using urMultiQueueLaunchMemcpyTest<numOps, Param>::context;
159158
using urMultiQueueLaunchMemcpyTest<numOps, Param>::queues;
160-
using urMultiQueueLaunchMemcpyTest<numOps, Param>::devices;
161159
using urMultiQueueLaunchMemcpyTest<numOps, Param>::kernels;
162160
using urMultiQueueLaunchMemcpyTest<numOps, Param>::SharedMem;
163161

164162
void SetUp() override {
163+
// We actually need a single device used multiple times for this test, as
164+
// opposed to utilizing all available devices for the platform.
165+
this->trueMultiDevice = false;
165166
UUR_RETURN_ON_FATAL_FAILURE(
166167
urMultiQueueLaunchMemcpyTest<numOps, Param>::
167168
SetUp()); // Use single device, duplicated numOps times
@@ -180,9 +181,6 @@ UUR_PLATFORM_TEST_SUITE_WITH_PARAM(
180181

181182
TEST_P(urEnqueueKernelLaunchIncrementTest, Success) {
182183
UUR_KNOWN_FAILURE_ON(uur::LevelZeroV2{});
183-
if (devices.size() > 1) {
184-
UUR_KNOWN_FAILURE_ON(uur::CUDA{});
185-
}
186184

187185
constexpr size_t global_offset = 0;
188186
constexpr size_t n_dimensions = 1;
@@ -347,9 +345,28 @@ TEST_P(urEnqueueKernelLaunchIncrementMultiDeviceTest, Success) {
347345
}
348346
}
349347

350-
using urEnqueueKernelLaunchIncrementMultiDeviceMultiThreadTest =
351-
urEnqueueKernelLaunchIncrementMultiDeviceTestWithParam<
352-
std::tuple<uur::BoolTestParam, uur::BoolTestParam>>;
348+
struct urEnqueueKernelLaunchIncrementMultiDeviceMultiThreadTest
349+
: urEnqueueKernelLaunchIncrementMultiDeviceTestWithParam<
350+
std::tuple<uur::BoolTestParam, uur::BoolTestParam>> {
351+
using Param = std::tuple<uur::BoolTestParam, uur::BoolTestParam>;
352+
353+
using urEnqueueKernelLaunchIncrementMultiDeviceTestWithParam<Param>::devices;
354+
using urEnqueueKernelLaunchIncrementMultiDeviceTestWithParam<Param>::queues;
355+
using urEnqueueKernelLaunchIncrementMultiDeviceTestWithParam<Param>::kernels;
356+
using urEnqueueKernelLaunchIncrementMultiDeviceTestWithParam<
357+
Param>::SharedMem;
358+
359+
void SetUp() override {
360+
useEvents = std::get<0>(getParam()).value;
361+
queuePerThread = std::get<1>(getParam()).value;
362+
// With !queuePerThread this becomes a test on a single device
363+
this->trueMultiDevice = queuePerThread;
364+
urEnqueueKernelLaunchIncrementMultiDeviceTestWithParam<Param>::SetUp();
365+
}
366+
367+
bool useEvents;
368+
bool queuePerThread;
369+
};
353370

354371
UUR_PLATFORM_TEST_SUITE_WITH_PARAM(
355372
urEnqueueKernelLaunchIncrementMultiDeviceMultiThreadTest,
@@ -359,14 +376,7 @@ UUR_PLATFORM_TEST_SUITE_WITH_PARAM(
359376
printParams<urEnqueueKernelLaunchIncrementMultiDeviceMultiThreadTest>);
360377

361378
// Enqueue kernelLaunch concurrently from multiple threads
362-
// With !queuePerThread this becomes a test on a single device
363379
TEST_P(urEnqueueKernelLaunchIncrementMultiDeviceMultiThreadTest, Success) {
364-
if (devices.size() > 1) {
365-
UUR_KNOWN_FAILURE_ON(uur::CUDA{});
366-
}
367-
auto useEvents = std::get<0>(getParam()).value;
368-
auto queuePerThread = std::get<1>(getParam()).value;
369-
370380
if (!queuePerThread) {
371381
UUR_KNOWN_FAILURE_ON(uur::LevelZero{}, uur::LevelZeroV2{});
372382
}
@@ -377,11 +387,11 @@ TEST_P(urEnqueueKernelLaunchIncrementMultiDeviceMultiThreadTest, Success) {
377387
static constexpr size_t numOpsPerThread = 6;
378388

379389
for (size_t i = 0; i < numThreads; i++) {
380-
threads.emplace_back([this, i, queuePerThread, useEvents]() {
390+
threads.emplace_back([this, i]() {
381391
constexpr size_t global_offset = 0;
382392
constexpr size_t n_dimensions = 1;
383393

384-
auto queue = queuePerThread ? queues[i] : queues.back();
394+
auto queue = this->queuePerThread ? queues[i] : queues.back();
385395
auto kernel = kernels[i];
386396
auto sharedPtr = SharedMem[i];
387397

@@ -391,7 +401,7 @@ TEST_P(urEnqueueKernelLaunchIncrementMultiDeviceMultiThreadTest, Success) {
391401
ur_event_handle_t *lastEvent = nullptr;
392402
ur_event_handle_t *signalEvent = nullptr;
393403

394-
if (useEvents) {
404+
if (this->useEvents) {
395405
waitNum = j > 0 ? 1 : 0;
396406
lastEvent = j > 0 ? Events[j - 1].ptr() : nullptr;
397407
signalEvent = Events[j].ptr();

0 commit comments

Comments
 (0)