Skip to content

Commit 7155dcd

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 7155dcd

File tree

1 file changed

+158
-8
lines changed

1 file changed

+158
-8
lines changed

conformance_tests/core/test_device/src/test_device.cpp

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

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-
466616
class DevicePropertiesTest : public ::testing::Test {
467617
public:
468618
std::vector<DeviceHandlesBySku_t *> deviceHandlesAllSkus;

0 commit comments

Comments
 (0)