fix: get right page size when malloc uses 0 alignment

Related-To: GSD-7103

Signed-off-by: Lu, Wenbin <wenbin.lu@intel.com>
This commit is contained in:
Lu, Wenbin
2023-12-05 19:30:46 +00:00
committed by Compute-Runtime-Automation
parent 739d181026
commit 67fa39c9a1
5 changed files with 39 additions and 12 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2022 Intel Corporation
* Copyright (C) 2018-2023 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -119,6 +119,24 @@ INSTANTIATE_TEST_CASE_P(
256,
4096));
struct AlignUpNonZero : public ::testing::TestWithParam<std::tuple<size_t, size_t>> {
};
TEST_P(AlignUpNonZero, GivenSizeAndAlignmentThenAlignedResultIsNonZero) {
size_t size = std::get<0>(GetParam());
size_t alignment = std::get<1>(GetParam());
const size_t result = alignUpNonZero(size, alignment);
EXPECT_TRUE(0 < result);
EXPECT_TRUE(0 == result % alignment);
}
INSTANTIATE_TEST_CASE_P(
AlignUpNonZeroParameterized,
AlignUpNonZero,
testing::Combine(
testing::Values(0, 1),
testing::Values(1, 4, 8, 32, 64, 256, 4096)));
TEST(AlignWholeSize, GivenSizeLessThanPageSizeWhenAligningWholeSizeToPageThenAlignedSizeIsPageSize) {
int size = 1;
auto retSize = alignSizeWholePage(ptrAlignedToPage, size);

View File

@@ -337,7 +337,7 @@ TEST_F(SVMLocalMemoryAllocatorTest, givenAlignmentThenUnifiedMemoryAllocationsAr
do {
alignment >>= 1;
memoryManager->validateAllocateProperties = [alignment](const AllocationProperties &properties) {
EXPECT_EQ(properties.alignment, alignUp<size_t>(alignment, MemoryConstants::pageSize64k));
EXPECT_EQ(properties.alignment, alignUpNonZero<size_t>(alignment, MemoryConstants::pageSize64k));
};
SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::DEVICE_UNIFIED_MEMORY, alignment, rootDeviceIndices, deviceBitfields);
unifiedMemoryProperties.device = device;
@@ -362,7 +362,7 @@ TEST_F(SVMLocalMemoryAllocatorTest, givenAlignmentThenHostUnifiedMemoryAllocatio
do {
alignment >>= 1;
memoryManager->validateAllocateProperties = [alignment](const AllocationProperties &properties) {
EXPECT_EQ(properties.alignment, alignUp<size_t>(alignment, MemoryConstants::pageSize));
EXPECT_EQ(properties.alignment, alignUpNonZero<size_t>(alignment, MemoryConstants::pageSize));
};
SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::HOST_UNIFIED_MEMORY, alignment, rootDeviceIndices, deviceBitfields);
unifiedMemoryProperties.device = device;
@@ -391,7 +391,7 @@ TEST_F(SVMLocalMemoryAllocatorTest, givenAlignmentThenSharedUnifiedMemoryAllocat
do {
alignment >>= 1;
memoryManager->validateAllocateProperties = [alignment](const AllocationProperties &properties) {
EXPECT_EQ(properties.alignment, alignUp<size_t>(alignment, MemoryConstants::pageSize64k));
EXPECT_EQ(properties.alignment, alignUpNonZero<size_t>(alignment, MemoryConstants::pageSize64k));
};
SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::SHARED_UNIFIED_MEMORY, alignment, rootDeviceIndices, deviceBitfields);
unifiedMemoryProperties.device = device;