Skip to content

Commit 53c2f91

Browse files
authored
coverity scan, bug, missing pti assert, tests added (#47)
* coverity scan, bug, missing pti assert, tests added * added status check for zeMemGetAllocProperties * bumped up version, clang formatted
1 parent f96492f commit 53c2f91

File tree

4 files changed

+86
-7
lines changed

4 files changed

+86
-7
lines changed

sdk/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.2.0
1+
0.3.1

sdk/src/levelzero/ze_collector.h

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2247,7 +2247,8 @@ overhead::Init();
22472247
ze_device_properties_t dev_props;
22482248
dev_props.stype = ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES;
22492249
dev_props.pNext = nullptr;
2250-
zeDeviceGetProperties(device, &dev_props);
2250+
ze_result_t status = zeDeviceGetProperties(device, &dev_props);
2251+
PTI_ASSERT(status == ZE_RESULT_SUCCESS);
22512252
std::copy_n(dev_props.uuid.id, ZE_MAX_DEVICE_UUID_SIZE, dev_uuid_map[command->src_device]);
22522253

22532254
command->sycl_node_id_ = sycl_data_kview.sycl_node_id_;
@@ -2376,17 +2377,23 @@ overhead::Init();
23762377
command_list_info.dst_device = nullptr;
23772378

23782379
if (dst != nullptr) {
2379-
zeMemGetAllocProperties(context, dst, &mem_props, &command_list_info.dst_device);
2380+
ze_result_t status =
2381+
zeMemGetAllocProperties(context, dst, &mem_props, &command_list_info.dst_device);
2382+
PTI_ASSERT(status == ZE_RESULT_SUCCESS);
23802383
if (command_list_info.dst_device) {
2381-
zeDeviceGetProperties(command_list_info.dst_device, &dev_props);
2384+
ze_result_t status = zeDeviceGetProperties(command_list_info.dst_device, &dev_props);
2385+
PTI_ASSERT(status == ZE_RESULT_SUCCESS);
23822386
std::copy_n(dev_props.uuid.id, ZE_MAX_DEVICE_UUID_SIZE,
23832387
dev_uuid_map[command_list_info.dst_device]);
23842388
}
23852389
}
23862390
if (src != nullptr) {
2387-
zeMemGetAllocProperties(context, src, &mem_props, &command_list_info.src_device);
2391+
ze_result_t status =
2392+
zeMemGetAllocProperties(context, src, &mem_props, &command_list_info.src_device);
2393+
PTI_ASSERT(status == ZE_RESULT_SUCCESS);
23882394
if (command_list_info.src_device) {
2389-
zeDeviceGetProperties(command_list_info.src_device, &dev_props);
2395+
ze_result_t status = zeDeviceGetProperties(command_list_info.src_device, &dev_props);
2396+
PTI_ASSERT(status == ZE_RESULT_SUCCESS);
23902397
std::copy_n(dev_props.uuid.id, ZE_MAX_DEVICE_UUID_SIZE,
23912398
dev_uuid_map[command_list_info.src_device]);
23922399
}

sdk/src/view_handler.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,13 +638,15 @@ inline void SetMemCpyIds(T& record, const ZeKernelCommandExecutionRecord& rec) {
638638
if (rec.device_ != nullptr) {
639639
GetDeviceId(record._pci_address, rec.pci_prop_);
640640
std::copy_n(rec.src_device_uuid, PTI_MAX_DEVICE_UUID_SIZE, record._device_uuid);
641+
SetMemCopyType<T>(record, rec);
641642
return;
642643
} else if (rec.dst_device_ != nullptr)
643644
GetDeviceId(record._pci_address, rec.dst_pci_prop_);
644645
else
645646
memset(record._pci_address, 0, PTI_MAX_PCI_ADDRESS_SIZE);
646647

647648
std::copy_n(rec.dst_device_uuid, PTI_MAX_DEVICE_UUID_SIZE, record._device_uuid);
649+
SetMemCopyType<T>(record, rec);
648650
}
649651

650652
template <typename T>
@@ -660,6 +662,7 @@ inline void SetMemCpyIdsP2P(T& record, const ZeKernelCommandExecutionRecord& rec
660662

661663
std::copy_n(rec.src_device_uuid, PTI_MAX_DEVICE_UUID_SIZE, record._src_uuid);
662664
std::copy_n(rec.dst_device_uuid, PTI_MAX_DEVICE_UUID_SIZE, record._dst_uuid);
665+
SetMemCopyType<T>(record, rec);
663666
}
664667

665668
template <typename T>

sdk/test/mem_ops_test.cc

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,20 @@
1212

1313
using namespace sycl;
1414

15+
namespace {
1516
bool p2p_d2d_record = false;
1617
bool p2p_d2s_record = false;
1718
bool p2p_s2d_record = false;
1819
bool p2p_s2s_record = false;
1920
bool uuid_non_unique = false;
2021
bool memfill_uuid_zero = false;
22+
bool memcopy_type_valid = false;
23+
bool memsrc_type_valid = false;
24+
bool memdst_type_valid = false;
2125
bool non_p2p_d2d_exists = false;
2226
bool atleast_2_devices = false;
2327
bool p2p_device_access = false;
28+
} // namespace
2429

2530
void StartTracing() {
2631
ASSERT_EQ(ptiViewEnable(PTI_VIEW_DEVICE_GPU_KERNEL), pti_result::PTI_SUCCESS);
@@ -81,6 +86,13 @@ static void BufferCompleted(unsigned char* buf, size_t buf_size, size_t used_byt
8186
std::string memcpy_name = reinterpret_cast<pti_view_record_memory_copy*>(ptr)->_name;
8287
if (memcpy_name.find("D2D)") != std::string::npos) {
8388
non_p2p_d2d_exists = true;
89+
pti_view_record_memory_copy* rec = reinterpret_cast<pti_view_record_memory_copy*>(ptr);
90+
if (rec->_memcpy_type == pti_view_memcpy_type::PTI_VIEW_MEMCPY_TYPE_D2D)
91+
memcopy_type_valid = true;
92+
if (rec->_mem_src == pti_view_memory_type::PTI_VIEW_MEMORY_TYPE_DEVICE)
93+
memsrc_type_valid = true;
94+
if (rec->_mem_dst == pti_view_memory_type::PTI_VIEW_MEMORY_TYPE_DEVICE)
95+
memdst_type_valid = true;
8496
}
8597
break;
8698
}
@@ -95,6 +107,14 @@ static void BufferCompleted(unsigned char* buf, size_t buf_size, size_t used_byt
95107
if (memcmp(rec->_src_uuid, rec->_dst_uuid, PTI_MAX_DEVICE_UUID_SIZE) == 0) {
96108
uuid_non_unique = true;
97109
}
110+
if (p2p_d2s_record) {
111+
if (rec->_memcpy_type == pti_view_memcpy_type::PTI_VIEW_MEMCPY_TYPE_D2S)
112+
memcopy_type_valid = true;
113+
if (rec->_mem_src == pti_view_memory_type::PTI_VIEW_MEMORY_TYPE_DEVICE)
114+
memsrc_type_valid = true;
115+
if (rec->_mem_dst == pti_view_memory_type::PTI_VIEW_MEMORY_TYPE_SHARED)
116+
memdst_type_valid = true;
117+
}
98118
break;
99119
}
100120
case pti_view_kind::PTI_VIEW_DEVICE_GPU_MEM_FILL: {
@@ -216,7 +236,20 @@ void p2pTest() {
216236

217237
class MemoryOperationFixtureTest : public ::testing::Test {
218238
protected:
219-
void SetUp() override {}
239+
void SetUp() override {
240+
p2p_d2d_record = false;
241+
p2p_d2s_record = false;
242+
p2p_s2d_record = false;
243+
p2p_s2s_record = false;
244+
uuid_non_unique = false;
245+
memfill_uuid_zero = false;
246+
memcopy_type_valid = false;
247+
memsrc_type_valid = false;
248+
memdst_type_valid = false;
249+
non_p2p_d2d_exists = false;
250+
atleast_2_devices = false;
251+
p2p_device_access = false;
252+
}
220253

221254
void TearDown() override {}
222255
};
@@ -256,3 +289,39 @@ TEST_F(MemoryOperationFixtureTest, MemFilluuidDeviceNonZero) {
256289
p2pTest();
257290
ASSERT_EQ(memfill_uuid_zero, false);
258291
}
292+
293+
TEST_F(MemoryOperationFixtureTest, MemCopyTypeDevice) {
294+
EXPECT_EQ(ptiViewSetCallbacks(BufferRequested, BufferCompleted), pti_result::PTI_SUCCESS);
295+
p2pTest();
296+
ASSERT_EQ(memcopy_type_valid, true);
297+
}
298+
299+
TEST_F(MemoryOperationFixtureTest, MemSrcTypeDevice) {
300+
EXPECT_EQ(ptiViewSetCallbacks(BufferRequested, BufferCompleted), pti_result::PTI_SUCCESS);
301+
p2pTest();
302+
ASSERT_EQ(memsrc_type_valid, true);
303+
}
304+
305+
TEST_F(MemoryOperationFixtureTest, MemDstTypeDevice) {
306+
EXPECT_EQ(ptiViewSetCallbacks(BufferRequested, BufferCompleted), pti_result::PTI_SUCCESS);
307+
p2pTest();
308+
ASSERT_EQ(memdst_type_valid, true);
309+
}
310+
311+
TEST_F(MemoryOperationFixtureTest, MemCopyTypeP2PDevice) {
312+
EXPECT_EQ(ptiViewSetCallbacks(BufferRequested, BufferCompleted), pti_result::PTI_SUCCESS);
313+
p2pTest();
314+
ASSERT_EQ(memcopy_type_valid, true);
315+
}
316+
317+
TEST_F(MemoryOperationFixtureTest, MemSrcTypeShared) {
318+
EXPECT_EQ(ptiViewSetCallbacks(BufferRequested, BufferCompleted), pti_result::PTI_SUCCESS);
319+
p2pTest();
320+
ASSERT_EQ(memsrc_type_valid, true);
321+
}
322+
323+
TEST_F(MemoryOperationFixtureTest, MemDstTypeShared) {
324+
EXPECT_EQ(ptiViewSetCallbacks(BufferRequested, BufferCompleted), pti_result::PTI_SUCCESS);
325+
p2pTest();
326+
ASSERT_EQ(memdst_type_valid, true);
327+
}

0 commit comments

Comments
 (0)