From ef8921247c6cb7ffe75624320b5af0d59e4b65fd Mon Sep 17 00:00:00 2001 From: Kamil Kopryk Date: Mon, 15 Jan 2024 15:49:28 +0000 Subject: [PATCH] refactor: improve constexpr array usage Gcc with o2 flag will allocate constexpr array on stack. Static constexpr std::array will be initialized at compile time. Signed-off-by: Kamil Kopryk --- .../kernel/kernel_arg_buffer_tests.cpp | 18 +++++++++--------- .../offline_compiler/ocloc_api_tests.cpp | 4 ++-- .../ocloc_igc_facade_tests.cpp | 4 ++-- .../image/image_surface_state_tests.cpp | 8 ++++---- .../xe_hpc_core/test_encode_xe_hpc_core.cpp | 4 ++-- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/opencl/test/unit_test/kernel/kernel_arg_buffer_tests.cpp b/opencl/test/unit_test/kernel/kernel_arg_buffer_tests.cpp index 919604342f..5f62435843 100644 --- a/opencl/test/unit_test/kernel/kernel_arg_buffer_tests.cpp +++ b/opencl/test/unit_test/kernel/kernel_arg_buffer_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2023 Intel Corporation + * Copyright (C) 2018-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -558,10 +558,10 @@ TEST_F(KernelArgBufferTest, givenSetUnifiedMemoryExecInfoOnKernelWithIndirectSta pKernelInfo->kernelDescriptor.kernelAttributes.hasIndirectStatelessAccess = true; - constexpr std::array allocationTypes = {{{AllocationType::buffer, false}, - {AllocationType::buffer, true}, - {AllocationType::bufferHostMemory, false}, - {AllocationType::svmGpu, true}}}; + static constexpr std::array allocationTypes = {{{AllocationType::buffer, false}, + {AllocationType::buffer, true}, + {AllocationType::bufferHostMemory, false}, + {AllocationType::svmGpu, true}}}; GmmRequirements gmmRequirements{}; gmmRequirements.allowLargePages = true; gmmRequirements.preferCompressed = false; @@ -600,10 +600,10 @@ TEST_F(KernelArgBufferTest, givenSVMAllocsManagerWithCompressedSVMAllocationsWhe DebugManagerStateRestore debugRestorer; debugManager.flags.EnableStatelessCompression.set(1); - constexpr std::array allocationTypes = {{{AllocationType::buffer, false}, - {AllocationType::buffer, true}, - {AllocationType::bufferHostMemory, false}, - {AllocationType::svmGpu, true}}}; + static constexpr std::array allocationTypes = {{{AllocationType::buffer, false}, + {AllocationType::buffer, true}, + {AllocationType::bufferHostMemory, false}, + {AllocationType::svmGpu, true}}}; GmmRequirements gmmRequirements{}; gmmRequirements.allowLargePages = true; gmmRequirements.preferCompressed = false; diff --git a/opencl/test/unit_test/offline_compiler/ocloc_api_tests.cpp b/opencl/test/unit_test/offline_compiler/ocloc_api_tests.cpp index 99d05df42b..6c4e1704b6 100644 --- a/opencl/test/unit_test/offline_compiler/ocloc_api_tests.cpp +++ b/opencl/test/unit_test/offline_compiler/ocloc_api_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2023 Intel Corporation + * Copyright (C) 2020-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -753,7 +753,7 @@ TEST(OclocApiTests, GivenCommandWithoutArgsWhenOclocIsInvokedThenHelpIsPrinted) } TEST(OclocApiTests, GivenHelpArgumentWhenOclocIsInvokedThenHelpIsPrinted) { - constexpr std::array flagsToTest = {"-h", "--help"}; + static constexpr std::array flagsToTest = {"-h", "--help"}; for (const auto helpFlag : flagsToTest) { const char *argv[] = { "ocloc", diff --git a/opencl/test/unit_test/offline_compiler/ocloc_igc_facade_tests.cpp b/opencl/test/unit_test/offline_compiler/ocloc_igc_facade_tests.cpp index 519fa26697..8f66f1d1fe 100644 --- a/opencl/test/unit_test/offline_compiler/ocloc_igc_facade_tests.cpp +++ b/opencl/test/unit_test/offline_compiler/ocloc_igc_facade_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022-2023 Intel Corporation + * Copyright (C) 2022-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -115,7 +115,7 @@ TEST_F(OclocIgcFacadeTest, GivenFailingCreationOfIgcDeviceContextWhenPreparingIg } TEST_F(OclocIgcFacadeTest, GivenInvalidIgcDeviceContextWhenPreparingIgcThenFailureIsReported) { - constexpr std::array invalidReturnFlags = { + static constexpr std::array invalidReturnFlags = { &MockOclocIgcFacade::shouldReturnInvalidIgcPlatformHandle, &MockOclocIgcFacade::shouldReturnInvalidGTSystemInfoHandle, &MockOclocIgcFacade::shouldReturnInvalidIgcFeaturesAndWorkaroundsHandle}; diff --git a/shared/test/unit_test/image/image_surface_state_tests.cpp b/shared/test/unit_test/image/image_surface_state_tests.cpp index 7895b760ab..9f624f966e 100644 --- a/shared/test/unit_test/image/image_surface_state_tests.cpp +++ b/shared/test/unit_test/image/image_surface_state_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2023 Intel Corporation + * Copyright (C) 2020-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -256,7 +256,7 @@ HWTEST_F(ImageWidthTest, givenMediaBlockWhenProgrammingWidthInSurfaceStateThenCo auto renderSurfaceState = FamilyType::cmdInitRenderSurfaceState; { surfaceFormatInfo.imageElementSizeInBytes = 1u; - constexpr std::array params = {{ + static constexpr std::array params = {{ {1, 1}, {2, 1}, {3, 1}, @@ -268,7 +268,7 @@ HWTEST_F(ImageWidthTest, givenMediaBlockWhenProgrammingWidthInSurfaceStateThenCo } { surfaceFormatInfo.imageElementSizeInBytes = 2u; - constexpr std::array params = {{ + static constexpr std::array params = {{ {1, 1}, {2, 1}, {3, 2}, @@ -280,7 +280,7 @@ HWTEST_F(ImageWidthTest, givenMediaBlockWhenProgrammingWidthInSurfaceStateThenCo } { surfaceFormatInfo.imageElementSizeInBytes = 4u; - constexpr std::array params = {{ + static constexpr std::array params = {{ {1, 1}, {2, 2}, {3, 3}, diff --git a/shared/test/unit_test/xe_hpc_core/test_encode_xe_hpc_core.cpp b/shared/test/unit_test/xe_hpc_core/test_encode_xe_hpc_core.cpp index 15a1f8eb4e..19fcc38a95 100644 --- a/shared/test/unit_test/xe_hpc_core/test_encode_xe_hpc_core.cpp +++ b/shared/test/unit_test/xe_hpc_core/test_encode_xe_hpc_core.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021-2023 Intel Corporation + * Copyright (C) 2021-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -91,7 +91,7 @@ XE_HPC_CORETEST_F(CommandEncodeXeHpcCoreTest, givenDebugVariableSetwhenProgramin const GraphicsAllocation allocation(0, AllocationType::buffer, nullptr, gpuVa, 0, 4096, MemoryPool::localMemory, MemoryManager::maxOsContextCount); - constexpr std::array expectedSizes = {{ + static constexpr std::array expectedSizes = {{ MemoryConstants::cacheLineSize - 1, MemoryConstants::cacheLineSize, MemoryConstants::cacheLineSize + 1,