diff --git a/level_zero/core/test/unit_tests/sources/device/test_l0_device.cpp b/level_zero/core/test/unit_tests/sources/device/test_l0_device.cpp index 095cf92fc0..b0c7f37830 100644 --- a/level_zero/core/test/unit_tests/sources/device/test_l0_device.cpp +++ b/level_zero/core/test/unit_tests/sources/device/test_l0_device.cpp @@ -811,7 +811,7 @@ TEST_F(DeviceHostPointerTest, givenHostPointerNotAcceptedByKernelThenNewAllocati EXPECT_EQ(NEO::AllocationType::internalHostMemory, allocation->getAllocationType()); EXPECT_EQ(rootDeviceIndex, allocation->getRootDeviceIndex()); EXPECT_NE(allocation->getUnderlyingBuffer(), reinterpret_cast(buffer)); - EXPECT_EQ(allocation->getUnderlyingBufferSize(), size); + EXPECT_EQ(alignUp(size, MemoryConstants::pageSize), allocation->getUnderlyingBufferSize()); EXPECT_EQ(0, memcmp(buffer, allocation->getUnderlyingBuffer(), size)); neoDevice->getMemoryManager()->freeGraphicsMemory(allocation); diff --git a/level_zero/core/test/unit_tests/sources/kernel/test_kernel.cpp b/level_zero/core/test/unit_tests/sources/kernel/test_kernel.cpp index 28c4a5dc35..059653f5b6 100644 --- a/level_zero/core/test/unit_tests/sources/kernel/test_kernel.cpp +++ b/level_zero/core/test/unit_tests/sources/kernel/test_kernel.cpp @@ -701,8 +701,9 @@ TEST_F(KernelImmutableDataTests, givenKernelInitializedWithPrivateMemoryThenPriv EXPECT_NE(nullptr, kernel->privateMemoryGraphicsAllocation); - size_t expectedSize = perHwThreadPrivateMemorySizeRequested * - device->getNEODevice()->getDeviceInfo().computeUnitsUsedForScratch; + size_t expectedSize = alignUp(perHwThreadPrivateMemorySizeRequested * + device->getNEODevice()->getDeviceInfo().computeUnitsUsedForScratch, + MemoryConstants::pageSize); EXPECT_EQ(expectedSize, kernel->privateMemoryGraphicsAllocation->getUnderlyingBufferSize()); } diff --git a/opencl/source/command_queue/enqueue_fill_buffer.h b/opencl/source/command_queue/enqueue_fill_buffer.h index 86949c800d..bb682ceb0e 100644 --- a/opencl/source/command_queue/enqueue_fill_buffer.h +++ b/opencl/source/command_queue/enqueue_fill_buffer.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2023 Intel Corporation + * Copyright (C) 2018-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -42,10 +42,10 @@ cl_int CommandQueueHw::enqueueFillBuffer( if (patternSize == 1) { int patternInt = (uint32_t)((*(uint8_t *)pattern << 24) | (*(uint8_t *)pattern << 16) | (*(uint8_t *)pattern << 8) | *(uint8_t *)pattern); - memcpy_s(patternAllocation->getUnderlyingBuffer(), sizeof(int), &patternInt, sizeof(int)); + memcpy_s(patternAllocation->getUnderlyingBuffer(), sizeof(uint32_t), &patternInt, sizeof(uint32_t)); } else if (patternSize == 2) { int patternInt = (uint32_t)((*(uint16_t *)pattern << 16) | *(uint16_t *)pattern); - memcpy_s(patternAllocation->getUnderlyingBuffer(), sizeof(int), &patternInt, sizeof(int)); + memcpy_s(patternAllocation->getUnderlyingBuffer(), sizeof(uint32_t), &patternInt, sizeof(uint32_t)); } else { memcpy_s(patternAllocation->getUnderlyingBuffer(), patternSize, pattern, patternSize); } diff --git a/opencl/source/command_queue/enqueue_svm.h b/opencl/source/command_queue/enqueue_svm.h index 98d777ed67..248b09dfaf 100644 --- a/opencl/source/command_queue/enqueue_svm.h +++ b/opencl/source/command_queue/enqueue_svm.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2023 Intel Corporation + * Copyright (C) 2018-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -502,10 +502,10 @@ cl_int CommandQueueHw::enqueueSVMMemFill(void *svmPtr, if (patternSize == 1) { int patternInt = (uint32_t)((*(uint8_t *)pattern << 24) | (*(uint8_t *)pattern << 16) | (*(uint8_t *)pattern << 8) | *(uint8_t *)pattern); - memcpy_s(patternAllocation->getUnderlyingBuffer(), sizeof(int), &patternInt, sizeof(int)); + memcpy_s(patternAllocation->getUnderlyingBuffer(), sizeof(uint32_t), &patternInt, sizeof(uint32_t)); } else if (patternSize == 2) { int patternInt = (uint32_t)((*(uint16_t *)pattern << 16) | *(uint16_t *)pattern); - memcpy_s(patternAllocation->getUnderlyingBuffer(), sizeof(int), &patternInt, sizeof(int)); + memcpy_s(patternAllocation->getUnderlyingBuffer(), sizeof(uint32_t), &patternInt, sizeof(uint32_t)); } else { memcpy_s(patternAllocation->getUnderlyingBuffer(), patternSize, pattern, patternSize); } diff --git a/opencl/test/unit_test/command_queue/enqueue_kernel_2_tests.cpp b/opencl/test/unit_test/command_queue/enqueue_kernel_2_tests.cpp index ec3345367b..c157179ad8 100644 --- a/opencl/test/unit_test/command_queue/enqueue_kernel_2_tests.cpp +++ b/opencl/test/unit_test/command_queue/enqueue_kernel_2_tests.cpp @@ -361,8 +361,8 @@ HWCMDTEST_P(IGFX_GEN8_CORE, EnqueueScratchSpaceTests, GivenKernelRequiringScratc EXPECT_EQ(gsHaddress + ScratchSpaceConstants::scratchSpaceOffsetFor64Bit, graphicsAllocation->getGpuAddress()); } - auto allocationSize = scratchSize * pDevice->getDeviceInfo().computeUnitsUsedForScratch; - EXPECT_EQ(graphicsAllocation->getUnderlyingBufferSize(), allocationSize); + auto allocationSize = alignUp(scratchSize * pDevice->getDeviceInfo().computeUnitsUsedForScratch, MemoryConstants::pageMask); + EXPECT_EQ(allocationSize, graphicsAllocation->getUnderlyingBufferSize()); // Generically validate this command Parse::template validateCommand(cmdList.begin(), itorCmd); diff --git a/opencl/test/unit_test/command_queue/enqueue_svm_mem_fill_tests.cpp b/opencl/test/unit_test/command_queue/enqueue_svm_mem_fill_tests.cpp index 15f1fc383b..24978c2061 100644 --- a/opencl/test/unit_test/command_queue/enqueue_svm_mem_fill_tests.cpp +++ b/opencl/test/unit_test/command_queue/enqueue_svm_mem_fill_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2023 Intel Corporation + * Copyright (C) 2018-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -140,7 +140,7 @@ HWTEST_P(EnqueueSvmMemFillTest, givenEnqueueSVMMemFillWhenUsingFillBufferBuilder } void validateInput(const BuiltinOpParams &conf) const override { auto patternAllocation = conf.srcMemObj->getMultiGraphicsAllocation().getDefaultGraphicsAllocation(); - EXPECT_EQ(patternSize, patternAllocation->getUnderlyingBufferSize()); + EXPECT_EQ(MemoryConstants::pageSize, patternAllocation->getUnderlyingBufferSize()); EXPECT_EQ(0, memcmp(pattern, patternAllocation->getUnderlyingBuffer(), patternSize)); }; const void *pattern; diff --git a/opencl/test/unit_test/command_stream/cl_command_stream_receiver_tests.cpp b/opencl/test/unit_test/command_stream/cl_command_stream_receiver_tests.cpp index be91b54673..ae19ec0745 100644 --- a/opencl/test/unit_test/command_stream/cl_command_stream_receiver_tests.cpp +++ b/opencl/test/unit_test/command_stream/cl_command_stream_receiver_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2023 Intel Corporation + * Copyright (C) 2018-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -91,12 +91,12 @@ TEST_F(CommandStreamReceiverMultiRootDeviceTest, WhenCreatingCommandStreamGraphi commandStreamReceiver->ensureCommandBufferAllocation(commandStream, 100u, 0u); EXPECT_EQ(allocation, commandStream.getGraphicsAllocation()); - EXPECT_EQ(128u, commandStream.getMaxAvailableSpace()); + EXPECT_EQ(MemoryConstants::pageSize, commandStream.getMaxAvailableSpace()); EXPECT_EQ(expectedRootDeviceIndex, commandStream.getGraphicsAllocation()->getRootDeviceIndex()); - commandStreamReceiver->ensureCommandBufferAllocation(commandStream, 1024u, 0u); + commandStreamReceiver->ensureCommandBufferAllocation(commandStream, MemoryConstants::pageSize64k, 0u); EXPECT_NE(allocation, commandStream.getGraphicsAllocation()); - EXPECT_EQ(0u, commandStream.getMaxAvailableSpace() % MemoryConstants::pageSize64k); + EXPECT_EQ(0u, commandStream.getMaxAvailableSpace() % MemoryConstants::pageSize); EXPECT_EQ(expectedRootDeviceIndex, commandStream.getGraphicsAllocation()->getRootDeviceIndex()); mockMemoryManager->freeGraphicsMemory(commandStream.getGraphicsAllocation()); diff --git a/shared/source/memory_manager/os_agnostic_memory_manager.cpp b/shared/source/memory_manager/os_agnostic_memory_manager.cpp index 9e8ccd111e..05aac2636c 100644 --- a/shared/source/memory_manager/os_agnostic_memory_manager.cpp +++ b/shared/source/memory_manager/os_agnostic_memory_manager.cpp @@ -27,7 +27,7 @@ #include "shared/source/memory_manager/memory_allocation.h" #include "shared/source/memory_manager/residency.h" #include "shared/source/os_interface/os_context.h" - +#include "shared/source/os_interface/product_helper.h" namespace NEO { struct OsHandleOsAgnostic : OsHandle { }; @@ -62,30 +62,32 @@ bool OsAgnosticMemoryManager::is64kbPagesEnabled(const HardwareInfo *hwInfo) { } GraphicsAllocation *OsAgnosticMemoryManager::allocateGraphicsMemoryWithAlignment(const AllocationData &allocationData) { - auto sizeAligned = alignUp(allocationData.size, MemoryConstants::pageSize); + auto alignment = alignUpNonZero(allocationData.alignment, MemoryConstants::pageSize); + auto sizeAligned = alignUp(allocationData.size, alignment); MemoryAllocation *memoryAllocation = nullptr; - if (fakeBigAllocations && allocationData.size > bigAllocation) { + if (fakeBigAllocations && sizeAligned > bigAllocation) { memoryAllocation = createMemoryAllocation( - allocationData.type, nullptr, reinterpret_cast(dummyAddress), dummyAddress, allocationData.size, counter, + allocationData.type, nullptr, reinterpret_cast(dummyAddress), dummyAddress, sizeAligned, counter, MemoryPool::system4KBPages, allocationData.rootDeviceIndex, allocationData.flags.uncacheable, allocationData.flags.flushL3, false); counter++; return memoryAllocation; } - auto alignment = allocationData.alignment; if (allocationData.type == AllocationType::svmCpu) { - alignment = MemoryConstants::pageSize2M; - sizeAligned = alignUp(allocationData.size, MemoryConstants::pageSize2M); + auto &rootDeviceEnvironment = *executionEnvironment.rootDeviceEnvironments[allocationData.rootDeviceIndex]; + auto &productHelper = rootDeviceEnvironment.getHelper(); + alignment = productHelper.getSvmCpuAlignment(); + sizeAligned = alignUp(allocationData.size, alignment); } - + auto cpuAllocationSize = sizeAligned; if (GraphicsAllocation::isDebugSurfaceAllocationType(allocationData.type)) { - sizeAligned *= allocationData.storageInfo.getNumBanks(); + cpuAllocationSize *= allocationData.storageInfo.getNumBanks(); } - auto ptr = allocateSystemMemory(sizeAligned, alignment ? alignUp(alignment, MemoryConstants::pageSize) : MemoryConstants::pageSize); + auto ptr = allocateSystemMemory(cpuAllocationSize, alignment); if (ptr != nullptr) { - memoryAllocation = createMemoryAllocation(allocationData.type, ptr, ptr, reinterpret_cast(ptr), allocationData.size, + memoryAllocation = createMemoryAllocation(allocationData.type, ptr, ptr, reinterpret_cast(ptr), sizeAligned, counter, MemoryPool::system4KBPages, allocationData.rootDeviceIndex, allocationData.flags.uncacheable, allocationData.flags.flushL3, false); if (allocationData.type == AllocationType::svmCpu) { diff --git a/shared/test/unit_test/command_stream/aub_command_stream_receiver_2_tests.cpp b/shared/test/unit_test/command_stream/aub_command_stream_receiver_2_tests.cpp index bcdac12df2..9a0755c9a8 100644 --- a/shared/test/unit_test/command_stream/aub_command_stream_receiver_2_tests.cpp +++ b/shared/test/unit_test/command_stream/aub_command_stream_receiver_2_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2023 Intel Corporation + * Copyright (C) 2018-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -70,7 +70,8 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenForcedB aubCsr->getFlatBatchBufferHelper().flattenBatchBuffer(aubCsr->getRootDeviceIndex(), batchBuffer, sizeBatchBuffer, DispatchMode::immediateDispatch, pDevice->getDeviceBitfield()), [&](GraphicsAllocation *ptr) { memoryManager->freeGraphicsMemory(ptr); }); EXPECT_NE(nullptr, flatBatchBuffer->getUnderlyingBuffer()); - EXPECT_EQ(alignUp(128u + 128u, MemoryConstants::pageSize), sizeBatchBuffer); + size_t expectedAlignedSize = alignUp(128u, MemoryConstants::pageSize) + alignUp(128u, MemoryConstants::pageSize); + EXPECT_EQ(expectedAlignedSize, sizeBatchBuffer); memoryManager->freeGraphicsMemory(commandBuffer); memoryManager->freeGraphicsMemory(chainedBatchBuffer); diff --git a/shared/test/unit_test/command_stream/command_stream_receiver_tests.cpp b/shared/test/unit_test/command_stream/command_stream_receiver_tests.cpp index be00c40693..d12d4e6e8e 100644 --- a/shared/test/unit_test/command_stream/command_stream_receiver_tests.cpp +++ b/shared/test/unit_test/command_stream/command_stream_receiver_tests.cpp @@ -815,7 +815,10 @@ HWTEST_F(CommandStreamReceiverTest, givenOverrideCsrAllocationSizeWhenCreatingCo bool ret = commandStreamReceiver.createPreemptionAllocation(); ASSERT_TRUE(ret); - EXPECT_EQ(static_cast(overrideSize), commandStreamReceiver.preemptionAllocation->getUnderlyingBufferSize()); + auto &gfxCoreHelper = pDevice->getGfxCoreHelper(); + auto aligment = gfxCoreHelper.getPreemptionAllocationAlignment(); + size_t expectedAlignedSize = alignUp(overrideSize, aligment); + EXPECT_EQ(expectedAlignedSize, commandStreamReceiver.preemptionAllocation->getUnderlyingBufferSize()); } HWTEST_F(CommandStreamReceiverTest, whenCreatingPreemptionAllocationForBcsThenNoAllocationIsCreated) { @@ -2068,11 +2071,11 @@ TEST_F(CommandStreamReceiverTest, givenMinimumSizeDoesNotExceedCurrentWhenCallin commandStreamReceiver->ensureCommandBufferAllocation(commandStream, 100u, 0u); EXPECT_EQ(allocation, commandStream.getGraphicsAllocation()); - EXPECT_EQ(128u, commandStream.getMaxAvailableSpace()); + EXPECT_EQ(MemoryConstants::pageSize, commandStream.getMaxAvailableSpace()); commandStreamReceiver->ensureCommandBufferAllocation(commandStream, 128u, 0u); EXPECT_EQ(allocation, commandStream.getGraphicsAllocation()); - EXPECT_EQ(128u, commandStream.getMaxAvailableSpace()); + EXPECT_EQ(MemoryConstants::pageSize, commandStream.getMaxAvailableSpace()); memoryManager->freeGraphicsMemory(commandStream.getGraphicsAllocation()); } @@ -2081,7 +2084,7 @@ TEST_F(CommandStreamReceiverTest, givenMinimumSizeExceedsCurrentWhenCallingEnsur GraphicsAllocation *allocation = memoryManager->allocateGraphicsMemoryWithProperties({commandStreamReceiver->getRootDeviceIndex(), 128u, AllocationType::commandBuffer, pDevice->getDeviceBitfield()}); LinearStream commandStream{allocation}; - commandStreamReceiver->ensureCommandBufferAllocation(commandStream, 129u, 0u); + commandStreamReceiver->ensureCommandBufferAllocation(commandStream, MemoryConstants::pageSize + 1, 0u); EXPECT_NE(allocation, commandStream.getGraphicsAllocation()); memoryManager->freeGraphicsMemory(commandStream.getGraphicsAllocation()); } @@ -2090,11 +2093,13 @@ TEST_F(CommandStreamReceiverTest, givenMinimumSizeExceedsCurrentWhenCallingEnsur GraphicsAllocation *allocation = memoryManager->allocateGraphicsMemoryWithProperties({commandStreamReceiver->getRootDeviceIndex(), 128u, AllocationType::commandBuffer, pDevice->getDeviceBitfield()}); LinearStream commandStream{allocation}; - commandStreamReceiver->ensureCommandBufferAllocation(commandStream, 129u, 0u); + commandStreamReceiver->ensureCommandBufferAllocation(commandStream, MemoryConstants::pageSize + 1, 0u); + EXPECT_EQ(MemoryConstants::pageSize64k, commandStream.getGraphicsAllocation()->getUnderlyingBufferSize()); EXPECT_EQ(MemoryConstants::pageSize64k, commandStream.getMaxAvailableSpace()); commandStreamReceiver->ensureCommandBufferAllocation(commandStream, MemoryConstants::pageSize64k + 1u, 0u); + EXPECT_EQ(2 * MemoryConstants::pageSize64k, commandStream.getGraphicsAllocation()->getUnderlyingBufferSize()); EXPECT_EQ(2 * MemoryConstants::pageSize64k, commandStream.getMaxAvailableSpace()); @@ -2108,7 +2113,7 @@ TEST_F(CommandStreamReceiverTest, givenForceCommandBufferAlignmentWhenEnsureComm GraphicsAllocation *allocation = memoryManager->allocateGraphicsMemoryWithProperties({commandStreamReceiver->getRootDeviceIndex(), 128u, AllocationType::commandBuffer, pDevice->getDeviceBitfield()}); LinearStream commandStream{allocation}; - commandStreamReceiver->ensureCommandBufferAllocation(commandStream, 129u, 0u); + commandStreamReceiver->ensureCommandBufferAllocation(commandStream, MemoryConstants::pageSize + 1, 0u); EXPECT_EQ(2 * MemoryConstants::megaByte, commandStream.getGraphicsAllocation()->getUnderlyingBufferSize()); EXPECT_EQ(2 * MemoryConstants::megaByte, commandStream.getMaxAvailableSpace()); @@ -2119,7 +2124,7 @@ TEST_F(CommandStreamReceiverTest, givenAdditionalAllocationSizeWhenCallingEnsure GraphicsAllocation *allocation = memoryManager->allocateGraphicsMemoryWithProperties({commandStreamReceiver->getRootDeviceIndex(), 128u, AllocationType::commandBuffer, pDevice->getDeviceBitfield()}); LinearStream commandStream{allocation}; - commandStreamReceiver->ensureCommandBufferAllocation(commandStream, 129u, 350u); + commandStreamReceiver->ensureCommandBufferAllocation(commandStream, MemoryConstants::pageSize + 1, 350u); EXPECT_NE(allocation, commandStream.getGraphicsAllocation()); EXPECT_EQ(MemoryConstants::pageSize64k, commandStream.getGraphicsAllocation()->getUnderlyingBufferSize()); EXPECT_EQ(MemoryConstants::pageSize64k - 350u, commandStream.getMaxAvailableSpace()); diff --git a/shared/test/unit_test/program/program_initialization_tests.cpp b/shared/test/unit_test/program/program_initialization_tests.cpp index 4081214b2e..463eea249b 100644 --- a/shared/test/unit_test/program/program_initialization_tests.cpp +++ b/shared/test/unit_test/program/program_initialization_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2023 Intel Corporation + * Copyright (C) 2020-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -7,6 +7,7 @@ #include "shared/source/compiler_interface/external_functions.h" #include "shared/source/gmm_helper/gmm.h" +#include "shared/source/helpers/aligned_memory.h" #include "shared/source/helpers/blit_helper.h" #include "shared/source/helpers/local_memory_access_modes.h" #include "shared/source/program/program_initialization.h" @@ -33,9 +34,10 @@ TEST(AllocateGlobalSurfaceTest, GivenSvmAllocsManagerWhenGlobalsAreNotExportedTh initData.resize(64, 7U); GraphicsAllocation *alloc = nullptr; + size_t aligmentSize = alignUp(initData.size(), MemoryConstants::pageSize); alloc = allocateGlobalsSurface(&svmAllocsManager, device, initData.size(), 0u, true /* constant */, nullptr /* linker input */, initData.data()); ASSERT_NE(nullptr, alloc); - ASSERT_EQ(initData.size(), alloc->getUnderlyingBufferSize()); + ASSERT_EQ(aligmentSize, alloc->getUnderlyingBufferSize()); EXPECT_EQ(0, memcmp(alloc->getUnderlyingBuffer(), initData.data(), initData.size())); EXPECT_EQ(nullptr, svmAllocsManager.getSVMAlloc(reinterpret_cast(static_cast(alloc->getGpuAddress())))); EXPECT_EQ(AllocationType::constantSurface, alloc->getAllocationType()); @@ -43,7 +45,7 @@ TEST(AllocateGlobalSurfaceTest, GivenSvmAllocsManagerWhenGlobalsAreNotExportedTh alloc = allocateGlobalsSurface(&svmAllocsManager, device, initData.size(), 0u, false /* constant */, nullptr /* linker input */, initData.data()); ASSERT_NE(nullptr, alloc); - ASSERT_EQ(initData.size(), alloc->getUnderlyingBufferSize()); + ASSERT_EQ(aligmentSize, alloc->getUnderlyingBufferSize()); EXPECT_EQ(0, memcmp(alloc->getUnderlyingBuffer(), initData.data(), initData.size())); EXPECT_EQ(nullptr, svmAllocsManager.getSVMAlloc(reinterpret_cast(static_cast(alloc->getGpuAddress())))); EXPECT_EQ(AllocationType::globalSurface, alloc->getAllocationType()); @@ -51,7 +53,7 @@ TEST(AllocateGlobalSurfaceTest, GivenSvmAllocsManagerWhenGlobalsAreNotExportedTh alloc = allocateGlobalsSurface(&svmAllocsManager, device, initData.size(), 0u, true /* constant */, &emptyLinkerInput, initData.data()); ASSERT_NE(nullptr, alloc); - ASSERT_EQ(initData.size(), alloc->getUnderlyingBufferSize()); + ASSERT_EQ(aligmentSize, alloc->getUnderlyingBufferSize()); EXPECT_EQ(0, memcmp(alloc->getUnderlyingBuffer(), initData.data(), initData.size())); EXPECT_EQ(nullptr, svmAllocsManager.getSVMAlloc(reinterpret_cast(static_cast(alloc->getGpuAddress())))); EXPECT_EQ(AllocationType::constantSurface, alloc->getAllocationType()); @@ -59,7 +61,7 @@ TEST(AllocateGlobalSurfaceTest, GivenSvmAllocsManagerWhenGlobalsAreNotExportedTh alloc = allocateGlobalsSurface(&svmAllocsManager, device, initData.size(), 0u, false /* constant */, &emptyLinkerInput, initData.data()); ASSERT_NE(nullptr, alloc); - ASSERT_EQ(initData.size(), alloc->getUnderlyingBufferSize()); + ASSERT_EQ(aligmentSize, alloc->getUnderlyingBufferSize()); EXPECT_EQ(0, memcmp(alloc->getUnderlyingBuffer(), initData.data(), initData.size())); EXPECT_EQ(nullptr, svmAllocsManager.getSVMAlloc(reinterpret_cast(static_cast(alloc->getGpuAddress())))); EXPECT_EQ(AllocationType::globalSurface, alloc->getAllocationType()); @@ -80,6 +82,7 @@ TEST(AllocateGlobalSurfaceTest, GivenSvmAllocsManagerWhenGlobalsAreExportedThenM std::vector initData; initData.resize(64, 7U); GraphicsAllocation *alloc = nullptr; + size_t expectedAlignedSize = alignUp(initData.size(), MemoryConstants::pageSize); alloc = allocateGlobalsSurface(&svmAllocsManager, device, initData.size(), 0u, true /* constant */, &linkerInputExportGlobalConstants, initData.data()); ASSERT_NE(nullptr, alloc); @@ -94,7 +97,7 @@ TEST(AllocateGlobalSurfaceTest, GivenSvmAllocsManagerWhenGlobalsAreExportedThenM alloc = allocateGlobalsSurface(&svmAllocsManager, device, initData.size(), 0u, true /* constant */, &linkerInputExportGlobalVariables, initData.data()); ASSERT_NE(nullptr, alloc); - ASSERT_EQ(initData.size(), alloc->getUnderlyingBufferSize()); + ASSERT_EQ(expectedAlignedSize, alloc->getUnderlyingBufferSize()); EXPECT_EQ(0, memcmp(alloc->getUnderlyingBuffer(), initData.data(), initData.size())); EXPECT_EQ(nullptr, svmAllocsManager.getSVMAlloc(reinterpret_cast(static_cast(alloc->getGpuAddress())))); EXPECT_EQ(AllocationType::constantSurface, alloc->getAllocationType()); @@ -102,7 +105,7 @@ TEST(AllocateGlobalSurfaceTest, GivenSvmAllocsManagerWhenGlobalsAreExportedThenM alloc = allocateGlobalsSurface(&svmAllocsManager, device, initData.size(), 0u, false /* constant */, &linkerInputExportGlobalConstants, initData.data()); ASSERT_NE(nullptr, alloc); - ASSERT_EQ(initData.size(), alloc->getUnderlyingBufferSize()); + ASSERT_EQ(expectedAlignedSize, alloc->getUnderlyingBufferSize()); EXPECT_EQ(0, memcmp(alloc->getUnderlyingBuffer(), initData.data(), initData.size())); EXPECT_EQ(nullptr, svmAllocsManager.getSVMAlloc(reinterpret_cast(static_cast(alloc->getGpuAddress())))); EXPECT_EQ(AllocationType::globalSurface, alloc->getAllocationType()); @@ -130,31 +133,32 @@ TEST(AllocateGlobalSurfaceTest, GivenNullSvmAllocsManagerWhenGlobalsAreExportedT std::vector initData; initData.resize(64, 7U); GraphicsAllocation *alloc = nullptr; + size_t expectedAlignedSize = alignUp(initData.size(), MemoryConstants::pageSize); alloc = allocateGlobalsSurface(nullptr, device, initData.size(), 0u, true /* constant */, &linkerInputExportGlobalConstants, initData.data()); ASSERT_NE(nullptr, alloc); - ASSERT_EQ(initData.size(), alloc->getUnderlyingBufferSize()); + ASSERT_EQ(expectedAlignedSize, alloc->getUnderlyingBufferSize()); EXPECT_EQ(0, memcmp(alloc->getUnderlyingBuffer(), initData.data(), initData.size())); EXPECT_EQ(AllocationType::constantSurface, alloc->getAllocationType()); device.getMemoryManager()->freeGraphicsMemory(alloc); alloc = allocateGlobalsSurface(nullptr, device, initData.size(), 0u, true /* constant */, &linkerInputExportGlobalVariables, initData.data()); ASSERT_NE(nullptr, alloc); - ASSERT_EQ(initData.size(), alloc->getUnderlyingBufferSize()); + ASSERT_EQ(expectedAlignedSize, alloc->getUnderlyingBufferSize()); EXPECT_EQ(0, memcmp(alloc->getUnderlyingBuffer(), initData.data(), initData.size())); EXPECT_EQ(AllocationType::constantSurface, alloc->getAllocationType()); device.getMemoryManager()->freeGraphicsMemory(alloc); alloc = allocateGlobalsSurface(nullptr, device, initData.size(), 0u, false /* constant */, &linkerInputExportGlobalConstants, initData.data()); ASSERT_NE(nullptr, alloc); - ASSERT_EQ(initData.size(), alloc->getUnderlyingBufferSize()); + ASSERT_EQ(expectedAlignedSize, alloc->getUnderlyingBufferSize()); EXPECT_EQ(0, memcmp(alloc->getUnderlyingBuffer(), initData.data(), initData.size())); EXPECT_EQ(AllocationType::globalSurface, alloc->getAllocationType()); device.getMemoryManager()->freeGraphicsMemory(alloc); alloc = allocateGlobalsSurface(nullptr, device, initData.size(), 0u, false /* constant */, &linkerInputExportGlobalVariables, initData.data()); ASSERT_NE(nullptr, alloc); - ASSERT_EQ(initData.size(), alloc->getUnderlyingBufferSize()); + ASSERT_EQ(expectedAlignedSize, alloc->getUnderlyingBufferSize()); EXPECT_EQ(0, memcmp(alloc->getUnderlyingBuffer(), initData.data(), initData.size())); EXPECT_EQ(AllocationType::globalSurface, alloc->getAllocationType()); device.getMemoryManager()->freeGraphicsMemory(alloc); @@ -251,10 +255,10 @@ TEST(AllocateGlobalSurfaceTest, whenAllocatingGlobalSurfaceWithNonZeroZeroInitSi std::fill(initData.begin() + 32, initData.end(), 16u); // this data should not be transfered GraphicsAllocation *alloc = nullptr; size_t zeroInitSize = 32u; - + size_t expectedAlignedSize = alignUp(initData.size(), MemoryConstants::pageSize); alloc = allocateGlobalsSurface(nullptr, device, initData.size(), zeroInitSize, true, &emptyLinkerInput, initData.data()); ASSERT_NE(nullptr, alloc); - EXPECT_EQ(64u, alloc->getUnderlyingBufferSize()); + EXPECT_EQ(expectedAlignedSize, alloc->getUnderlyingBufferSize()); auto dataPtr = reinterpret_cast(alloc->getUnderlyingBuffer()); EXPECT_EQ(0, memcmp(dataPtr, initData.data(), 32u));