Skip to content

Commit 1a5d143

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 1a5d143

File tree

1 file changed

+163
-8
lines changed

1 file changed

+163
-8
lines changed

conformance_tests/core/test_device/src/test_device.cpp

Lines changed: 163 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,169 @@ 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() && !foundPair; ++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+
}
424+
}
425+
}
426+
427+
if (!foundPair) {
428+
LOG_INFO << "No two devices with the same UUID were found.";
429+
}
430+
}
431+
432+
TEST(zeDeviceCanAccessPeerTests,
433+
GivenTheSameSubdevicesWhenCheckingAccessThenTrueReturned) {
434+
std::vector<ze_device_handle_t> sub_devices;
435+
auto devices = lzt::get_ze_devices();
436+
437+
for (auto device : devices) {
438+
sub_devices = lzt::get_ze_sub_devices(device);
439+
if (sub_devices.size() >= 2)
440+
break;
441+
}
442+
if (sub_devices.size() < 2) {
443+
LOG_INFO << "WARNING: Exiting as no multiple subdevices was found";
444+
GTEST_SKIP();
445+
}
446+
447+
bool foundPair = false;
448+
for (size_t i = 0; i < sub_devices.size() && !foundPair; ++i) {
449+
for (size_t j = i + 1; j < sub_devices.size() && !foundPair; ++j) {
450+
ze_device_properties_t deviceProperties =
451+
lzt::get_device_properties(sub_devices[i]);
452+
ze_device_properties_t peerDeviceProperties =
453+
lzt::get_device_properties(sub_devices[j]);
454+
455+
if (areDeviceUuidsEqual(deviceProperties.uuid,
456+
peerDeviceProperties.uuid)) {
457+
ze_bool_t a2b = lzt::can_access_peer(sub_devices[i], sub_devices[j]);
458+
EXPECT_TRUE(a2b);
459+
ze_bool_t b2a = lzt::can_access_peer(sub_devices[j], sub_devices[i]);
460+
EXPECT_TRUE(b2a);
461+
foundPair = true;
462+
}
463+
}
464+
}
465+
466+
if (!foundPair) {
467+
LOG_INFO << "No two subdevices with the same UUID were found.";
468+
}
469+
}
470+
471+
bool checkIfDevicesShareSameParent(ze_device_handle_t device1,
472+
ze_device_handle_t device2) {
473+
ze_device_handle_t rootDevice1 = nullptr;
474+
ze_device_handle_t rootDevice2 = nullptr;
475+
476+
ze_result_t result1 = zeDeviceGetRootDevice(device1, &rootDevice1);
477+
ze_result_t result2 = zeDeviceGetRootDevice(device2, &rootDevice2);
478+
479+
if (result1 != ZE_RESULT_SUCCESS || result2 != ZE_RESULT_SUCCESS) {
480+
return false;
481+
}
482+
483+
return rootDevice1 == rootDevice2;
484+
}
485+
486+
TEST(zeDeviceCanAccessPeerTests,
487+
GivenSubDevicesWithSameParentWhenCheckingAccessThenTrueReturned) {
488+
std::vector<ze_device_handle_t> sub_devices;
489+
auto devices = lzt::get_ze_devices();
490+
bool sufficientSubDevicesFound = false;
491+
492+
for (auto device : devices) {
493+
sub_devices = lzt::get_ze_sub_devices(device);
494+
495+
if (sub_devices.size() >= 2 &&
496+
checkIfDevicesShareSameParent(sub_devices[0], sub_devices[1])) {
497+
sufficientSubDevicesFound = true;
498+
break;
499+
}
500+
}
501+
if (!sufficientSubDevicesFound) {
502+
LOG_INFO
503+
<< "WARNING: Exiting as no device with at least two subdevices exists";
504+
GTEST_SKIP();
505+
}
506+
ze_bool_t a2b = lzt::can_access_peer(sub_devices[0], sub_devices[1]);
507+
EXPECT_TRUE(a2b);
508+
ze_bool_t b2a = lzt::can_access_peer(sub_devices[1], sub_devices[0]);
509+
EXPECT_TRUE(b2a);
510+
}
511+
512+
bool areDeviceHandlesEqual(ze_device_handle_t handle1, ze_device_handle_t handle2) {
513+
return handle1 == handle2;
514+
}
515+
516+
TEST(zeDeviceCanAccessPeerTests,
517+
GivenTheSameDeviceHandleWhenCheckingAccessThenTrueReturned) {
518+
auto drivers = lzt::get_all_driver_handles();
519+
ASSERT_GT(drivers.size(), 0)
520+
<< "no drivers found for peer to peer device test";
521+
522+
std::vector<ze_device_handle_t> all_devices;
523+
for (auto driver : drivers) {
524+
auto devices = lzt::get_ze_devices(driver);
525+
all_devices.insert(all_devices.end(), devices.begin(), devices.end());
526+
}
527+
528+
bool foundSameHandle = false;
529+
for (size_t i = 0; i < all_devices.size() && !foundSameHandle; ++i) {
530+
for (size_t j = i + 1; j < all_devices.size() && !foundSameHandle; ++j) {
531+
if (areDeviceHandlesEqual(all_devices[i], all_devices[j])) {
532+
ze_bool_t a2b = lzt::can_access_peer(all_devices[i], all_devices[j]);
533+
EXPECT_TRUE(a2b);
534+
ze_bool_t b2a = lzt::can_access_peer(all_devices[j], all_devices[i]);
535+
EXPECT_TRUE(b2a);
536+
foundSameHandle = true;
537+
}
538+
}
539+
}
540+
541+
if (!foundSameHandle) {
542+
LOG_INFO << "No two devices with the same handle were found.";
543+
}
544+
}
545+
383546
TEST(
384547
zeDeviceGetModulePropertiesTests,
385548
GivenValidDeviceWhenRetrievingModulePropertiesThenValidPropertiesReturned) {
@@ -455,14 +618,6 @@ typedef struct DeviceHandlesBySku_ {
455618
std::vector<ze_device_handle_t> deviceHandlesForSku;
456619
} DeviceHandlesBySku_t;
457620

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-
466621
class DevicePropertiesTest : public ::testing::Test {
467622
public:
468623
std::vector<DeviceHandlesBySku_t *> deviceHandlesAllSkus;

0 commit comments

Comments
 (0)