Skip to content

Commit dda4731

Browse files
authored
Coverity issues: view_handler, L0 src_device bug. (#71)
1 parent 9650d0a commit dda4731

File tree

4 files changed

+69
-60
lines changed

4 files changed

+69
-60
lines changed

sdk/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.3.3
1+
0.3.4

sdk/src/levelzero/ze_collector.h

Lines changed: 55 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
#include <map>
2828
#include <memory>
2929
#include <mutex>
30-
#include <shared_mutex>
3130
#include <set>
31+
#include <shared_mutex>
3232
#include <sstream>
3333
#include <string>
3434
#include <vector>
@@ -216,8 +216,8 @@ struct ZeMetricQueryPools {
216216

217217
struct ZeInstanceData {
218218
uint64_t start_time_host;
219-
uint64_t timestamp_host; // in ns
220-
uint64_t timestamp_device; // in ticks
219+
uint64_t timestamp_host; // in ns
220+
uint64_t timestamp_device; // in ticks
221221
uint64_t end_time_host;
222222
uint64_t kid; // passing kid from enter callback to exit callback
223223
};
@@ -300,8 +300,8 @@ struct ZeKernelCommand {
300300
ze_command_list_handle_t command_list = nullptr;
301301
ze_command_queue_handle_t queue = nullptr;
302302
ze_fence_handle_t fence;
303-
uint64_t submit_time = 0; //in ns
304-
uint64_t submit_time_device_ = 0; //in ticks
303+
uint64_t submit_time = 0; // in ns
304+
uint64_t submit_time_device_ = 0; // in ticks
305305
uint64_t tid = 0;
306306
uint64_t sycl_node_id_ = 0;
307307
uint32_t sycl_invocation_id_ = 0;
@@ -1420,8 +1420,8 @@ overhead::Init();
14201420

14211421
uint64_t GetDeviceTimeNs(uint64_t cycles, uint64_t freq) { return cycles * NSEC_IN_SEC / freq; }
14221422

1423-
inline void GetHostTime(const ZeKernelCommand *command, const ze_kernel_timestamp_result_t& ts,
1424-
uint64_t& start, uint64_t& end) {
1423+
inline void GetHostTime(const ZeKernelCommand* command, const ze_kernel_timestamp_result_t& ts,
1424+
uint64_t& start, uint64_t& end) {
14251425
uint64_t device_freq = command->device_timer_frequency_;
14261426
uint64_t device_mask = command->device_timer_mask_;
14271427

@@ -1441,7 +1441,8 @@ overhead::Init();
14411441
// - at Enter to CommandListAppendLaunch<...> time for an Immediate Command List
14421442
// - at Enter to CommandQueueExecuteCommandLists for not Immediate CommandLists
14431443

1444-
// GPU time mask applied to the GPU time to remove some spiritous bits (in case they made there)
1444+
// GPU time mask applied to the GPU time to remove some spiritous bits (in case they made
1445+
// there)
14451446
uint64_t device_submit_time = (command->submit_time_device_ & device_mask);
14461447

14471448
// time_shift calculated in GPU scale between sync point and GPU command start,
@@ -1450,10 +1451,10 @@ overhead::Init();
14501451

14511452
if (device_start > device_submit_time) {
14521453
time_shift = (device_start - device_submit_time) * NSEC_IN_SEC / device_freq;
1453-
}
1454-
else {
1454+
} else {
14551455
// overflow
1456-
time_shift = (device_mask - device_submit_time + 1 + device_start) * NSEC_IN_SEC / device_freq;
1456+
time_shift =
1457+
(device_mask - device_submit_time + 1 + device_start) * NSEC_IN_SEC / device_freq;
14571458
}
14581459

14591460
// GPU command duration recalculated to CPU time scale units
@@ -1841,8 +1842,8 @@ overhead::Init();
18411842

18421843
PTI_ASSERT(device_descriptors_.count(device) != 0);
18431844

1844-
command_list_map_[command_list] = {
1845-
std::vector<ZeKernelCommand*>(), context, device, immediate, oi_pair};
1845+
command_list_map_[command_list] = {std::vector<ZeKernelCommand*>(), context, device, immediate,
1846+
oi_pair};
18461847
command_list_map_mutex_.unlock();
18471848

18481849
if (immediate) {
@@ -1893,19 +1894,20 @@ overhead::Init();
18931894
}
18941895
#endif /* 0 */
18951896

1896-
void PrepareToExecuteCommandLists(ze_command_list_handle_t* command_lists, uint32_t command_list_count,
1897-
ze_command_queue_handle_t queue, ze_fence_handle_t fence) {
1897+
void PrepareToExecuteCommandLists(ze_command_list_handle_t* command_lists,
1898+
uint32_t command_list_count, ze_command_queue_handle_t queue,
1899+
ze_fence_handle_t fence) {
18981900
const std::lock_guard<std::mutex> lock(lock_);
18991901
uint64_t host_time_sync = 0;
19001902
uint64_t device_time_sync = 0;
19011903
auto it = command_queues_.find(queue);
19021904
PTI_ASSERT(it != command_queues_.end());
1903-
ze_device_handle_t device = it->second.device_; // this should be only one device, as queue created on specific device
1905+
ze_device_handle_t device =
1906+
it->second.device_; // this should be only one device, as queue created on specific device
19041907
PTI_ASSERT(nullptr != device);
19051908
ze_result_t status = zeDeviceGetGlobalTimestamps(device, &host_time_sync, &device_time_sync);
19061909
PTI_ASSERT(status == ZE_RESULT_SUCCESS);
19071910

1908-
19091911
for (uint32_t i = 0; i < command_list_count; ++i) {
19101912
ze_command_list_handle_t clist = command_lists[i];
19111913
PTI_ASSERT(clist != nullptr);
@@ -1918,23 +1920,22 @@ overhead::Init();
19181920
for (ZeKernelCommand* command : info.kernel_commands) {
19191921
if (!command->tid) command->tid = utils::GetTid();
19201922
command->queue = queue;
1921-
//command->submit_time = host_sync;
1923+
// command->submit_time = host_sync;
19221924
command->submit_time = host_time_sync;
19231925
command->submit_time_device_ = device_time_sync;
19241926

19251927
PTI_ASSERT(command->append_time <= command->submit_time);
19261928
command->fence = fence;
19271929

1928-
// if (queue_ordinal_index_map_.count(queue) != 0) {
1929-
// std::pair<uint32_t, uint32_t> oi = queue_ordinal_index_map_[queue];
1930-
// }
1931-
1930+
// if (queue_ordinal_index_map_.count(queue) != 0) {
1931+
// std::pair<uint32_t, uint32_t> oi = queue_ordinal_index_map_[queue];
1932+
// }
19321933
}
19331934
}
19341935
}
19351936

1936-
void PostSubmitKernelCommands(ze_command_list_handle_t* command_lists, uint32_t command_list_count,
1937-
std::vector<uint64_t>* kids) {
1937+
void PostSubmitKernelCommands(ze_command_list_handle_t* command_lists,
1938+
uint32_t command_list_count, std::vector<uint64_t>* kids) {
19381939
const std::lock_guard<std::mutex> lock(lock_);
19391940

19401941
for (uint32_t i = 0; i < command_list_count; ++i) {
@@ -2048,9 +2049,8 @@ overhead::Init();
20482049
}
20492050
}
20502051

2051-
static void OnEnterEventDestroy(ze_event_destroy_params_t* params,
2052-
void* global_data, void** /*instance_data*/,
2053-
std::vector<uint64_t>* kids) {
2052+
static void OnEnterEventDestroy(ze_event_destroy_params_t* params, void* global_data,
2053+
void** /*instance_data*/, std::vector<uint64_t>* kids) {
20542054
if (*(params->phEvent) != nullptr) {
20552055
ZeCollector* collector = reinterpret_cast<ZeCollector*>(global_data);
20562056
std::vector<ZeKernelCommandExecutionRecord> kcexec;
@@ -2067,9 +2067,8 @@ overhead::Init();
20672067
}
20682068
}
20692069

2070-
static void OnEnterEventHostReset(ze_event_host_reset_params_t* params,
2071-
void* global_data, void** /*instance_data*/,
2072-
std::vector<uint64_t>* kids) {
2070+
static void OnEnterEventHostReset(ze_event_host_reset_params_t* params, void* global_data,
2071+
void** /*instance_data*/, std::vector<uint64_t>* kids) {
20732072
if (*(params->phEvent) != nullptr) {
20742073
ZeCollector* collector = reinterpret_cast<ZeCollector*>(global_data);
20752074
std::vector<ZeKernelCommandExecutionRecord> kcexec;
@@ -2209,7 +2208,6 @@ overhead::Init();
22092208

22102209
zet_metric_query_handle_t query = nullptr;
22112210
if (collector->options_.metric_query && iskernel) {
2212-
22132211
const auto it = collector->FindCommandListInfo(command_list);
22142212
PTI_ASSERT(it != collector->command_list_map_.end());
22152213

@@ -2229,7 +2227,7 @@ overhead::Init();
22292227
PTI_ASSERT(status == ZE_RESULT_SUCCESS);
22302228
}
22312229
uint64_t host_timestamp;
2232-
uint64_t device_timestamp; // in ticks
2230+
uint64_t device_timestamp; // in ticks
22332231

22342232
ze_result_t status = zeDeviceGetGlobalTimestamps(device, &host_timestamp, &device_timestamp);
22352233
PTI_ASSERT(status == ZE_RESULT_SUCCESS);
@@ -2331,7 +2329,8 @@ overhead::Init();
23312329
if (command_list_info.immediate) {
23322330
// command->tid = utils::GetTid();
23332331
command->submit_time = command->append_time;
2334-
command->submit_time_device_ = ze_instance_data.timestamp_device; // append time and submit time are the same
2332+
command->submit_time_device_ =
2333+
ze_instance_data.timestamp_device; // append time and submit time are the same
23352334
command->queue = reinterpret_cast<ze_command_queue_handle_t>(command_list);
23362335
kernel_command_list_.push_back(command);
23372336
kids->push_back(command->kernel_id);
@@ -2424,8 +2423,7 @@ overhead::Init();
24242423
// in below GetTransferProperties => so twice for src and dst.
24252424
// this should be avoided
24262425
if (dst != nullptr) {
2427-
ze_result_t status =
2428-
zeMemGetAllocProperties(context, dst, &mem_props, &dst_device);
2426+
ze_result_t status = zeMemGetAllocProperties(context, dst, &mem_props, &dst_device);
24292427
PTI_ASSERT(status == ZE_RESULT_SUCCESS);
24302428
if (dst_device) {
24312429
ze_result_t status = zeDeviceGetProperties(dst_device, &dev_props);
@@ -2434,8 +2432,7 @@ overhead::Init();
24342432
}
24352433
}
24362434
if (src != nullptr) {
2437-
ze_result_t status =
2438-
zeMemGetAllocProperties(context, src, &mem_props, &src_device);
2435+
ze_result_t status = zeMemGetAllocProperties(context, src, &mem_props, &src_device);
24392436
PTI_ASSERT(status == ZE_RESULT_SUCCESS);
24402437
if (src_device) {
24412438
ze_result_t status = zeDeviceGetProperties(src_device, &dev_props);
@@ -2651,7 +2648,7 @@ overhead::Init();
26512648
props.value_size = pattern_size;
26522649
props.type = KERNEL_COMMAND_TYPE_MEMORY;
26532650
props.src_device = hSrcDevice;
2654-
props.src_device = hDstDevice;
2651+
props.dst_device = hDstDevice;
26552652
return props;
26562653
}
26572654

@@ -2693,8 +2690,8 @@ overhead::Init();
26932690
}
26942691

26952692
static void OnEnterCommandListAppendLaunchCooperativeKernel(
2696-
ze_command_list_append_launch_cooperative_kernel_params_t* params,
2697-
void* global_data, void** instance_data) {
2693+
ze_command_list_append_launch_cooperative_kernel_params_t* params, void* global_data,
2694+
void** instance_data) {
26982695
if (UniController::IsCollectionEnabled()) {
26992696
ZeCollector* collector = reinterpret_cast<ZeCollector*>(global_data);
27002697
zet_metric_query_handle_t query = PrepareToAppendKernelCommand(
@@ -2721,8 +2718,8 @@ overhead::Init();
27212718
}
27222719

27232720
static void OnEnterCommandListAppendLaunchKernelIndirect(
2724-
ze_command_list_append_launch_kernel_indirect_params_t* params,
2725-
void* global_data, void** instance_data) {
2721+
ze_command_list_append_launch_kernel_indirect_params_t* params, void* global_data,
2722+
void** instance_data) {
27262723
if (UniController::IsCollectionEnabled()) {
27272724
ZeCollector* collector = reinterpret_cast<ZeCollector*>(global_data);
27282725
zet_metric_query_handle_t query = PrepareToAppendKernelCommand(
@@ -2833,8 +2830,8 @@ overhead::Init();
28332830
}
28342831

28352832
static void OnEnterCommandListAppendMemoryRangesBarrier(
2836-
ze_command_list_append_memory_ranges_barrier_params_t* params,
2837-
void* global_data, void** instance_data) {
2833+
ze_command_list_append_memory_ranges_barrier_params_t* params, void* global_data,
2834+
void** instance_data) {
28382835
if (UniController::IsCollectionEnabled()) {
28392836
ZeCollector* collector = reinterpret_cast<ZeCollector*>(global_data);
28402837
zet_metric_query_handle_t query = PrepareToAppendKernelCommand(
@@ -2861,8 +2858,8 @@ overhead::Init();
28612858
}
28622859

28632860
static void OnEnterCommandListAppendMemoryCopyRegion(
2864-
ze_command_list_append_memory_copy_region_params_t* params,
2865-
void* global_data, void** instance_data) {
2861+
ze_command_list_append_memory_copy_region_params_t* params, void* global_data,
2862+
void** instance_data) {
28662863
if (UniController::IsCollectionEnabled()) {
28672864
ZeCollector* collector = reinterpret_cast<ZeCollector*>(global_data);
28682865
zet_metric_query_handle_t query = PrepareToAppendKernelCommand(
@@ -2900,8 +2897,8 @@ overhead::Init();
29002897
}
29012898

29022899
static void OnEnterCommandListAppendMemoryCopyFromContext(
2903-
ze_command_list_append_memory_copy_from_context_params_t* params,
2904-
void* global_data, void** instance_data) {
2900+
ze_command_list_append_memory_copy_from_context_params_t* params, void* global_data,
2901+
void** instance_data) {
29052902
if (UniController::IsCollectionEnabled()) {
29062903
ZeCollector* collector = reinterpret_cast<ZeCollector*>(global_data);
29072904
zet_metric_query_handle_t query = PrepareToAppendKernelCommand(
@@ -2958,8 +2955,8 @@ overhead::Init();
29582955
}
29592956

29602957
static void OnEnterCommandListAppendImageCopyRegion(
2961-
ze_command_list_append_image_copy_region_params_t* params,
2962-
void* global_data, void** instance_data) {
2958+
ze_command_list_append_image_copy_region_params_t* params, void* global_data,
2959+
void** instance_data) {
29632960
if (UniController::IsCollectionEnabled()) {
29642961
ZeCollector* collector = reinterpret_cast<ZeCollector*>(global_data);
29652962
zet_metric_query_handle_t query = PrepareToAppendKernelCommand(
@@ -2986,8 +2983,8 @@ overhead::Init();
29862983
}
29872984

29882985
static void OnEnterCommandListAppendImageCopyToMemory(
2989-
ze_command_list_append_image_copy_to_memory_params_t* params,
2990-
void* global_data, void** instance_data) {
2986+
ze_command_list_append_image_copy_to_memory_params_t* params, void* global_data,
2987+
void** instance_data) {
29912988
if (UniController::IsCollectionEnabled()) {
29922989
ZeCollector* collector = reinterpret_cast<ZeCollector*>(global_data);
29932990
zet_metric_query_handle_t query = PrepareToAppendKernelCommand(
@@ -3015,8 +3012,8 @@ overhead::Init();
30153012
}
30163013

30173014
static void OnEnterCommandListAppendImageCopyFromMemory(
3018-
ze_command_list_append_image_copy_from_memory_params_t* params,
3019-
void* global_data, void** instance_data) {
3015+
ze_command_list_append_image_copy_from_memory_params_t* params, void* global_data,
3016+
void** instance_data) {
30203017
if (UniController::IsCollectionEnabled()) {
30213018
ZeCollector* collector = reinterpret_cast<ZeCollector*>(global_data);
30223019
zet_metric_query_handle_t query = PrepareToAppendKernelCommand(
@@ -3136,8 +3133,8 @@ overhead::Init();
31363133
}
31373134

31383135
static void OnEnterCommandQueueExecuteCommandLists(
3139-
ze_command_queue_execute_command_lists_params_t* params,
3140-
void* global_data, void** /*instance_data*/) {
3136+
ze_command_queue_execute_command_lists_params_t* params, void* global_data,
3137+
void** /*instance_data*/) {
31413138
ZeCollector* collector = reinterpret_cast<ZeCollector*>(global_data);
31423139

31433140
if (UniController::IsCollectionEnabled()) {
@@ -3152,7 +3149,7 @@ overhead::Init();
31523149
}
31533150

31543151
collector->PrepareToExecuteCommandLists(command_lists, command_list_count,
3155-
*(params->phCommandQueue), *(params->phFence));
3152+
*(params->phCommandQueue), *(params->phFence));
31563153
}
31573154
}
31583155
static void OnExitCommandQueueExecuteCommandLists(
@@ -3177,7 +3174,6 @@ overhead::Init();
31773174
}
31783175
}
31793176

3180-
31813177
static void OnExitCommandQueueSynchronize(ze_command_queue_synchronize_params_t* /*params*/,
31823178
ze_result_t result, void* global_data,
31833179
void** /*instance_data*/, std::vector<uint64_t>* kids) {
@@ -3225,7 +3221,7 @@ overhead::Init();
32253221
desc.context_ = *(params->phContext);
32263222
desc.device_ = *device;
32273223
desc.engine_ordinal_ = queue_desc->ordinal;
3228-
desc.engine_index_ = queue_desc->index;;
3224+
desc.engine_index_ = queue_desc->index;
32293225

32303226
collector->command_queues_.erase(*command_queue);
32313227
collector->command_queues_.insert({*command_queue, std::move(desc)});

sdk/src/utils/utils.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <unistd.h>
1717
#endif
1818

19+
#include <cstring>
1920
#include <stdint.h>
2021

2122
#include <fstream>
@@ -39,6 +40,17 @@
3940

4041
namespace utils {
4142

43+
// Duplicated from test/utils --- there are some useful methods there that can be pulled here as
44+
// needed.
45+
//-----
46+
template <typename T>
47+
inline void Zeroize(T& item) {
48+
static_assert(std::is_trivially_copyable<T>::value,
49+
"Can't zeroize an object that's not trivially copyable");
50+
std::memset(&item, 0, sizeof(T));
51+
}
52+
//-----
53+
4254
struct Comparator {
4355
template <typename T>
4456
bool operator()(const T& left, const T& right) const {

sdk/src/view_handler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,7 @@ inline void SetMemCpyIdsP2P(T& record, const ZeKernelCommandExecutionRecord& rec
668668
template <typename T>
669669
inline auto DoCommonMemCopy(bool p2p, const ZeKernelCommandExecutionRecord& rec) {
670670
T record;
671+
utils::Zeroize(record);
671672

672673
record._view_kind._view_kind = pti_view_kind::PTI_VIEW_DEVICE_GPU_MEM_COPY;
673674
if (p2p) record._view_kind._view_kind = pti_view_kind::PTI_VIEW_DEVICE_GPU_MEM_COPY_P2P;

0 commit comments

Comments
 (0)