8000 Add: zeDeviceCanAccessPeer additional tests and missing maxClockRate … · oneapi-src/level-zero-tests@46ae568 · GitHub
[go: up one dir, main page]

Skip to content

Commit 46ae568

Browse files
committed
Add: zeDeviceCanAccessPeer additional tests and missing maxClockRate check
GivenValidDeviceWhenRetrievingMemoryPropertiesThenValidPropertiesAreReturned maxClockRate zeDeviceCanAccessPeer: If both device and peer device are the same then return true. If both sub-device and peer sub-device are the same then return true. If both are sub-devices and share the same parent device then return true.
1 parent 6fe343d commit 46ae568

File tree

1 file changed

+137
-8
lines changed

1 file changed

+137
-8
lines changed

conformance_tests/core/test_device/src/test_device.cpp

Lines changed: 137 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,143 @@ TEST(zeDeviceCanAccessPeerTests,
380380
EXPECT_EQ(a2b, b2a);
381381
}
382382

383+
// Return false if uuuid's are NOT equal.
384+
bool areDeviceUuidsEqual(ze_device_uuid_t uuid1, ze_device_uuid_t uuid2) {
385+
if (std::memcmp(&uuid1, &uuid2, sizeof(ze_device_uuid_t))) {
386+
return false;
387+
}
388+
return true;
389+
}
390+
391+
TEST(zeDeviceCanAccessPeerTests,
392+
GivenTheSameDevicesWhenCheckingAccessThenTrueReturned) {
393+
auto drivers = lzt::get_all_driver_handles();
394+
ASSERT_GT(drivers.size(), 0)
395+
<< "no drivers found for peer to peer device test";
396+
397+
std::vector<ze_device_handle_t> all_devices;
398+
for (auto driver : drivers) {
399+
auto devices = lzt::get_ze_devices(driver);
400+
all_devices.insert(all_devices.end(), devices.begin(), devices.end());
401+
}
402+
403+
if (all_devices.size() < 2) {
404+
LOG_INFO << "WARNING: Exiting as no multiple devices was found";
405+
GTEST_SKIP();
406+
}
407+
408+
bool foundPair = false;
409+
for (size_t i = 0; i < all_devices.size() && !foundPair; ++i) {
410+
for (size_t j = i + 1; j < all_devices.size(); ++j) {
411+
ze_device_properties_t deviceProperties =
412+
lzt::get_device_properties(all_devices[i]);
413+
ze_device_properties_t peerDeviceProperties =
414+
lzt::get_device_properties(all_devices[j]);
415+
416+
if (areDeviceUuidsEqual(deviceProperties.uuid,
417+
peerDeviceProperties.uuid)) {
418+
ze_bool_t a2b = lzt::can_access_peer(all_devices[i], all_devices[j]);
419+
EXPECT_TRUE(a2b);
420+
ze_bool_t b2a = lzt::can_access_peer(all_devices[j], all_devices[i]);
421+
EXPECT_TRUE(b2a);
422+
foundPair = true;
423+
break;
424+
}
425+
}
426+
if (foundPair) {
427+
break;
428+
}
429+
}
430+
431+
if (!foundPair) {
432+
LOG_INFO << "No two devices with the same UUID were found.";
433+
}
434+
}
435+
436+
TEST(zeDeviceCanAccessPeerTests,
437+
GivenTheSameSubdevicesWhenCheckingAccessThenTrueReturned) {
438+
std::vector<ze_device_handle_t> sub_devices;
439+
auto devices = lzt::get_ze_devices();
440+
441+
for (auto device : devices) {
442+
sub_devices = lzt::get_ze_sub_devices(device);
443+
if (sub_devices.size() >= 2)
444+
break;
445+
}
446+
if (sub_devices.size() < 2) {
447+
LOG_INFO << "WARNING: Exiting as no multiple subdevices was found";
448+
GTEST_SKIP();
449+
}
450+
451+
bool foundPair = false;
452+
for (size_t i = 0; i < sub_devices.size() && !foundPair; ++i) {
453+
for (size_t j = i + 1; j < sub_devices.size(); ++j) {
454+
ze_device_properties_t deviceProperties =
455+
lzt::get_device_properties(sub_devices[i]);
456+
ze_device_properties_t peerDeviceProperties =
457+
lzt::get_device_properties(sub_devices[j]);
458+
459+
if (areDeviceUuidsEqual(deviceProperties.uuid,
460+
peerDeviceProperties.uuid)) {
461+
ze_bool_t a2b = lzt::can_access_peer(sub_devices[i], sub_devices[j]);
462+
EXPECT_TRUE(a2b);
463+
ze_bool_t b2a = lzt::can_access_peer(sub_devices[j], sub_devices[i]);
464+
EXPECT_TRUE(b2a);
465+
foundPair = true;
466+
break;
467+
}
468+
}
469+
if (foundPair) {
470+
break;
471+
}
472+
}
473+
474+
if (!foundPair) {
475+
LOG_INFO << "No two subdevices with the same UUID were found.";
476+
}
477+
}
478+
479+
bool checkIfDevicesShareSameParent(ze_device_handle_t device1,
480+
ze_device_handle_t device2) {
481+
ze_device_handle_t rootDevice1 = nullptr;
482+
ze_device_handle_t rootDevice2 = nullptr;
483+
484+
ze_result_t result1 = zeDeviceGetRootDevice(device1, &rootDevice1);
485+
ze_result_t result2 = zeDeviceGetRootDevice(device2, &rootDevice2);
486+
487+
if (result1 != ZE_RESULT_SUCCESS || result2 != ZE_RESULT_SUCCESS) {
488+
return false;
489+
}
490+
491+
return rootDevice1 == rootDevice2;
492+
}
493+
494+
TEST(zeDeviceCanAccessPeerTests,
495+
GivenSubDevicesWithSameParentWhenCheckingAccessThenTrueReturned) {
496+
std::vector<ze_device_handle_t> sub_devices;
497+
auto devices = lzt::get_ze_devices();
498+
bool sufficientSubDevicesFound = false;
499+
500+
for (auto device : devices) {
501+
sub_devices = lzt::get_ze_sub_devices(device);
502+
503+
if (sub_devices.size() >= 2 &&
504+
checkIfDevicesShareSameParent(sub_devices[0], sub_devices[1])) {
505+
sufficientSubDevicesFound = true;
506+
break;
507+
}
508+
}
509+
if (!sufficientSubDevicesFound) {
510+
LOG_INFO
511+
<< "WARNING: Exiting as no device with at least two subdevices exists";
512+
GTEST_SKIP();
513+
}
514< BAD5 code class="diff-text syntax-highlighted-line addition">+
ze_bool_t a2b = lzt::can_access_peer(sub_devices[0], sub_devices[1]);
515+
EXPECT_TRUE(a2b);
516+
ze_bool_t b2a = lzt::can_access_peer(sub_devices[1], sub_devices[0]);
517+
EXPECT_TRUE(b2a);
518+
}
519+
383520
TEST(
384521
zeDeviceGetModulePropertiesTests,
385522
GivenValidDeviceWhenRetrievingModulePropertiesThenValidPropertiesReturned) {
@@ -455,14 +592,6 @@ typedef struct DeviceHandlesBySku_ {
455592
std::vector<ze_device_handle_t> deviceHandlesForSku;
456593
} DeviceHandlesBySku_t;
457594

458-
// Return false if uuuid's are NOT equal.
459-
bool areDeviceUuidsEqual(ze_device_uuid_t uuid1, ze_device_uuid_t uuid2) {
460-
if (std::memcmp(&uuid1, &uuid2, sizeof(ze_device_uuid_t))) {
461-
return false;
462-
}
463-
return true;
464-
}
465-
466595
class DevicePropertiesTest : public ::testing::Test {
467596
public:
468597
std::vector<DeviceHandlesBySku_t *> deviceHandlesAllSkus;

0 commit comments

Comments
 (0)
0