Fix calculating maxMemAllocSize

Signed-off-by: Szymon Morek <szymon.morek@intel.com>
This commit is contained in:
Szymon Morek
2021-07-13 16:01:30 +00:00
committed by Compute-Runtime-Automation
parent f293b409ff
commit 42c5f2235b
7 changed files with 55 additions and 15 deletions

View File

@ -625,6 +625,14 @@ TEST_F(DeviceTest, givenCallToDevicePropertiesThenMaximumMemoryToBeAllocatedIsCo
deviceProperties.maxMemAllocSize = 0;
device->getProperties(&deviceProperties);
EXPECT_EQ(deviceProperties.maxMemAllocSize, this->neoDevice->getDeviceInfo().maxMemAllocSize);
HardwareCapabilities hwCaps = {0};
auto &hwHelper = HwHelper::get(defaultHwInfo->platform.eRenderCoreFamily);
hwHelper.setupHardwareCapabilities(&hwCaps, *defaultHwInfo);
auto expectedSize = this->neoDevice->getDeviceInfo().globalMemSize;
if (!this->neoDevice->getDeviceInfo().sharedSystemAllocationsSupport) {
expectedSize = std::min(expectedSize, hwCaps.maxMemAllocSize);
}
EXPECT_EQ(deviceProperties.maxMemAllocSize, expectedSize);
}
struct DeviceHwInfoTest : public ::testing::Test {

View File

@ -392,6 +392,9 @@ TEST_F(MemoryRelaxedSizeTests,
TEST_F(MemoryRelaxedSizeTests,
givenCallToDeviceAllocWithLargerThanAllowedSizeAndRelaxedFlagThenAllocationIsMade) {
if (device->getDeviceInfo().sharedSystemAllocationsSupport) {
GTEST_SKIP();
}
size_t size = device->getNEODevice()->getDeviceInfo().maxMemAllocSize + 1;
size_t alignment = 1u;
void *ptr = nullptr;
@ -506,6 +509,9 @@ TEST_F(MemoryRelaxedSizeTests,
TEST_F(MemoryRelaxedSizeTests,
givenCallToSharedAllocWithLargerThanAllowedSizeAndRelaxedFlagThenAllocationIsMade) {
if (device->getDeviceInfo().sharedSystemAllocationsSupport) {
GTEST_SKIP();
}
size_t size = device->getNEODevice()->getDeviceInfo().maxMemAllocSize + 1;
size_t alignment = 1u;
void *ptr = nullptr;

View File

@ -302,6 +302,7 @@ void ClDevice::initializeCaps() {
deviceInfo.preferredInteropUserSync = 1u;
device.reduceMaxMemAllocSize();
// OpenCL 1.2 requires 128MB minimum
deviceInfo.maxConstantBufferSize = sharedDeviceInfo.maxMemAllocSize;

View File

@ -1045,7 +1045,7 @@ TEST(clUnifiedSharedMemoryTests, givenUnifiedMemoryAllocationSizeGreaterThanMaxM
MockContext mockContext;
cl_int retVal = CL_SUCCESS;
cl_mem_properties_intel properties[] = {0};
auto bigSize = MemoryConstants::gigaByte * 10;
auto bigSize = MemoryConstants::gigaByte * 20;
auto allocationSize = static_cast<size_t>(bigSize);
auto memoryManager = static_cast<OsAgnosticMemoryManager *>(mockContext.getDevice(0u)->getMemoryManager());
memoryManager->turnOnFakingBigAllocations();

View File

@ -503,8 +503,8 @@ TEST_F(DeviceGetCapsTest, givenDeviceCapsWhenLocalMemoryIsEnabledThenCalculateGl
TEST_F(DeviceGetCapsTest, givenGlobalMemSizeAndSharedSystemAllocationsNotSupportedWhenCalculatingMaxAllocSizeThenAdjustToHWCap) {
DebugManagerStateRestore dbgRestorer;
DebugManager.flags.EnableSharedSystemUsmSupport.set(0);
auto device = std::unique_ptr<Device>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(defaultHwInfo.get()));
const auto &caps = device->getDeviceInfo();
auto device = std::make_unique<MockClDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(defaultHwInfo.get()));
const auto &caps = device->getSharedDeviceInfo();
HardwareCapabilities hwCaps = {0};
auto &hwHelper = HwHelper::get(defaultHwInfo->platform.eRenderCoreFamily);
@ -515,18 +515,13 @@ TEST_F(DeviceGetCapsTest, givenGlobalMemSizeAndSharedSystemAllocationsNotSupport
EXPECT_EQ(caps.maxMemAllocSize, expectedSize);
}
TEST_F(DeviceGetCapsTest, givenGlobalMemSizeAndSharedSystemAllocationsSupportedWhenCalculatingMaxAllocSizeThenAdjustToGlobalMemSize) {
TEST_F(DeviceGetCapsTest, givenGlobalMemSizeAndSharedSystemAllocationsSupportedWhenCalculatingMaxAllocSizeThenEqualsToGlobalMemSize) {
DebugManagerStateRestore dbgRestorer;
DebugManager.flags.EnableSharedSystemUsmSupport.set(1);
auto device = std::unique_ptr<Device>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(defaultHwInfo.get()));
const auto &caps = device->getDeviceInfo();
auto device = std::make_unique<MockClDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(defaultHwInfo.get()));
const auto &caps = device->getSharedDeviceInfo();
HardwareCapabilities hwCaps = {0};
auto &hwHelper = HwHelper::get(defaultHwInfo->platform.eRenderCoreFamily);
hwHelper.setupHardwareCapabilities(&hwCaps, *defaultHwInfo);
uint64_t expectedSize = std::max((caps.globalMemSize / 2), static_cast<uint64_t>(128ULL * MemoryConstants::megaByte));
EXPECT_EQ(caps.maxMemAllocSize, expectedSize);
EXPECT_EQ(caps.maxMemAllocSize, caps.globalMemSize);
}
TEST_F(DeviceGetCapsTest, whenDriverModelHasLimitationForMaxMemoryAllocationSizeThenTakeItIntoAccount) {
@ -1732,3 +1727,23 @@ HWTEST_F(DeviceGetCapsTest, givenDSSCountEqualZeroWhenDeviceCreatedThenMaxEuPerD
EXPECT_EQ(device->sharedDeviceInfo.maxNumEUsPerSubSlice, device->sharedDeviceInfo.maxNumEUsPerDualSubSlice);
}
TEST_F(DeviceGetCapsTest, givenGlobalMemSizeAndSharedSystemAllocationSupportWhenReduceMaxMemAllocSizeThenValidValueIsSet) {
HardwareCapabilities hwCaps = {0};
auto &hwHelper = HwHelper::get(defaultHwInfo->platform.eRenderCoreFamily);
hwHelper.setupHardwareCapabilities(&hwCaps, *defaultHwInfo);
DebugManagerStateRestore dbgRestorer;
DebugManager.flags.EnableSharedSystemUsmSupport.set(0);
auto device = std::make_unique<MockClDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(defaultHwInfo.get()));
auto globalMemSize = device->getSharedDeviceInfo().globalMemSize;
device->getDevice().reduceMaxMemAllocSize();
auto expectedSize = std::min(globalMemSize / 2, hwCaps.maxMemAllocSize);
expectedSize = std::max(expectedSize, static_cast<uint64_t>(128llu * MB));
EXPECT_EQ(device->getSharedDeviceInfo().maxMemAllocSize, expectedSize);
DebugManager.flags.EnableSharedSystemUsmSupport.set(1);
device.reset(new MockClDevice(MockDevice::createWithNewExecutionEnvironment<MockDevice>(defaultHwInfo.get())));
device->getDevice().reduceMaxMemAllocSize();
EXPECT_EQ(device->getSharedDeviceInfo().maxMemAllocSize, globalMemSize);
}

View File

@ -119,6 +119,7 @@ class Device : public ReferenceTrackedObject<Device> {
std::unique_ptr<SyncBufferHandler> syncBufferHandler;
GraphicsAllocation *getRTMemoryBackedBuffer() { return rtMemoryBackedBuffer; }
void initializeRayTracing();
void reduceMaxMemAllocSize();
protected:
Device() = delete;

View File

@ -71,9 +71,6 @@ void Device::initializeCaps() {
deviceInfo.globalMemSize = alignDown(deviceInfo.globalMemSize, MemoryConstants::pageSize);
deviceInfo.maxMemAllocSize = std::min(deviceInfo.globalMemSize, deviceInfo.maxMemAllocSize); // if globalMemSize was reduced for 32b
// OpenCL 1.2 requires 128MB minimum
deviceInfo.maxMemAllocSize = std::max(deviceInfo.maxMemAllocSize / 2, static_cast<uint64_t>(128llu * MB));
if (!deviceInfo.sharedSystemAllocationsSupport) {
deviceInfo.maxMemAllocSize = std::min(deviceInfo.maxMemAllocSize, this->hardwareCapabilities.maxMemAllocSize);
}
@ -171,4 +168,16 @@ void Device::initializeCaps() {
deviceInfo.name = deviceName.str();
}
void Device::reduceMaxMemAllocSize() {
deviceInfo.maxMemAllocSize = deviceInfo.globalMemSize;
if (!deviceInfo.sharedSystemAllocationsSupport) {
deviceInfo.maxMemAllocSize /= 2;
deviceInfo.maxMemAllocSize = std::min(deviceInfo.maxMemAllocSize, this->hardwareCapabilities.maxMemAllocSize);
}
// OpenCL 1.2 requires 128MB minimum
deviceInfo.maxMemAllocSize = std::max(deviceInfo.maxMemAllocSize, static_cast<uint64_t>(128llu * MB));
}
} // namespace NEO