From 1c1b2db9a902b1baf6bfff909afd17c13cb5adfe Mon Sep 17 00:00:00 2001 From: Oskar Hubert Weber Date: Wed, 18 Dec 2024 14:51:08 +0000 Subject: [PATCH] fix: allowing neo ULT build with optimization enabled 5/n - fix mismatched-new-delete warnings - fix initialization warnings - fix attempt to free a non-heap object warnings Related-To: NEO-8116 Signed-off-by: Oskar Hubert Weber --- .../core/test/unit_tests/sources/rtas/test_rtas.cpp | 9 ++++----- opencl/test/black_box_test/hello_world_opencl.cpp | 2 +- .../black_box_test/hello_world_opencl_tracing.cpp | 4 ++-- .../memory_manager/cl_memory_manager_tests.cpp | 10 +++++----- .../linux/os_compiler_cache_helper.cpp | 8 ++++++-- shared/source/os_interface/linux/os_time_linux.cpp | 12 +++++++++--- .../helpers/bindless_heaps_helper_tests.cpp | 2 +- .../os_interface/linux/drm_memory_manager_tests.cpp | 13 +++++++++++-- 8 files changed, 39 insertions(+), 21 deletions(-) diff --git a/level_zero/core/test/unit_tests/sources/rtas/test_rtas.cpp b/level_zero/core/test/unit_tests/sources/rtas/test_rtas.cpp index 39888e030f..bffbda4a25 100644 --- a/level_zero/core/test/unit_tests/sources/rtas/test_rtas.cpp +++ b/level_zero/core/test/unit_tests/sources/rtas/test_rtas.cpp @@ -349,11 +349,10 @@ TEST_F(RTASTest, GivenUnderlyingBuilderDestroySucceedsThenSuccessIsReturned) { } TEST_F(RTASTest, GivenUnderlyingBuilderDestroyFailsThenErrorIsReturned) { - RTASBuilder pRTASBuilder; + auto pRTASBuilder = std::make_unique(); builderDestroyExpImpl = &builderDestroyFail; - driverHandle->rtasLibraryHandle = std::make_unique(); - EXPECT_EQ(ZE_RESULT_ERROR_UNKNOWN, L0::zeRTASBuilderDestroyExp(pRTASBuilder.toHandle())); + EXPECT_EQ(ZE_RESULT_ERROR_UNKNOWN, L0::zeRTASBuilderDestroyExp(pRTASBuilder.get())); EXPECT_EQ(1u, builderDestroyFailCalled); } @@ -454,10 +453,10 @@ TEST_F(RTASTest, GivenUnderlyingParallelOperationDestroySucceedsThenSuccessIsRet } TEST_F(RTASTest, GivenUnderlyingParallelOperationDestroyFailsThenErrorIsReturned) { - RTASParallelOperation pParallelOperation; + auto pParallelOperation = std::make_unique(); parallelOperationDestroyExpImpl = ¶llelOperationDestroyFail; - EXPECT_EQ(ZE_RESULT_ERROR_UNKNOWN, L0::zeRTASParallelOperationDestroyExp(pParallelOperation.toHandle())); + EXPECT_EQ(ZE_RESULT_ERROR_UNKNOWN, L0::zeRTASParallelOperationDestroyExp(pParallelOperation.get())); EXPECT_EQ(1u, parallelOperationDestroyFailCalled); } diff --git a/opencl/test/black_box_test/hello_world_opencl.cpp b/opencl/test/black_box_test/hello_world_opencl.cpp index 53e814fd61..3bb4378fc5 100644 --- a/opencl/test/black_box_test/hello_world_opencl.cpp +++ b/opencl/test/black_box_test/hello_world_opencl.cpp @@ -19,7 +19,7 @@ int main(int argc, char **argv) { int retVal = 0; const char *fileName = "kernelOutput.txt"; cl_int err = 0; - unique_ptr platforms; + unique_ptr platforms; cl_device_id device_id = 0; cl_uint platformsCount = 0; cl_context context = NULL; diff --git a/opencl/test/black_box_test/hello_world_opencl_tracing.cpp b/opencl/test/black_box_test/hello_world_opencl_tracing.cpp index b6346fdce0..0f7fc377eb 100644 --- a/opencl/test/black_box_test/hello_world_opencl_tracing.cpp +++ b/opencl/test/black_box_test/hello_world_opencl_tracing.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 Intel Corporation + * Copyright (C) 2023-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -65,7 +65,7 @@ bool validateOutput(const std::stringstream &out) { } int main(int argc, char **argv) { - std::unique_ptr platforms; + std::unique_ptr platforms; cl_device_id deviceId = 0; cl_uint platformsCount = 0; cl_context context = nullptr; diff --git a/opencl/test/unit_test/memory_manager/cl_memory_manager_tests.cpp b/opencl/test/unit_test/memory_manager/cl_memory_manager_tests.cpp index 7756374d9c..dfe4c2ce2b 100644 --- a/opencl/test/unit_test/memory_manager/cl_memory_manager_tests.cpp +++ b/opencl/test/unit_test/memory_manager/cl_memory_manager_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2023 Intel Corporation + * Copyright (C) 2018-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -207,7 +207,7 @@ TEST(ClMemoryManagerTest, givenAllowedTilingWhenIsCopyRequiredIsCalledThenTrueIs imgInfo.slicePitch = imgInfo.rowPitch * imageDesc.image_height; imgInfo.size = imgInfo.slicePitch; - char memory; + char memory{}; EXPECT_TRUE(MockMemoryManager::isCopyRequired(imgInfo, &memory)); } @@ -233,7 +233,7 @@ TEST(ClMemoryManagerTest, givenDifferentRowPitchWhenIsCopyRequiredIsCalledThenTr imgInfo.slicePitch = imgInfo.rowPitch * imageDesc.image_height; imgInfo.size = imgInfo.slicePitch; - char memory[10]; + char memory[10] = {}; EXPECT_TRUE(MockMemoryManager::isCopyRequired(imgInfo, memory)); } @@ -259,7 +259,7 @@ TEST(ClMemoryManagerTest, givenDifferentSlicePitchAndTilingNotAllowedWhenIsCopyR imgInfo.rowPitch = imageDesc.image_width * surfaceFormat->surfaceFormat.imageElementSizeInBytes; imgInfo.slicePitch = imgInfo.rowPitch * imageDesc.image_height; imgInfo.size = imgInfo.slicePitch; - char memory[8]; + char memory[8] = {}; EXPECT_TRUE(MockMemoryManager::isCopyRequired(imgInfo, memory)); } @@ -284,7 +284,7 @@ TEST(ClMemoryManagerTest, givenNotCachelinAlignedPointerWhenIsCopyRequiredIsCall imgInfo.rowPitch = imageDesc.image_width * surfaceFormat->surfaceFormat.imageElementSizeInBytes; imgInfo.slicePitch = imgInfo.rowPitch * imageDesc.image_height; imgInfo.size = imgInfo.slicePitch; - char memory[8]; + char memory[8] = {}; EXPECT_TRUE(MockMemoryManager::isCopyRequired(imgInfo, &memory[1])); } diff --git a/shared/source/compiler_interface/linux/os_compiler_cache_helper.cpp b/shared/source/compiler_interface/linux/os_compiler_cache_helper.cpp index fbc23c712f..57527cc6c3 100644 --- a/shared/source/compiler_interface/linux/os_compiler_cache_helper.cpp +++ b/shared/source/compiler_interface/linux/os_compiler_cache_helper.cpp @@ -67,7 +67,9 @@ bool checkDefaultCacheDirSettings(std::string &cacheDir, NEO::EnvironmentVariabl } time_t getFileModificationTime(const std::string &path) { - struct stat st; + struct stat st { + 0, 0 + }; if (NEO::SysCalls::stat(path, &st) == 0) { return st.st_mtime; } @@ -75,7 +77,9 @@ time_t getFileModificationTime(const std::string &path) { } size_t getFileSize(const std::string &path) { - struct stat st; + struct stat st { + 0, 0 + }; if (NEO::SysCalls::stat(path, &st) == 0) { return static_cast(st.st_size); } diff --git a/shared/source/os_interface/linux/os_time_linux.cpp b/shared/source/os_interface/linux/os_time_linux.cpp index 0675ea5dbb..38567b01a7 100644 --- a/shared/source/os_interface/linux/os_time_linux.cpp +++ b/shared/source/os_interface/linux/os_time_linux.cpp @@ -29,7 +29,9 @@ OSTimeLinux::OSTimeLinux(OSInterface &osInterface, std::unique_ptr d } bool OSTimeLinux::getCpuTime(uint64_t *timestamp) { - struct timespec ts; + struct timespec ts { + 0, 0 + }; if (getTimeFunc(CLOCK_MONOTONIC_RAW, &ts)) { return false; @@ -41,7 +43,9 @@ bool OSTimeLinux::getCpuTime(uint64_t *timestamp) { } bool OSTime::getCpuTimeHost(uint64_t *timestamp) { - struct timespec ts; + struct timespec ts { + 0, 0 + }; auto ret = clock_gettime(CLOCK_MONOTONIC_RAW, &ts); @@ -51,7 +55,9 @@ bool OSTime::getCpuTimeHost(uint64_t *timestamp) { } double OSTimeLinux::getHostTimerResolution() const { - struct timespec ts; + struct timespec ts { + 0, 0 + }; if (resolutionFunc(CLOCK_MONOTONIC_RAW, &ts)) { return 0; } diff --git a/shared/test/unit_test/helpers/bindless_heaps_helper_tests.cpp b/shared/test/unit_test/helpers/bindless_heaps_helper_tests.cpp index dfe1d01caf..d058dbce0c 100644 --- a/shared/test/unit_test/helpers/bindless_heaps_helper_tests.cpp +++ b/shared/test/unit_test/helpers/bindless_heaps_helper_tests.cpp @@ -634,7 +634,7 @@ TEST_F(BindlessHeapsHelperTests, givenLocalMemorySupportWhenReservingMemoryForSp size_t reservationSize = MemoryConstants::pageSize64k; size_t alignment = MemoryConstants::pageSize64k; - memManager->localMemorySupported = {localMemSupported}; + memManager->localMemorySupported = std::vector{localMemSupported}; auto specialSshReservationSuccessful = bindlessHeapHelper->tryReservingMemoryForSpecialSsh(reservationSize, alignment); EXPECT_TRUE(specialSshReservationSuccessful); diff --git a/shared/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp b/shared/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp index cadadc8d54..117b0ffefd 100644 --- a/shared/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp +++ b/shared/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp @@ -5243,8 +5243,17 @@ TEST_F(DrmMemoryManagerTest, whenDebugFlagToNotFreeResourcesIsSpecifiedThenFreeI TestedDrmMemoryManager memoryManager(false, false, false, *executionEnvironment); size_t sizeIn = 1024llu; uint64_t gpuAddress = 0x1337llu; - DrmAllocation stackDrmAllocation(0u, 1u /*num gmms*/, AllocationType::buffer, nullptr, nullptr, gpuAddress, sizeIn, MemoryPool::system64KBPages); - memoryManager.freeGraphicsMemoryImpl(&stackDrmAllocation); + auto drmAllocation = std::make_unique(0u, 1u /*num gmms*/, AllocationType::buffer, nullptr, nullptr, gpuAddress, sizeIn, MemoryPool::system64KBPages); + memoryManager.freeGraphicsMemoryImpl(drmAllocation.get()); + + EXPECT_EQ(drmAllocation->getNumGmms(), 1u); + EXPECT_EQ(drmAllocation->getRootDeviceIndex(), 0u); + EXPECT_EQ(drmAllocation->getBOs().size(), EngineLimits::maxHandleCount); + EXPECT_EQ(drmAllocation->getAllocationType(), AllocationType::buffer); + EXPECT_EQ(drmAllocation->getGpuAddress(), gpuAddress); + EXPECT_EQ(drmAllocation->getUnderlyingBufferSize(), sizeIn); + EXPECT_EQ(drmAllocation->getMemoryPool(), MemoryPool::system64KBPages); + EXPECT_EQ(drmAllocation->getUnderlyingBuffer(), nullptr); } TEST_F(DrmMemoryManagerTest, given2MbPagesDisabledWhenWddmMemoryManagerIsCreatedThenAlignmentSelectorHasExpectedAlignments) {