Skip to content

Commit 5d90e2a

Browse files
Find copy engines correctly before using in test cases
Signed-off-by: Aravind Gopalakrishnan <[email protected]>
1 parent 8453287 commit 5d90e2a

File tree

2 files changed

+77
-16
lines changed

2 files changed

+77
-16
lines changed

level_zero/core/test/black_box_tests/common/zello_common.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,21 @@ void createEventPoolAndEvents(ze_context_handle_t &context,
194194
}
195195
}
196196

197+
std::vector<ze_device_handle_t> zelloGetSubDevices(ze_device_handle_t &device, int &subDevCount) {
198+
uint32_t deviceCount = 0;
199+
std::vector<ze_device_handle_t> subdevs(deviceCount, nullptr);
200+
SUCCESS_OR_TERMINATE(zeDeviceGetSubDevices(device, &deviceCount, nullptr));
201+
if (deviceCount == 0) {
202+
std::cout << "No sub device found!\n";
203+
subDevCount = 0;
204+
return subdevs;
205+
}
206+
subDevCount = deviceCount;
207+
subdevs.resize(deviceCount);
208+
SUCCESS_OR_TERMINATE(zeDeviceGetSubDevices(device, &deviceCount, subdevs.data()));
209+
return subdevs;
210+
}
211+
197212
std::vector<ze_device_handle_t> zelloInitContextAndGetDevices(ze_context_handle_t &context, ze_driver_handle_t &driverHandle) {
198213
SUCCESS_OR_TERMINATE(zeInit(ZE_INIT_FLAG_GPU_ONLY));
199214

level_zero/core/test/black_box_tests/zello_immediate.cpp

Lines changed: 62 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,13 @@ void createImmediateCommandList(ze_device_handle_t &device,
4040
SUCCESS_OR_TERMINATE(zeCommandListCreateImmediate(context, device, &cmdQueueDesc, &cmdList));
4141
}
4242

43-
void testCopyBetweenHostMemAndDeviceMem(ze_context_handle_t &context, ze_device_handle_t &device, bool syncMode, bool &validRet) {
43+
void testCopyBetweenHostMemAndDeviceMem(ze_context_handle_t &context, ze_device_handle_t &device, bool syncMode, int32_t copyQueueGroup, bool &validRet) {
4444
const size_t allocSize = 4096 + 7; // +7 to brake alignment and make it harder
4545
char *hostBuffer = nullptr;
4646
void *deviceBuffer = nullptr;
4747
char *stackBuffer = new char[allocSize];
4848
ze_command_list_handle_t cmdList;
4949

50-
int32_t copyQueueGroup = getCopyOnlyCommandQueueOrdinal(device);
51-
if (copyQueueGroup < 0) {
52-
std::cout << "No Copy queue group found. Skipping test run\n";
53-
validRet = true;
54-
return;
55-
}
56-
5750
createImmediateCommandList(device, context, copyQueueGroup, syncMode, cmdList);
5851

5952
ze_host_mem_alloc_desc_t hostDesc = {};
@@ -275,15 +268,68 @@ int main(int argc, char *argv[]) {
275268
std::cout << "\nTest case: Async mode compute queue with Kernel launch \n";
276269
executeGpuKernelAndValidate(context, device, false, outputValidationSuccessful);
277270
}
278-
if (outputValidationSuccessful) {
279-
//Sync mode with Copy queue
280-
std::cout << "\nTest case: Sync mode copy queue for memory copy\n";
281-
testCopyBetweenHostMemAndDeviceMem(context, device, true, outputValidationSuccessful);
271+
272+
// Find copy queue in root device, if not found, try subdevices
273+
int32_t copyQueueGroup = 0;
274+
bool copyQueueFound = false;
275+
auto copyQueueDev = devices[0];
276+
for (auto &rd : devices) {
277+
copyQueueGroup = getCopyOnlyCommandQueueOrdinal(rd);
278+
if (copyQueueGroup >= 0) {
279+
copyQueueFound = true;
280+
copyQueueDev = rd;
281+
if (verbose) {
282+
std::cout << "\nCopy queue group found in root device\n";
283+
}
284+
break;
285+
}
282286
}
283-
if (outputValidationSuccessful) {
284-
//Async mode with Copy queue
285-
std::cout << "\nTest case: Async mode copy queue for memory copy\n";
286-
testCopyBetweenHostMemAndDeviceMem(context, device, false, outputValidationSuccessful);
287+
288+
if (!copyQueueFound) {
289+
if (verbose) {
290+
std::cout << "\nNo Copy queue group found in root device. Checking subdevices now...\n";
291+
}
292+
copyQueueGroup = 0;
293+
for (auto &rd : devices) {
294+
int subDevCount = 0;
295+
auto subdevs = zelloGetSubDevices(rd, subDevCount);
296+
297+
if (!subDevCount) {
298+
continue;
299+
}
300+
301+
// Find subdev that has a copy engine. If not skip tests
302+
for (auto &sd : subdevs) {
303+
copyQueueGroup = getCopyOnlyCommandQueueOrdinal(sd);
304+
if (copyQueueGroup >= 0) {
305+
copyQueueFound = true;
306+
copyQueueDev = sd;
307+
break;
308+
}
309+
}
310+
311+
if (copyQueueFound) {
312+
if (verbose) {
313+
std::cout << "\nCopy queue group found in sub device\n";
314+
}
315+
break;
316+
}
317+
}
318+
}
319+
320+
if (!copyQueueFound) {
321+
std::cout << "No Copy queue group found. Skipping further test runs\n";
322+
} else {
323+
if (outputValidationSuccessful) {
324+
//Sync mode with Copy queue
325+
std::cout << "\nTest case: Sync mode copy queue for memory copy\n";
326+
testCopyBetweenHostMemAndDeviceMem(context, copyQueueDev, true, copyQueueGroup, outputValidationSuccessful);
327+
}
328+
if (outputValidationSuccessful) {
329+
//Async mode with Copy queue
330+
std::cout << "\nTest case: Async mode copy queue for memory copy\n";
331+
testCopyBetweenHostMemAndDeviceMem(context, copyQueueDev, false, copyQueueGroup, outputValidationSuccessful);
332+
}
287333
}
288334

289335
SUCCESS_OR_TERMINATE(zeContextDestroy(context));

0 commit comments

Comments
 (0)