Skip to content

Commit a3b8659

Browse files
Tarakarevu1zma2
andauthored
[unitrace] Fixed warnings (#444)
* Fixed warnings * Fixed UNitrace warnings * Addressed review comments * Addressed review comments * Update chromelogger.h * Update itt_collector.h * Update ze_collector.h * Update ze_metrics.h * Update tracer.h * Update unitrace.cc * Update itt_collector.h --------- Co-authored-by: Zhiqiang Ma <[email protected]>
1 parent 6999201 commit a3b8659

File tree

11 files changed

+69
-45
lines changed

11 files changed

+69
-45
lines changed

tools/unitrace/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ else()
2121
endif()
2222

2323
if(WIN32)
24-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++17 ")
24+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++17 /bigobj ")
2525
else()
2626
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -fvisibility=default")
2727
endif()

tools/unitrace/scripts/gen_tracing_callbacks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ def gen_enter_callback(f, func, command_list_func_list, command_queue_func_list,
439439
f.write(" auto phWaitEvents = *(params->p"+ name + ");\n")
440440
f.write(" auto numWaitEvents = *(params->p" + prev_name + ");\n")
441441
f.write(" while(numWaitEvents > 0) {\n")
442-
f.write(" str += std::to_string((long int)*phWaitEvents);\n")
442+
f.write(" str += std::to_string(reinterpret_cast<uintptr_t>(*phWaitEvents));\n")
443443
f.write(" numWaitEvents--;\n")
444444
f.write(" if (numWaitEvents > 0)\n")
445445
f.write(" str +=\", \";\n")

tools/unitrace/src/chromelogger.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,19 @@ static inline std::string GetHostName(void) {
3030
#ifdef _WIN32
3131
DWORD size = sizeof(hname);
3232
GetComputerNameA(hname, &size);
33-
#else
33+
#else /* _WIN32 */
3434
gethostname(hname, sizeof(hname));
35-
#endif
35+
#endif /* _WIN32 */
3636
hname[255] = 0;
3737
return hname;
3838
}
3939

40+
#ifdef _WIN32
41+
#define strdup _strdup
42+
#else /* _WIN32 */
43+
#define strdup strdup
44+
#endif /* _WIN32 */
45+
4046
static std::string EncodeURI(const std::string &input) {
4147
std::ostringstream encoded;
4248
encoded.fill('0');

tools/unitrace/src/itt/itt_collector.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,20 @@ ITT_EXTERN_C void ITTAPI __itt_task_begin(const __itt_domain *domain, __itt_id t
320320
}
321321

322322
ThreadTaskDescriptor desc;
323+
#ifdef _WIN32
324+
if (domain && domain->nameA) {
325+
strncpy_s(desc.domain, sizeof(desc.domain), domain->nameA, sizeof(desc.domain) - 2);
326+
}
327+
else {
328+
desc.domain[0] = 0;
329+
}
330+
if (name && name->strA) {
331+
strncpy_s(desc.domain, sizeof(desc.domain), domain->nameA, sizeof(desc.domain) - 2);
332+
}
333+
else {
334+
desc.name[0] = 0;
335+
}
336+
#else /* _WIN32 */
323337
if (domain && domain->nameA) {
324338
strncpy(desc.domain, domain->nameA, sizeof(desc.domain) - 2);
325339
}
@@ -332,6 +346,7 @@ ITT_EXTERN_C void ITTAPI __itt_task_begin(const __itt_domain *domain, __itt_id t
332346
else {
333347
desc.name[0] = 0;
334348
}
349+
#endif /* _WIN32 */
335350

336351
desc.start_time = UniTimer::GetHostTimestamp();
337352
desc.buff_size = 0;

tools/unitrace/src/levelzero/ze_collector.h

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,7 +1080,8 @@ inline std::string GetZeKernelCommandName(uint64_t id, const ze_group_count_t& g
10801080
kernel_command_properties_mutex_.lock_shared();
10811081
auto it = kernel_command_properties_->find(id);
10821082
if (it != kernel_command_properties_->end()) {
1083-
str = "\"" + std::move(utils::Demangle(it->second.name_.c_str())); // quote kernel name which may contain ","
1083+
str = "\"";
1084+
str += std::move(utils::Demangle(it->second.name_.c_str())); // quote kernel name which may contain ","
10841085
if (detailed) {
10851086
if (it->second.type_ == KERNEL_COMMAND_TYPE_COMPUTE) {
10861087
if (it->second.simd_width_ > 0) {
@@ -1504,7 +1505,6 @@ class ZeCollector {
15041505
if (local_device_submissions_.IsFinalized()) {
15051506
return;
15061507
}
1507-
ze_result_t status = ZE_RESULT_SUCCESS;
15081508

15091509
global_device_submissions_mutex_.lock_shared();
15101510
auto it = local_device_submissions_.commands_submitted_.begin();
@@ -1549,7 +1549,6 @@ class ZeCollector {
15491549
if (local_device_submissions_.IsFinalized()) {
15501550
return;
15511551
}
1552-
ze_result_t status = ZE_RESULT_SUCCESS;
15531552

15541553
global_device_submissions_mutex_.lock();
15551554
if (global_device_submissions_) {
@@ -1596,7 +1595,6 @@ class ZeCollector {
15961595
}
15971596

15981597
void FinalizeDeviceSubmissions(std::vector<uint64_t> *kids) {
1599-
ze_result_t status = ZE_RESULT_SUCCESS;
16001598

16011599
// Do not acquire any locks!
16021600
auto it = local_device_submissions_.commands_submitted_.begin();
@@ -1649,7 +1647,6 @@ class ZeCollector {
16491647
options_(options),
16501648
kcallback_(kcallback),
16511649
fcallback_(fcallback),
1652-
callback_data_(callback_data),
16531650
event_cache_(ZE_EVENT_POOL_FLAG_KERNEL_TIMESTAMP) {
16541651
data_dir_name_ = data_dir_name;
16551652
EnumerateAndSetupDevices();
@@ -1907,6 +1904,7 @@ class ZeCollector {
19071904
PTI_ASSERT(0);
19081905
break;
19091906
}
1907+
return ""; //in case of error returns empty string.
19101908
}
19111909

19121910
inline static std::string GetMetricUnits(const char* units) {
@@ -2408,7 +2406,7 @@ class ZeCollector {
24082406

24092407
void PrintCommandCompleted(const ZeCommand *command, uint64_t kernel_start, uint64_t kernel_end) {
24102408
std::string str("Thread ");
2411-
str += std::to_string(command->tid_) + " Device " + std::to_string((unsigned long)(command->device_)) +
2409+
str += std::to_string(command->tid_) + " Device " + std::to_string(reinterpret_cast<uintptr_t>(command->device_)) +
24122410
" : " + GetZeKernelCommandName(command->kernel_command_id_, command->group_count_, command->mem_size_) + " [ns] " +
24132411
std::to_string(command->append_time_) + " (append) " +
24142412
std::to_string(command->submit_time_) + " (submit) " +
@@ -3768,7 +3766,6 @@ class ZeCollector {
37683766
desc->metric_timer_frequency_ = cl->metric_timer_frequency_;
37693767
desc->metric_timer_mask_ = cl->metric_timer_mask_;
37703768
desc->device_ = cl->device_;
3771-
ze_context_handle_t context = cl->context_;
37723769

37733770
desc->group_count_ = {0, 0, 0};
37743771
desc->mem_size_ = 0;
@@ -4135,7 +4132,6 @@ class ZeCollector {
41354132
const ze_copy_region_t* region = *(params->psrcRegion);
41364133

41374134
if (region != nullptr) {
4138-
size_t bytes_transferred = region->width * region->height * (*(params->psrcPitch));
41394135
if (region->depth != 0) {
41404136
bytes_transferred *= region->depth;
41414137
}
@@ -4171,7 +4167,6 @@ class ZeCollector {
41714167
ZeCollector* collector = reinterpret_cast<ZeCollector*>(global_data);
41724168
if ((result == ZE_RESULT_SUCCESS) && (UniController::IsCollectionEnabled())) {
41734169
ze_context_handle_t src_context = *(params->phContextSrc);
4174-
ze_context_handle_t dst_context = nullptr;
41754170
collector->AppendMemoryCommandContext(MemoryCopyFromContext, *(params->psize),
41764171
src_context, *(params->psrcptr), nullptr, *(params->pdstptr), *(params->phSignalEvent), query,
41774172
*(params->phCommandList), kids);
@@ -4611,7 +4606,6 @@ class ZeCollector {
46114606

46124607
static void OnExitModuleCreate(ze_module_create_params_t* params, ze_result_t result, void* global_data, void** instance_user_data) {
46134608
if (result == ZE_RESULT_SUCCESS) {
4614-
ZeCollector* collector = reinterpret_cast<ZeCollector*>(global_data);
46154609
ze_module_handle_t mod = **(params->pphModule);
46164610
ze_device_handle_t device = *(params->phDevice);
46174611
size_t binary_size;
@@ -4632,7 +4626,6 @@ class ZeCollector {
46324626
}
46334627

46344628
static void OnEnterModuleDestroy(ze_module_destroy_params_t* params, void* global_data, void** instance_user_data) {
4635-
ZeCollector* collector = reinterpret_cast<ZeCollector*>(global_data);
46364629
ze_module_handle_t mod = *(params->phModule);
46374630
modules_on_devices_mutex_.lock();
46384631
modules_on_devices_.erase(mod);
@@ -4780,7 +4773,6 @@ typedef struct _zex_kernel_register_file_size_exp_t {
47804773
void* global_data, void** instance_data) {
47814774
if (result == ZE_RESULT_SUCCESS) {
47824775
if (UniController::IsCollectionEnabled()) {
4783-
ZeCollector* collector = reinterpret_cast<ZeCollector*>(global_data);
47844776
ZeKernelGroupSize group_size{*(params->pgroupSizeX), *(params->pgroupSizeY), *(params->pgroupSizeZ)};
47854777
kernel_command_properties_mutex_.lock();
47864778

@@ -4816,7 +4808,6 @@ typedef struct _zex_kernel_register_file_size_exp_t {
48164808

48174809
static void OnExitKernelDestroy(ze_kernel_destroy_params_t* params, ze_result_t result, void* global_data, void** instance_data) {
48184810
if (result == ZE_RESULT_SUCCESS) {
4819-
ZeCollector* collector = reinterpret_cast<ZeCollector*>(global_data);
48204811
kernel_command_properties_mutex_.lock();
48214812
active_kernel_properties_->erase(*(params->phKernel));
48224813
kernel_command_properties_mutex_.unlock();
@@ -4886,7 +4877,6 @@ typedef struct _zex_kernel_register_file_size_exp_t {
48864877
Logger *logger_ = nullptr;
48874878
OnZeKernelFinishCallback kcallback_ = nullptr;
48884879
OnZeFunctionFinishCallback fcallback_ = nullptr;
4889-
void* callback_data_ = nullptr;
48904880

48914881
mutable std::shared_mutex images_mutex_;
48924882
std::map<ze_image_handle_t, size_t> images_;

tools/unitrace/src/levelzero/ze_metrics.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "utils.h"
3232
#include "ze_utils.h"
3333
#include "pti_assert.h"
34+
#include <inttypes.h>
3435

3536

3637
constexpr static uint64_t min_dummy_instance_id = 1024 * 1024; // min dummy instance id if idle sampling is enabled
@@ -709,7 +710,7 @@ class ZeMetricProfiler {
709710
std::string line;
710711

711712
char offset[128];
712-
snprintf(offset, sizeof(offset), "0x%08lx", (it->first - rit->first));
713+
snprintf(offset, sizeof(offset), "%" PRIx64, (it->first - rit->first));
713714
line = std::string(std::max(int(field_sizes[0] - rit->second.first.length()), 0), ' ') +
714715
rit->second.first + ", ";
715716
logger_->Log(line);
@@ -971,6 +972,7 @@ class ZeMetricProfiler {
971972
PTI_ASSERT(0);
972973
break;
973974
}
975+
return ""; // in case of error returns empty string.
974976
}
975977

976978
inline static std::string GetMetricUnits(const char* units) {

tools/unitrace/src/opencl/cl_api_callbacks.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ static void clCompileProgramOnEnter(
149149
stream << " numInputHeaders = " << *(params->numInputHeaders);
150150
stream << " inputHeaders = " << *(params->inputHeaders);
151151
stream << " headerIncludeNames = " << *(params->headerIncludeNames);
152-
stream << " funcNotify = " << *(params->funcNotify);
152+
stream << " funcNotify = " << *reinterpret_cast<decltype(params->funcNotify)*>(params->funcNotify);
153153
stream << " userData = " << *(params->userData);
154154
stream << std::endl;
155155

@@ -202,7 +202,7 @@ static void clSetEventCallbackOnEnter(
202202
stream << " event = " << *(params->event);
203203
stream << " commandExecCallbackType = " <<
204204
*(params->commandExecCallbackType);
205-
stream << " funcNotify = " << *(params->funcNotify);
205+
stream << " funcNotify = " << *reinterpret_cast<decltype(params->funcNotify)*>(params->funcNotify);
206206
stream << " userData = " << *(params->userData);
207207
stream << std::endl;
208208

@@ -649,7 +649,7 @@ static void clEnqueueSVMFreeOnEnter(
649649
stream << " commandQueue = " << *(params->commandQueue);
650650
stream << " numSvmPointers = " << *(params->numSvmPointers);
651651
stream << " svmPointers = " << *(params->svmPointers);
652-
stream << " pfnFreeFunc = " << *(params->pfnFreeFunc);
652+
stream << " pfnFreeFunc = " << *reinterpret_cast<decltype(params->pfnFreeFunc)*>(params->pfnFreeFunc);
653653
stream << " userData = " << *(params->userData);
654654
stream << " numEventsInWaitList = " << *(params->numEventsInWaitList);
655655
stream << " eventWaitList = " << *(params->eventWaitList);
@@ -1642,7 +1642,7 @@ static void clCreateContextOnEnter(
16421642
stream << " properties = " << *(params->properties);
16431643
stream << " numDevices = " << *(params->numDevices);
16441644
stream << " devices = " << *(params->devices);
1645-
stream << " funcNotify = " << *(params->funcNotify);
1645+
stream << " funcNotify = " << *reinterpret_cast<decltype(params->funcNotify)*>(params->funcNotify);
16461646
stream << " userData = " << *(params->userData);
16471647
stream << " errcodeRet = " << *(params->errcodeRet);
16481648
stream << std::endl;
@@ -1986,7 +1986,7 @@ static void clCreateContextFromTypeOnEnter(
19861986

19871987
stream << " properties = " << *(params->properties);
19881988
stream << " deviceType = " << *(params->deviceType);
1989-
stream << " funcNotify = " << *(params->funcNotify);
1989+
stream << " funcNotify = " << *reinterpret_cast<decltype(params->funcNotify)*>(params->funcNotify);
19901990
stream << " userData = " << *(params->userData);
19911991
stream << " errcodeRet = " << *(params->errcodeRet);
19921992
stream << std::endl;
@@ -2228,7 +2228,7 @@ static void clLinkProgramOnEnter(
22282228
}
22292229
stream << " numInputPrograms = " << *(params->numInputPrograms);
22302230
stream << " inputPrograms = " << *(params->inputPrograms);
2231-
stream << " funcNotify = " << *(params->funcNotify);
2231+
stream << " funcNotify = " << *reinterpret_cast<decltype(params->funcNotify)*>(params->funcNotify);
22322232
stream << " userData = " << *(params->userData);
22332233
stream << " errcodeRet = " << *(params->errcodeRet);
22342234
stream << std::endl;
@@ -3363,7 +3363,7 @@ static void clEnqueueNativeKernelOnEnter(
33633363
stream << data->functionName << ":";
33643364

33653365
stream << " commandQueue = " << *(params->commandQueue);
3366-
stream << " userFunc = " << *(params->userFunc);
3366+
stream << " userFunc = " << *reinterpret_cast<decltype(params->userFunc)*>(params->userFunc);
33673367
stream << " args = " << *(params->args);
33683368
stream << " cbArgs = " << *(params->cbArgs);
33693369
stream << " numMemObjects = " << *(params->numMemObjects);
@@ -4058,7 +4058,7 @@ static void clSetMemObjectDestructorCallbackOnEnter(
40584058
stream << data->functionName << ":";
40594059

40604060
stream << " memobj = " << *(params->memobj);
4061-
stream << " funcNotify = " << *(params->funcNotify);
4061+
stream << " funcNotify = " << *reinterpret_cast<decltype(params->funcNotify)*>(params->funcNotify);
40624062
stream << " userData = " << *(params->userData);
40634063
stream << std::endl;
40644064

@@ -5435,7 +5435,7 @@ static void clBuildProgramOnEnter(
54355435
} else {
54365436
stream << " options = \"" << *(params->options) << "\"";
54375437
}
5438-
stream << " funcNotify = " << *(params->funcNotify);
5438+
stream << " funcNotify = " << *reinterpret_cast<decltype(params->funcNotify)*>(params->funcNotify);
54395439
stream << " userData = " << *(params->userData);
54405440
stream << std::endl;
54415441

tools/unitrace/src/opencl/cl_collector.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,6 @@ class ClCollector {
685685
options_(options),
686686
kcallback_(kcallback),
687687
fcallback_(fcallback),
688-
callback_data_(callback_data),
689688
data_dir_name_(data_dir_name) {
690689
PTI_ASSERT(device_ != nullptr);
691690
PTI_ASSERT(logger_ != nullptr);
@@ -857,7 +856,6 @@ class ClCollector {
857856
const std::lock_guard<std::mutex> lock(lock_);
858857

859858
cl_event event = instance->event;
860-
cl_int event_status = utils::cl::GetEventStatus(event);
861859
cl_command_queue queue = utils::cl::GetCommandQueue(event);
862860
PTI_ASSERT(queue != nullptr);
863861
cl_device_id device = utils::cl::GetDevice(queue);
@@ -945,7 +943,6 @@ class ClCollector {
945943

946944
inline cl_device_pci_bus_info_khr GetDevicePciInfo(cl_device_id device) {
947945
cl_device_pci_bus_info_khr pciInfo;
948-
cl_uint vendorId = 0 ;
949946
cl_int status = clGetDeviceInfo(device, CL_DEVICE_PCI_BUS_INFO_KHR, sizeof(cl_device_pci_bus_info_khr), &pciInfo, nullptr);
950947
PTI_ASSERT(status == CL_SUCCESS);
951948
return pciInfo;
@@ -1314,7 +1311,6 @@ class ClCollector {
13141311
collector->CalculateKernelLocalSize(params, &instance->props);
13151312

13161313
uint64_t base_addr = 0;
1317-
uint32_t addrbits = 0;
13181314
uint64_t size = 0;
13191315

13201316
status = clGetKernelInfo(kernel, CL_KERNEL_BINARY_GPU_ADDRESS_INTEL, 0, nullptr, &size);
@@ -1924,7 +1920,6 @@ class ClCollector {
19241920

19251921
OnClKernelFinishCallback kcallback_ = nullptr;
19261922
OnClFunctionFinishCallback fcallback_ = nullptr;
1927-
void* callback_data_ = nullptr;
19281923

19291924
std::mutex lock_;
19301925
ClKernelInfoMap kernel_info_map_;
@@ -1944,7 +1939,6 @@ class ClCollector {
19441939

19451940
cl_device_type device_type_ = CL_DEVICE_TYPE_ALL;
19461941

1947-
OnClFunctionFinishCallback callback_ = nullptr;
19481942

19491943
ClFunctionInfoMap function_info_map_;
19501944

@@ -2274,7 +2268,7 @@ cl_int clGetMemAllocInfoINTEL(cl_context context, const void *ptr, cl_mem_info_i
22742268

22752269
str += " context = " + std::to_string(uint64_t(context));
22762270
str += " ptr = " + std::to_string(uint64_t(ptr));
2277-
str += " param_name = " + param_name;
2271+
str += " param_name = " + std::to_string(param_name);
22782272
str += " param_value_size = " + std::to_string(param_value_size);
22792273
str += " param_value = " + std::to_string(uint64_t(param_value));
22802274
str += " param_value_size_ret = " + std::to_string(uint64_t(param_value_size_ret));

tools/unitrace/src/unitimer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class UniTimer {
7373
private:
7474
inline static uint64_t epoch_start_time_ = 0;
7575
#if defined(_WIN32)
76-
inline static LARGE_INTEGER frequency_{0};
76+
inline static LARGE_INTEGER frequency_{{0}};
7777
#endif /* _WIN32 */
7878
};
7979

0 commit comments

Comments
 (0)