Skip to content

Commit 9574c98

Browse files
authored
Fix/type mismatch warnings (#290)
Fixes several hundred type mismatch warnings during build on Windows and Linux. See the related Jira task comments for details about the warning types. Related-To: VLCLJ-2555 Signed-off-by: Eric Mortensen <[email protected]>
1 parent ae3cdb1 commit 9574c98

File tree

144 files changed

+2392
-2230
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

144 files changed

+2392
-2230
lines changed

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,11 @@ else()
348348
set(CMAKE_NEWLINE "\n")
349349
endif()
350350

351+
if (MSVC)
352+
add_compile_options(/W4)
353+
else()
354+
add_compile_options(-Wsign-compare -Wnarrowing -Wsign-conversion -Wfloat-conversion -Wconversion)
355+
endif()
351356

352357
option(ENABLE_ZESYSMAN
353358
"Enables build of zesysman"

conformance_tests/core/test_barrier/src/test_barrier.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ namespace lzt = level_zero_tests;
1717

1818
namespace {
1919

20+
using lzt::to_u32;
21+
2022
class zeCommandListAppendBarrierTests : public ::testing::Test {
2123
public:
2224
void run(bool isImmediate) {
@@ -79,7 +81,7 @@ void RunAppendingBarrierWithEvents(bool isImmediate) {
7981
auto bundle = lzt::create_command_bundle(context, device, 0, isImmediate);
8082

8183
EXPECT_ZE_RESULT_SUCCESS(zeCommandListAppendBarrier(
82-
bundle.list, nullptr, events.size(), events.data()));
84+
bundle.list, nullptr, to_u32(events.size()), events.data()));
8385
for (auto &ev : events) {
8486
lzt::signal_event_from_host(ev);
8587
}
@@ -114,11 +116,11 @@ void RunAppendingBarrierWithSignalEventAndWaitEvents(bool isImmediate) {
114116
auto bundle = lzt::create_command_bundle(context, device, 0, isImmediate);
115117
auto events_initial = events;
116118
EXPECT_ZE_RESULT_SUCCESS(zeCommandListAppendBarrier(
117-
bundle.list, event, events.size(), events.data()));
119+
bundle.list, event, to_u32(events.size()), events.data()));
118120
for (auto &ev : events) {
119121
lzt::signal_event_from_host(ev);
120122
}
121-
for (int i = 0; i < events.size(); i++) {
123+
for (size_t i = 0U; i < events.size(); i++) {
122124
ASSERT_EQ(events[i], events_initial[i]);
123125
}
124126
ep.destroy_events(events);
@@ -151,8 +153,8 @@ void AppendMemoryRangesBarrierTest(
151153
context)};
152154

153155
EXPECT_ZE_RESULT_SUCCESS(zeCommandListAppendMemoryRangesBarrier(
154-
command_list, ranges.size(), range_sizes.data(), ranges.data(),
155-
signaling_event, waiting_events.size(), waiting_events.data()));
156+
command_list, to_u32(ranges.size()), range_sizes.data(), ranges.data(),
157+
signaling_event, to_u32(waiting_events.size()), waiting_events.data()));
156158

157159
for (auto &ev : waiting_events) {
158160
lzt::signal_event_from_host(ev);
@@ -233,7 +235,7 @@ void RunAppendingMemoryRangesBarrierWaitEvents(bool isImmediate) {
233235
auto wait_events_initial = waiting_events;
234236
AppendMemoryRangesBarrierTest(context, device, bundle.list, nullptr,
235237
waiting_events);
236-
for (int i = 0; i < waiting_events.size(); i++) {
238+
for (size_t i = 0U; i < waiting_events.size(); i++) {
237239
ASSERT_EQ(waiting_events[i], wait_events_initial[i]);
238240
}
239241
ep.destroy_events(waiting_events);
@@ -427,7 +429,7 @@ void RunEventSignaledWhenAppendingMemoryRangesBarrierThenHostDetectsEvent(
427429
ZE_EVENT_SCOPE_FLAG_HOST);
428430
lzt::append_memory_copy(bundle.list, dev_mem, inpa.data(), xfer_size,
429431
nullptr);
430-
lzt::append_memory_ranges_barrier(bundle.list, ranges.size(),
432+
lzt::append_memory_ranges_barrier(bundle.list, to_u32(ranges.size()),
431433
range_sizes.data(), ranges.data(),
432434
event_barrier_to_host, 0, nullptr);
433435
lzt::append_memory_copy(bundle.list, host_mem, dev_mem, xfer_size, nullptr);
@@ -484,7 +486,7 @@ void RunAppendingMemoryRangesBarrierWaitsForEventsWhenHostAndSendSignals(
484486
lzt::append_memory_copy(bundle.list, dev_mem, inpa.data(), xfer_size,
485487
nullptr);
486488
lzt::append_signal_event(bundle.list, events_to_barrier[1]);
487-
lzt::append_memory_ranges_barrier(bundle.list, ranges.size(),
489+
lzt::append_memory_ranges_barrier(bundle.list, to_u32(ranges.size()),
488490
range_sizes.data(), ranges.data(), nullptr,
489491
num_events, events_to_barrier.data());
490492
lzt::append_memory_copy(bundle.list, host_mem, dev_mem, xfer_size, nullptr);
@@ -546,7 +548,7 @@ LZT_TEST_P(
546548
auto bundle = lzt::create_command_bundle(
547549
context, device, 0, ZE_COMMAND_QUEUE_MODE_DEFAULT,
548550
ZE_COMMAND_QUEUE_PRIORITY_NORMAL, 0, 0, 0, isImmediate);
549-
size_t num_int = 1000;
551+
uint32_t num_int = 1000;
550552
void *dev_buff = lzt::allocate_device_memory((num_int * sizeof(int)), 1, 0, 0,
551553
device, context);
552554
void *host_buff =
@@ -559,7 +561,7 @@ LZT_TEST_P(
559561
const int addval_1 = -100;
560562
const int val_1 = 50000;
561563
int val = val_1;
562-
for (size_t i = 0; i < num_int; i++) {
564+
for (uint32_t i = 0; i < num_int; i++) {
563565
p_host[i] = val;
564566
val += addval_1;
565567
}
@@ -616,7 +618,7 @@ LZT_TEST_P(
616618
const std::vector<size_t> range_sizes{num_int * sizeof(int),
617619
num_int * sizeof(int)};
618620
std::vector<const void *> ranges{dev_buff, host_buff};
619-
lzt::append_memory_ranges_barrier(bundle.list, ranges.size(),
621+
lzt::append_memory_ranges_barrier(bundle.list, to_u32(ranges.size()),
620622
range_sizes.data(), ranges.data(),
621623
nullptr, 0, nullptr);
622624
} else if (barrier_type == BT_GLOBAL_BARRIER) {
@@ -640,7 +642,7 @@ LZT_TEST_P(
640642
lzt::close_command_list(bundle.list);
641643
lzt::execute_and_sync_command_bundle(bundle, UINT64_MAX);
642644
val = (2 * val_1) + addval_2;
643-
for (size_t i = 0; i < num_int; i++) {
645+
for (uint32_t i = 0; i < num_int; i++) {
644646
EXPECT_EQ(p_host[i], val);
645647
val += (2 * addval_1);
646648
}

conformance_tests/core/test_cmdlist/src/test_cmdlist.cpp

Lines changed: 46 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ namespace lzt = level_zero_tests;
2222

2323
namespace {
2424

25+
using lzt::to_int;
26+
using lzt::to_u32;
27+
using lzt::to_u8;
28+
2529
using cmdListVec = std::vector<ze_command_list_handle_t>;
2630
using cmdQueueVec = std::vector<ze_command_queue_handle_t>;
2731

@@ -158,7 +162,7 @@ class zeCommandListResetTests : public ::testing::Test {
158162
lzt::append_barrier(bundle.list);
159163

160164
uint8_t pattern = 0xAA;
161-
int pattern_size = 1;
165+
size_t pattern_size = 1;
162166
auto memory_fill_mem = lzt::allocate_shared_memory(size);
163167
memset(memory_fill_mem, 0, size);
164168
lzt::append_memory_fill(bundle.list, memory_fill_mem, &pattern,
@@ -186,7 +190,7 @@ class zeCommandListResetTests : public ::testing::Test {
186190
ze_kernel_handle_t kernel =
187191
lzt::create_function(module, "cmdlist_add_constant");
188192
lzt::set_group_size(kernel, 1, 1, 1);
189-
ze_group_count_t args = {static_cast<uint32_t>(size), 1, 1};
193+
ze_group_count_t args = {to_u32(size), 1, 1};
190194

191195
const int addval = 10;
192196
auto kernel_buffer = lzt::allocate_shared_memory(size * sizeof(int));
@@ -231,12 +235,12 @@ class zeCommandListResetTests : public ::testing::Test {
231235
if (execute_all_commands || is_immediate) {
232236
lzt::validate_data_pattern(host_mem, size, 1);
233237
if (lzt::image_support()) {
234-
EXPECT_EQ(0, compare_data_pattern(*dest_host_image_ptr,
235-
img_ptr->dflt_host_image_, 0, 0,
236-
img_ptr->dflt_host_image_.width(),
237-
img_ptr->dflt_host_image_.height(), 0,
238-
0, img_ptr->dflt_host_image_.width(),
239-
img_ptr->dflt_host_image_.height()));
238+
EXPECT_EQ(0, compare_data_pattern(
239+
*dest_host_image_ptr, img_ptr->dflt_host_image_, 0U,
240+
0U, img_ptr->dflt_host_image_.width(),
241+
img_ptr->dflt_host_image_.height(), 0U, 0U,
242+
img_ptr->dflt_host_image_.width(),
243+
img_ptr->dflt_host_image_.height()));
240244
delete img_ptr;
241245
delete dest_host_image_ptr;
242246
}
@@ -252,12 +256,12 @@ class zeCommandListResetTests : public ::testing::Test {
252256
EXPECT_EQ(static_cast<uint8_t *>(memory_fill_mem)[i], 0);
253257
}
254258
if (lzt::image_support()) {
255-
EXPECT_NE(0, compare_data_pattern(*dest_host_image_ptr,
256-
img_ptr->dflt_host_image_, 0, 0,
257-
img_ptr->dflt_host_image_.width(),
258-
img_ptr->dflt_host_image_.height(), 0,
259-
0, img_ptr->dflt_host_image_.width(),
260-
img_ptr->dflt_host_image_.height()));
259+
EXPECT_NE(0, compare_data_pattern(
260+
*dest_host_image_ptr, img_ptr->dflt_host_image_, 0U,
261+
0U, img_ptr->dflt_host_image_.width(),
262+
img_ptr->dflt_host_image_.height(), 0U, 0U,
263+
img_ptr->dflt_host_image_.width(),
264+
img_ptr->dflt_host_image_.height()));
261265
delete img_ptr;
262266
delete dest_host_image_ptr;
263267
}
@@ -343,17 +347,17 @@ LZT_TEST(zeCommandListReuseTests,
343347
lzt::append_memory_copy(cmdlist_mem_zero, host_buffer, device_buffer, size);
344348
lzt::close_command_list(cmdlist_mem_zero);
345349

346-
const int num_execute = 5;
347-
for (int i = 0; i < num_execute; i++) {
350+
const uint32_t num_execute = 5;
351+
for (uint32_t i = 0U; i < num_execute; i++) {
348352
lzt::execute_command_lists(cmdq, 1, &cmdlist_mem_zero, nullptr);
349353
lzt::synchronize(cmdq, UINT64_MAX);
350-
for (int j = 0; j < size; j++)
354+
for (size_t j = 0U; j < size; j++)
351355
ASSERT_EQ(static_cast<uint8_t *>(host_buffer)[j], 0x0)
352356
<< "Memory Set did not match.";
353357

354358
lzt::execute_command_lists(cmdq, 1, &cmdlist_mem_set, nullptr);
355359
lzt::synchronize(cmdq, UINT64_MAX);
356-
for (int j = 0; j < size; j++)
360+
for (size_t j = 0U; j < size; j++)
357361
ASSERT_EQ(static_cast<uint8_t *>(host_buffer)[j], 0x1)
358362
<< "Memory Set did not match.";
359363
}
@@ -447,7 +451,7 @@ void RunWhenResetThenVerifyOnlySubsequentInstructionsExecuted(
447451
std::vector<uint8_t> val;
448452
for (size_t i = 0; i < num_instr; i++) {
449453
buffer.push_back(lzt::allocate_shared_memory(size));
450-
val.push_back(static_cast<uint8_t>(i + 1));
454+
val.push_back(to_u8(i + 1));
451455
}
452456

453457
// Begin with num_instr command list instructions, reset and reduce by one
@@ -525,7 +529,7 @@ LZT_TEST_P(zeCommandListFlagTests,
525529
auto host_memory = lzt::allocate_host_memory(size);
526530
auto device = lzt::zeDevice::get_instance()->get_device();
527531
uint8_t pattern = 0xAB;
528-
const int pattern_size = 1;
532+
const size_t pattern_size = 1;
529533
ze_command_list_flags_t flags = std::get<0>(GetParam());
530534
bool is_immediate = std::get<1>(GetParam());
531535
auto cmd_bundle = lzt::create_command_bundle(device, flags, is_immediate);
@@ -597,7 +601,7 @@ RunGivenCommandListWithMultipleAppendMemoryCopiesFollowedByResetInLoopTest(
597601
temp1 = static_cast<uint8_t *>(host_memory_src);
598602
temp2 = static_cast<uint8_t *>(host_memory_dst);
599603
for (uint32_t i = 0; i < max_copy_count; i++) {
600-
temp1[i] = i;
604+
temp1[i] = to_u8(i);
601605
temp2[i] = 0;
602606
}
603607
for (uint32_t i = 0; i < max_copy_count; i++) {
@@ -635,7 +639,7 @@ LZT_TEST(
635639
zeCommandListAppendMemoryCopyTest,
636640
GivenCommandListWithMultipleAppendMemoryCopiesFollowedByResetInLoopThenSuccessIsReturnedWithSharedSystemAllocator) {
637641
SKIP_IF_SHARED_SYSTEM_ALLOC_UNSUPPORTED();
638-
for (int i = 1; i < 4; ++i) {
642+
for (uint32_t i = 1; i < 4; ++i) {
639643
std::bitset<2> bits(i);
640644
RunGivenCommandListWithMultipleAppendMemoryCopiesFollowedByResetInLoopTest(
641645
bits[1], bits[0]);
@@ -722,7 +726,7 @@ RunGivenTwoCommandQueuesHavingCommandListsWithScratchSpaceThenSuccessIsReturnedT
722726
size, is_shared_system_dst);
723727

724728
uint8_t pattern = 0xAB;
725-
const int pattern_size = 1;
729+
const size_t pattern_size = 1;
726730
uint32_t num_iterations = 2;
727731

728732
auto context = lzt::get_default_context();
@@ -765,7 +769,8 @@ RunGivenTwoCommandQueuesHavingCommandListsWithScratchSpaceThenSuccessIsReturnedT
765769
&offsetBuffer);
766770
// if groupSize is greater then memory count, then at least one thread group
767771
// should be dispatched
768-
uint32_t threadGroup = arraySize / groupSize > 1 ? arraySize / groupSize : 1;
772+
uint32_t threadGroup =
773+
arraySize / groupSize > 1 ? to_u32(arraySize / groupSize) : 1;
769774
ze_group_count_t thread_group_dimensions = {threadGroup, 1, 1};
770775

771776
for (uint32_t i = 0; i < num_iterations; i++) {
@@ -863,7 +868,7 @@ LZT_TEST(
863868
zeCommandListAppendMemoryCopyTest,
864869
GivenTwoCommandQueuesHavingCommandListsWithScratchSpaceThenSuccessIsReturnedWithSharedSystemAllocator) {
865870
SKIP_IF_SHARED_SYSTEM_ALLOC_UNSUPPORTED();
866-
for (int i = 1; i < 8; ++i) {
871+
for (uint32_t i = 1; i < 8; ++i) {
867872
std::bitset<3> bits(i);
868873
RunGivenTwoCommandQueuesHavingCommandListsWithScratchSpaceThenSuccessIsReturnedTest(
869874
bits[2], bits[1], bits[0]);
@@ -930,11 +935,12 @@ class zeCommandListEventCounterTests : public lzt::zeEventPoolTests {
930935
};
931936

932937
static void RunAppendLaunchKernelEvent(cmdListVec cmdlist, cmdQueueVec cmdqueue,
933-
ze_event_handle_t event, int num_cmdlist,
934-
void *buffer, const size_t size) {
938+
ze_event_handle_t event,
939+
size_t num_cmdlist, void *buffer,
940+
const size_t size) {
935941

936942
const int addval = 10;
937-
const int num_iterations = 100;
943+
const uint32_t num_iterations = 100;
938944
int addval2 = 0;
939945
const uint64_t timeout = UINT64_MAX - 1;
940946

@@ -949,28 +955,28 @@ static void RunAppendLaunchKernelEvent(cmdListVec cmdlist, cmdQueueVec cmdqueue,
949955

950956
memset(buffer, 0x0, num_cmdlist * size * sizeof(int));
951957

952-
for (int n = 0; n < num_cmdlist; n++) {
958+
for (size_t n = 0; n < num_cmdlist; n++) {
953959
int *p_dev = static_cast<int *>(buffer);
954960
p_dev += (n * size);
955961
lzt::set_argument_value(kernel, 0, sizeof(p_dev), &p_dev);
956962
lzt::set_argument_value(kernel, 1, sizeof(addval), &addval);
957963
ze_group_count_t tg;
958-
tg.groupCountX = static_cast<uint32_t>(size);
964+
tg.groupCountX = to_u32(size);
959965
tg.groupCountY = 1;
960966
tg.groupCountZ = 1;
961967

962968
lzt::append_launch_function(cmdlist[n], kernel, &tg, nullptr, 0, nullptr);
963969

964970
totalVal[n] = 0;
965-
for (int i = 0; i < (num_iterations - 1); i++) {
971+
for (uint32_t i = 0; i < (num_iterations - 1); i++) {
966972
addval2 = lzt::generate_value<int>() & 0xFFFF;
967973
totalVal[n] += addval2;
968974
lzt::set_argument_value(kernel, 1, sizeof(addval2), &addval2);
969975

970976
lzt::append_launch_function(cmdlist[n], kernel, &tg, nullptr, 0, nullptr);
971977
}
972978
addval2 = lzt::generate_value<int>() & 0xFFFF;
973-
;
979+
974980
totalVal[n] += addval2;
975981
lzt::set_argument_value(kernel, 1, sizeof(addval2), &addval2);
976982
if (n == 0) {
@@ -985,7 +991,7 @@ static void RunAppendLaunchKernelEvent(cmdListVec cmdlist, cmdQueueVec cmdqueue,
985991

986992
EXPECT_ZE_RESULT_SUCCESS(zeEventHostSynchronize(event, timeout));
987993

988-
for (int n = 0; n < num_cmdlist; n++) {
994+
for (uint32_t n = 0; n < num_cmdlist; n++) {
989995
for (size_t i = 0; i < size; i++) {
990996
EXPECT_EQ(static_cast<int *>(buffer)[(n * size) + i],
991997
(addval + totalVal[n]));
@@ -999,7 +1005,7 @@ static void RunAppendLaunchKernelEvent(cmdListVec cmdlist, cmdQueueVec cmdqueue,
9991005
static void RunAppendLaunchKernelEventL0SharedAlloc(cmdListVec cmdlist,
10001006
cmdQueueVec cmdqueue,
10011007
ze_event_handle_t event,
1002-
int num_cmdlist,
1008+
size_t num_cmdlist,
10031009
const size_t size) {
10041010
void *buffer = lzt::allocate_shared_memory(num_cmdlist * size * sizeof(int));
10051011
RunAppendLaunchKernelEvent(cmdlist, cmdqueue, event, num_cmdlist, buffer,
@@ -1010,7 +1016,7 @@ static void RunAppendLaunchKernelEventL0SharedAlloc(cmdListVec cmdlist,
10101016
static void RunAppendLaunchKernelEventHostMalloc(cmdListVec cmdlist,
10111017
cmdQueueVec cmdqueue,
10121018
ze_event_handle_t event,
1013-
int num_cmdlist,
1019+
size_t num_cmdlist,
10141020
const size_t size) {
10151021
void *buffer = malloc(num_cmdlist * size * sizeof(int));
10161022
ASSERT_NE(nullptr, buffer);
@@ -1022,7 +1028,7 @@ static void RunAppendLaunchKernelEventHostMalloc(cmdListVec cmdlist,
10221028
static void RunAppendLaunchKernelEventHostNew(cmdListVec cmdlist,
10231029
cmdQueueVec cmdqueue,
10241030
ze_event_handle_t event,
1025-
int num_cmdlist,
1031+
size_t num_cmdlist,
10261032
const size_t size) {
10271033
int *buffer = new int[num_cmdlist * size];
10281034
ASSERT_NE(nullptr, buffer);
@@ -1034,7 +1040,7 @@ static void RunAppendLaunchKernelEventHostNew(cmdListVec cmdlist,
10341040
static void RunAppendLaunchKernelEventHostUniquePtr(cmdListVec cmdlist,
10351041
cmdQueueVec cmdqueue,
10361042
ze_event_handle_t event,
1037-
int num_cmdlist,
1043+
size_t num_cmdlist,
10381044
const size_t size) {
10391045
std::unique_ptr<int[]> buffer(new int[num_cmdlist * size]);
10401046
ASSERT_NE(nullptr, buffer);
@@ -1045,7 +1051,7 @@ static void RunAppendLaunchKernelEventHostUniquePtr(cmdListVec cmdlist,
10451051
static void RunAppendLaunchKernelEventHostSharedPtr(cmdListVec cmdlist,
10461052
cmdQueueVec cmdqueue,
10471053
ze_event_handle_t event,
1048-
int num_cmdlist,
1054+
size_t num_cmdlist,
10491055
const size_t size) {
10501056
std::shared_ptr<int[]> buffer(new int[num_cmdlist * size]);
10511057
ASSERT_NE(nullptr, buffer);
@@ -1054,7 +1060,7 @@ static void RunAppendLaunchKernelEventHostSharedPtr(cmdListVec cmdlist,
10541060
}
10551061

10561062
typedef void (*RunAppendLaunchKernelEventFunc)(cmdListVec, cmdQueueVec,
1057-
ze_event_handle_t, int,
1063+
ze_event_handle_t, size_t,
10581064
const size_t);
10591065

10601066
static void
@@ -1068,7 +1074,7 @@ RunAppendLaunchKernelEventLoop(cmdListVec cmdlist, cmdQueueVec cmdqueue,
10681074
}
10691075

10701076
constexpr size_t size = 16;
1071-
for (int i = 1; i <= cmdlist.size(); i++) {
1077+
for (size_t i = 1; i <= cmdlist.size(); i++) {
10721078
LOG_INFO << "Testing " << i << " command list(s)";
10731079
func(cmdlist, cmdqueue, event, i, size);
10741080
}

0 commit comments

Comments
 (0)