diff --git a/level_zero/core/source/helpers/api_specific_config_l0.cpp b/level_zero/core/source/helpers/api_specific_config_l0.cpp index 0577d69e1b..d56519f57f 100644 --- a/level_zero/core/source/helpers/api_specific_config_l0.cpp +++ b/level_zero/core/source/helpers/api_specific_config_l0.cpp @@ -33,4 +33,8 @@ const char *ApiSpecificConfig::getAubPrefixForSpecificApi() { return "l0_"; } -} // namespace NEO \ No newline at end of file +uint64_t ApiSpecificConfig::getReducedMaxAllocSize(uint64_t maxAllocSize) { + return maxAllocSize; +} + +} // namespace NEO diff --git a/level_zero/core/test/unit_tests/sources/helper/api_specific_config_l0_tests.cpp b/level_zero/core/test/unit_tests/sources/helper/api_specific_config_l0_tests.cpp index c6354c6d87..f792a1c49f 100644 --- a/level_zero/core/test/unit_tests/sources/helper/api_specific_config_l0_tests.cpp +++ b/level_zero/core/test/unit_tests/sources/helper/api_specific_config_l0_tests.cpp @@ -23,4 +23,8 @@ TEST(ApiSpecificConfigL0Tests, WhenCheckingIfStatelessCompressionIsSupportedThen EXPECT_FALSE(ApiSpecificConfig::isStatelessCompressionSupported()); } -} // namespace NEO \ No newline at end of file +TEST(ApiSpecificConfigL0Tests, givenMaxAllocSizeWhenGettingReducedMaxAllocSizeThenReturnSameValue) { + EXPECT_EQ(1024u, ApiSpecificConfig::getReducedMaxAllocSize(1024)); +} + +} // namespace NEO diff --git a/opencl/source/cl_device/cl_device_caps.cpp b/opencl/source/cl_device/cl_device_caps.cpp index 9a2e93fb3f..e059c0e661 100644 --- a/opencl/source/cl_device/cl_device_caps.cpp +++ b/opencl/source/cl_device/cl_device_caps.cpp @@ -302,7 +302,6 @@ void ClDevice::initializeCaps() { deviceInfo.preferredInteropUserSync = 1u; - device.reduceMaxMemAllocSize(); // OpenCL 1.2 requires 128MB minimum deviceInfo.maxConstantBufferSize = sharedDeviceInfo.maxMemAllocSize; diff --git a/opencl/source/helpers/api_specific_config_ocl.cpp b/opencl/source/helpers/api_specific_config_ocl.cpp index e9967a2465..ae4843f7a1 100644 --- a/opencl/source/helpers/api_specific_config_ocl.cpp +++ b/opencl/source/helpers/api_specific_config_ocl.cpp @@ -32,4 +32,9 @@ ApiSpecificConfig::ApiType ApiSpecificConfig::getApiType() { const char *ApiSpecificConfig::getAubPrefixForSpecificApi() { return "ocl_"; } -} // namespace NEO \ No newline at end of file + +uint64_t ApiSpecificConfig::getReducedMaxAllocSize(uint64_t maxAllocSize) { + return maxAllocSize / 2; +} + +} // namespace NEO diff --git a/opencl/test/unit_test/device/device_caps_tests.cpp b/opencl/test/unit_test/device/device_caps_tests.cpp index d70a92649d..ac1b1f810f 100644 --- a/opencl/test/unit_test/device/device_caps_tests.cpp +++ b/opencl/test/unit_test/device/device_caps_tests.cpp @@ -1731,23 +1731,3 @@ 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(MockDevice::createWithNewExecutionEnvironment(defaultHwInfo.get())); - auto globalMemSize = std::min(device->getDevice().getGlobalMemorySize(1u), device->getSharedDeviceInfo().globalMemSize); - device->getDevice().reduceMaxMemAllocSize(); - auto expectedSize = std::min(globalMemSize / 2, hwCaps.maxMemAllocSize); - expectedSize = std::max(expectedSize, static_cast(128llu * MB)); - EXPECT_EQ(device->getSharedDeviceInfo().maxMemAllocSize, expectedSize); - - DebugManager.flags.EnableSharedSystemUsmSupport.set(1); - device.reset(new MockClDevice(MockDevice::createWithNewExecutionEnvironment(defaultHwInfo.get()))); - device->getDevice().reduceMaxMemAllocSize(); - EXPECT_EQ(device->getSharedDeviceInfo().maxMemAllocSize, globalMemSize); -} diff --git a/opencl/test/unit_test/helpers/api_specific_config_ocl_tests.cpp b/opencl/test/unit_test/helpers/api_specific_config_ocl_tests.cpp index 9f48fdfa79..0e161f0509 100644 --- a/opencl/test/unit_test/helpers/api_specific_config_ocl_tests.cpp +++ b/opencl/test/unit_test/helpers/api_specific_config_ocl_tests.cpp @@ -15,12 +15,16 @@ TEST(ApiSpecificConfigOclTests, WhenGettingApiTypeThenCorrectTypeIsReturned) { EXPECT_EQ(ApiSpecificConfig::OCL, ApiSpecificConfig::getApiType()); } -TEST(ApiSpecificConfigL0Tests, WhenGettingAUBPrefixByApiTypeOCLIsReturned) { +TEST(ApiSpecificConfigOclTests, WhenGettingAUBPrefixByApiTypeOCLIsReturned) { EXPECT_EQ(0, strcmp("ocl_", ApiSpecificConfig::getAubPrefixForSpecificApi())); } -TEST(ApiSpecificConfigL0Tests, WhenCheckingIfStatelessCompressionIsSupportedThenReturnTrue) { +TEST(ApiSpecificConfigOclTests, WhenCheckingIfStatelessCompressionIsSupportedThenReturnTrue) { EXPECT_TRUE(ApiSpecificConfig::isStatelessCompressionSupported()); } -} // namespace NEO \ No newline at end of file +TEST(ApiSpecificConfigOclTests, givenMaxAllocSizeWhenGettingReducedMaxAllocSizeThenReturnHalfOfThat) { + EXPECT_EQ(512u, ApiSpecificConfig::getReducedMaxAllocSize(1024)); +} + +} // namespace NEO diff --git a/shared/source/device/device.h b/shared/source/device/device.h index 657b60b4f4..45c92d782a 100644 --- a/shared/source/device/device.h +++ b/shared/source/device/device.h @@ -118,7 +118,6 @@ class Device : public ReferenceTrackedObject { std::unique_ptr syncBufferHandler; GraphicsAllocation *getRTMemoryBackedBuffer() { return rtMemoryBackedBuffer; } void initializeRayTracing(); - void reduceMaxMemAllocSize(); virtual uint64_t getGlobalMemorySize(uint32_t deviceBitfield) const; diff --git a/shared/source/device/device_caps.cpp b/shared/source/device/device_caps.cpp index fe3a5ea914..ffac1393e1 100644 --- a/shared/source/device/device_caps.cpp +++ b/shared/source/device/device_caps.cpp @@ -7,6 +7,7 @@ #include "shared/source/debugger/debugger.h" #include "shared/source/device/device.h" +#include "shared/source/helpers/api_specific_config.h" #include "shared/source/helpers/basic_math.h" #include "shared/source/helpers/hw_helper.h" #include "shared/source/memory_manager/memory_manager.h" @@ -72,6 +73,7 @@ void Device::initializeCaps() { deviceInfo.maxMemAllocSize = std::min(deviceInfo.globalMemSize, deviceInfo.maxMemAllocSize); // if globalMemSize was reduced for 32b if (!deviceInfo.sharedSystemAllocationsSupport) { + deviceInfo.maxMemAllocSize = ApiSpecificConfig::getReducedMaxAllocSize(deviceInfo.maxMemAllocSize); deviceInfo.maxMemAllocSize = std::min(deviceInfo.maxMemAllocSize, this->hardwareCapabilities.maxMemAllocSize); } @@ -168,16 +170,4 @@ void Device::initializeCaps() { deviceInfo.name = deviceName.str(); } -void Device::reduceMaxMemAllocSize() { - deviceInfo.maxMemAllocSize = std::min(deviceInfo.globalMemSize, getGlobalMemorySize(1u)); - - 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(128llu * MB)); -} - } // namespace NEO diff --git a/shared/source/helpers/api_specific_config.h b/shared/source/helpers/api_specific_config.h index 11e88f9b95..98f05fdb9e 100644 --- a/shared/source/helpers/api_specific_config.h +++ b/shared/source/helpers/api_specific_config.h @@ -5,6 +5,8 @@ * */ +#include + #pragma once namespace NEO { struct ApiSpecificConfig { @@ -15,5 +17,6 @@ struct ApiSpecificConfig { static bool getBindlessConfiguration(); static ApiType getApiType(); static const char *getAubPrefixForSpecificApi(); + static uint64_t getReducedMaxAllocSize(uint64_t maxAllocSize); }; -} // namespace NEO \ No newline at end of file +} // namespace NEO diff --git a/shared/test/common/helpers/api_specific_config_shared_tests.cpp b/shared/test/common/helpers/api_specific_config_shared_tests.cpp index f6c78f26de..c2157706b6 100644 --- a/shared/test/common/helpers/api_specific_config_shared_tests.cpp +++ b/shared/test/common/helpers/api_specific_config_shared_tests.cpp @@ -25,4 +25,9 @@ bool ApiSpecificConfig::getBindlessConfiguration() { ApiSpecificConfig::ApiType ApiSpecificConfig::getApiType() { return ApiSpecificConfig::OCL; } -} // namespace NEO \ No newline at end of file + +uint64_t ApiSpecificConfig::getReducedMaxAllocSize(uint64_t maxAllocSize) { + return maxAllocSize / 2; +} + +} // namespace NEO