diff --git a/level_zero/core/source/context/context_imp.cpp b/level_zero/core/source/context/context_imp.cpp index ba92ab8f59..49cd3464bd 100644 --- a/level_zero/core/source/context/context_imp.cpp +++ b/level_zero/core/source/context/context_imp.cpp @@ -69,7 +69,7 @@ ze_result_t ContextImp::allocHostMem(const ze_host_mem_alloc_desc_t *hostDesc, } if (relaxedSizeAllowed == false && - (size > this->driverHandle->devices[0]->getNEODevice()->getHardwareCapabilities().maxMemAllocSize)) { + (size > this->driverHandle->devices[0]->getNEODevice()->getDeviceInfo().maxMemAllocSize)) { *ptr = nullptr; return ZE_RESULT_ERROR_UNSUPPORTED_SIZE; } @@ -137,7 +137,7 @@ ze_result_t ContextImp::allocDeviceMem(ze_device_handle_t hDevice, } if (relaxedSizeAllowed == false && - (size > this->driverHandle->devices[0]->getNEODevice()->getHardwareCapabilities().maxMemAllocSize)) { + (size > this->driverHandle->devices[0]->getNEODevice()->getDeviceInfo().maxMemAllocSize)) { *ptr = nullptr; return ZE_RESULT_ERROR_UNSUPPORTED_SIZE; } @@ -192,7 +192,7 @@ ze_result_t ContextImp::allocSharedMem(ze_device_handle_t hDevice, } if (relaxedSizeAllowed == false && - (size > this->devices.begin()->second->getNEODevice()->getHardwareCapabilities().maxMemAllocSize)) { + (size > this->devices.begin()->second->getNEODevice()->getDeviceInfo().maxMemAllocSize)) { *ptr = nullptr; return ZE_RESULT_ERROR_UNSUPPORTED_SIZE; } diff --git a/level_zero/core/test/unit_tests/sources/memory/test_memory.cpp b/level_zero/core/test/unit_tests/sources/memory/test_memory.cpp index 95281393f0..3dcb5c9625 100644 --- a/level_zero/core/test/unit_tests/sources/memory/test_memory.cpp +++ b/level_zero/core/test/unit_tests/sources/memory/test_memory.cpp @@ -149,7 +149,7 @@ struct OutOfMemoryTests : public ::testing::Test { TEST_F(OutOfMemoryTests, givenCallToDeviceAllocAndFailureToAllocateThenOutOfDeviceMemoryIsReturned) { - size_t size = device->getNEODevice()->getHardwareCapabilities().maxMemAllocSize - 1; + size_t size = device->getNEODevice()->getDeviceInfo().maxMemAllocSize - 1; size_t alignment = 1u; void *ptr = nullptr; @@ -225,7 +225,7 @@ struct MemoryRelaxedSizeTests : public ::testing::Test { TEST_F(MemoryRelaxedSizeTests, givenCallToHostAllocWithAllowedSizeAndWithoutRelaxedFlagThenAllocationIsMade) { - size_t size = device->getNEODevice()->getHardwareCapabilities().maxMemAllocSize - 1; + size_t size = device->getNEODevice()->getDeviceInfo().maxMemAllocSize - 1; size_t alignment = 1u; void *ptr = nullptr; @@ -241,7 +241,7 @@ TEST_F(MemoryRelaxedSizeTests, TEST_F(MemoryRelaxedSizeTests, givenCallToHostAllocWithLargerThanAllowedSizeAndWithoutRelaxedFlagThenAllocationIsNotMade) { - size_t size = device->getNEODevice()->getHardwareCapabilities().maxMemAllocSize + 1; + size_t size = device->getNEODevice()->getDeviceInfo().maxMemAllocSize + 1; size_t alignment = 1u; void *ptr = nullptr; @@ -254,7 +254,7 @@ TEST_F(MemoryRelaxedSizeTests, TEST_F(MemoryRelaxedSizeTests, givenCallToHostAllocWithLargerThanAllowedSizeAndRelaxedFlagThenAllocationIsMade) { - size_t size = device->getNEODevice()->getHardwareCapabilities().maxMemAllocSize + 1; + size_t size = device->getNEODevice()->getDeviceInfo().maxMemAllocSize + 1; size_t alignment = 1u; void *ptr = nullptr; @@ -275,7 +275,7 @@ TEST_F(MemoryRelaxedSizeTests, TEST_F(MemoryRelaxedSizeTests, givenCallToHostAllocWithLargerThanAllowedSizeAndRelaxedFlagWithIncorrectFlagThenAllocationIsNotMade) { - size_t size = device->getNEODevice()->getHardwareCapabilities().maxMemAllocSize + 1; + size_t size = device->getNEODevice()->getDeviceInfo().maxMemAllocSize + 1; size_t alignment = 1u; void *ptr = nullptr; @@ -293,7 +293,7 @@ TEST_F(MemoryRelaxedSizeTests, TEST_F(MemoryRelaxedSizeTests, givenCallToHostAllocWithLargerThanAllowedSizeAndRelaxedDescriptorWithWrongStypeThenUnsupportedSizeIsReturned) { - size_t size = device->getNEODevice()->getHardwareCapabilities().maxMemAllocSize + 1; + size_t size = device->getNEODevice()->getDeviceInfo().maxMemAllocSize + 1; size_t alignment = 1u; void *ptr = nullptr; @@ -311,7 +311,7 @@ TEST_F(MemoryRelaxedSizeTests, TEST_F(MemoryRelaxedSizeTests, givenCallToDeviceAllocWithAllowedSizeAndWithoutRelaxedFlagThenAllocationIsMade) { - size_t size = device->getNEODevice()->getHardwareCapabilities().maxMemAllocSize - 1; + size_t size = device->getNEODevice()->getDeviceInfo().maxMemAllocSize - 1; size_t alignment = 1u; void *ptr = nullptr; @@ -328,7 +328,7 @@ TEST_F(MemoryRelaxedSizeTests, TEST_F(MemoryRelaxedSizeTests, givenCallToDeviceAllocWithLargerThanAllowedSizeAndWithoutRelaxedFlagThenAllocationIsNotMade) { - size_t size = device->getNEODevice()->getHardwareCapabilities().maxMemAllocSize + 1; + size_t size = device->getNEODevice()->getDeviceInfo().maxMemAllocSize + 1; size_t alignment = 1u; void *ptr = nullptr; @@ -342,7 +342,7 @@ TEST_F(MemoryRelaxedSizeTests, TEST_F(MemoryRelaxedSizeTests, givenCallToDeviceAllocWithLargerThanAllowedSizeAndRelaxedFlagThenAllocationIsMade) { - size_t size = device->getNEODevice()->getHardwareCapabilities().maxMemAllocSize + 1; + size_t size = device->getNEODevice()->getDeviceInfo().maxMemAllocSize + 1; size_t alignment = 1u; void *ptr = nullptr; @@ -383,7 +383,7 @@ TEST_F(MemoryRelaxedSizeTests, TEST_F(MemoryRelaxedSizeTests, givenCallToDeviceAllocWithLargerThanAllowedSizeAndRelaxedFlagWithIncorrectFlagThenAllocationIsNotMade) { - size_t size = device->getNEODevice()->getHardwareCapabilities().maxMemAllocSize + 1; + size_t size = device->getNEODevice()->getDeviceInfo().maxMemAllocSize + 1; size_t alignment = 1u; void *ptr = nullptr; @@ -402,7 +402,7 @@ TEST_F(MemoryRelaxedSizeTests, TEST_F(MemoryRelaxedSizeTests, givenCallToDeviceAllocWithLargerThanAllowedSizeAndRelaxedDescriptorWithWrongStypeThenUnsupportedSizeIsReturned) { - size_t size = device->getNEODevice()->getHardwareCapabilities().maxMemAllocSize + 1; + size_t size = device->getNEODevice()->getDeviceInfo().maxMemAllocSize + 1; size_t alignment = 1u; void *ptr = nullptr; @@ -421,7 +421,7 @@ TEST_F(MemoryRelaxedSizeTests, TEST_F(MemoryRelaxedSizeTests, givenCallToSharedAllocWithAllowedSizeAndWithoutRelaxedFlagThenAllocationIsMade) { - size_t size = device->getNEODevice()->getHardwareCapabilities().maxMemAllocSize - 1; + size_t size = device->getNEODevice()->getDeviceInfo().maxMemAllocSize - 1; size_t alignment = 1u; void *ptr = nullptr; @@ -440,7 +440,7 @@ TEST_F(MemoryRelaxedSizeTests, TEST_F(MemoryRelaxedSizeTests, givenCallToSharedAllocWithLargerThanAllowedSizeAndWithoutRelaxedFlagThenAllocationIsNotMade) { - size_t size = device->getNEODevice()->getHardwareCapabilities().maxMemAllocSize + 1; + size_t size = device->getNEODevice()->getDeviceInfo().maxMemAllocSize + 1; size_t alignment = 1u; void *ptr = nullptr; @@ -456,7 +456,7 @@ TEST_F(MemoryRelaxedSizeTests, TEST_F(MemoryRelaxedSizeTests, givenCallToSharedAllocWithLargerThanAllowedSizeAndRelaxedFlagThenAllocationIsMade) { - size_t size = device->getNEODevice()->getHardwareCapabilities().maxMemAllocSize + 1; + size_t size = device->getNEODevice()->getDeviceInfo().maxMemAllocSize + 1; size_t alignment = 1u; void *ptr = nullptr; @@ -501,7 +501,7 @@ TEST_F(MemoryRelaxedSizeTests, TEST_F(MemoryRelaxedSizeTests, givenCallToSharedAllocWithLargerThanAllowedSizeAndRelaxedFlagWithIncorrectFlagThenAllocationIsNotMade) { - size_t size = device->getNEODevice()->getHardwareCapabilities().maxMemAllocSize + 1; + size_t size = device->getNEODevice()->getDeviceInfo().maxMemAllocSize + 1; size_t alignment = 1u; void *ptr = nullptr; @@ -522,7 +522,7 @@ TEST_F(MemoryRelaxedSizeTests, TEST_F(MemoryRelaxedSizeTests, givenCallToSharedAllocWithLargerThanAllowedSizeAndRelaxedDescriptorWithWrongStypeThenUnsupportedSizeIsReturned) { - size_t size = device->getNEODevice()->getHardwareCapabilities().maxMemAllocSize + 1; + size_t size = device->getNEODevice()->getDeviceInfo().maxMemAllocSize + 1; size_t alignment = 1u; void *ptr = nullptr; @@ -1833,7 +1833,7 @@ TEST_F(MemoryFailedOpenIpcHandleTest, using DeviceMemorySizeTest = Test; TEST_F(DeviceMemorySizeTest, givenSizeGreaterThanLimitThenDeviceAllocationFails) { - size_t size = neoDevice->getHardwareCapabilities().maxMemAllocSize + 1; + size_t size = neoDevice->getDeviceInfo().maxMemAllocSize + 1; size_t alignment = 1u; void *ptr = nullptr; diff --git a/opencl/source/api/api.cpp b/opencl/source/api/api.cpp index 8c326b333b..5a1d4110a3 100644 --- a/opencl/source/api/api.cpp +++ b/opencl/source/api/api.cpp @@ -3851,7 +3851,7 @@ void *clDeviceMemAllocINTEL( return nullptr; } - if (size > neoDevice->getHardwareCapabilities().maxMemAllocSize && + if (size > neoDevice->getDevice().getDeviceInfo().maxMemAllocSize && !unifiedMemoryProperties.allocationFlags.flags.allowUnrestrictedSize) { err.set(CL_INVALID_BUFFER_SIZE); return nullptr; diff --git a/opencl/source/mem_obj/buffer.cpp b/opencl/source/mem_obj/buffer.cpp index 5099832ce8..4ec89d3fef 100644 --- a/opencl/source/mem_obj/buffer.cpp +++ b/opencl/source/mem_obj/buffer.cpp @@ -126,7 +126,7 @@ cl_mem Buffer::validateInputAndCreateBuffer(cl_context context, bool allowCreateBuffersWithUnrestrictedSize = isValueSet(flags, CL_MEM_ALLOW_UNRESTRICTED_SIZE_INTEL) || isValueSet(flagsIntel, CL_MEM_ALLOW_UNRESTRICTED_SIZE_INTEL); - if (size == 0 || (size > pDevice->getHardwareCapabilities().maxMemAllocSize && !allowCreateBuffersWithUnrestrictedSize)) { + if (size == 0 || (size > pDevice->getDevice().getDeviceInfo().maxMemAllocSize && !allowCreateBuffersWithUnrestrictedSize)) { retVal = CL_INVALID_BUFFER_SIZE; return nullptr; } diff --git a/opencl/test/unit_test/api/cl_create_buffer_tests.cpp b/opencl/test/unit_test/api/cl_create_buffer_tests.cpp index 28ce1a7750..8a197ccea1 100644 --- a/opencl/test/unit_test/api/cl_create_buffer_tests.cpp +++ b/opencl/test/unit_test/api/cl_create_buffer_tests.cpp @@ -221,7 +221,7 @@ TEST_F(clCreateBufferTests, GivenMemWriteOnlyFlagAndMemReadWriteFlagWhenCreating TEST_F(clCreateBufferTests, GivenBufferSizeOverMaxMemAllocSizeWhenCreatingBufferThenInvalidBufferSizeErrorIsReturned) { auto pDevice = pContext->getDevice(0); - size_t size = static_cast(pDevice->getHardwareCapabilities().maxMemAllocSize) + 1; + size_t size = static_cast(pDevice->getDevice().getDeviceInfo().maxMemAllocSize) + 1; auto buffer = clCreateBuffer(pContext, CL_MEM_ALLOC_HOST_PTR, size, nullptr, &retVal); EXPECT_EQ(CL_INVALID_BUFFER_SIZE, retVal); @@ -230,7 +230,7 @@ TEST_F(clCreateBufferTests, GivenBufferSizeOverMaxMemAllocSizeWhenCreatingBuffer TEST_F(clCreateBufferTests, GivenBufferSizeOverMaxMemAllocSizeWhenCreateBufferWithPropertiesINTELThenInvalidBufferSizeErrorIsReturned) { auto pDevice = pContext->getDevice(0); - size_t size = static_cast(pDevice->getHardwareCapabilities().maxMemAllocSize) + 1; + size_t size = static_cast(pDevice->getDevice().getDeviceInfo().maxMemAllocSize) + 1; auto buffer = clCreateBufferWithPropertiesINTEL(pContext, nullptr, 0, size, nullptr, &retVal); EXPECT_EQ(CL_INVALID_BUFFER_SIZE, retVal); diff --git a/opencl/test/unit_test/api/cl_unified_shared_memory_tests.inl b/opencl/test/unit_test/api/cl_unified_shared_memory_tests.inl index 4c2aa46191..d152e9b138 100644 --- a/opencl/test/unit_test/api/cl_unified_shared_memory_tests.inl +++ b/opencl/test/unit_test/api/cl_unified_shared_memory_tests.inl @@ -92,7 +92,7 @@ TEST(clUnifiedSharedMemoryTests, whenClDeviceMemAllocIntelIsCalledThenItAllocate TEST(clUnifiedSharedMemoryTests, whenUnifiedSharedMemoryAllocationCallsAreCalledWithSizeGreaterThenMaxMemAllocSizeThenErrorIsReturned) { MockContext mockContext; cl_int retVal = CL_SUCCESS; - auto maxMemAllocSize = mockContext.getDevice(0u)->getHardwareCapabilities().maxMemAllocSize; + auto maxMemAllocSize = mockContext.getDevice(0u)->getDevice().getDeviceInfo().maxMemAllocSize; size_t requestedSize = static_cast(maxMemAllocSize) + 1u; auto unfiedMemoryDeviceAllocation = clDeviceMemAllocINTEL(&mockContext, mockContext.getDevice(0u), nullptr, requestedSize, 0, &retVal); diff --git a/opencl/test/unit_test/device/device_caps_tests.cpp b/opencl/test/unit_test/device/device_caps_tests.cpp index 5949b4f7ae..930594c789 100644 --- a/opencl/test/unit_test/device/device_caps_tests.cpp +++ b/opencl/test/unit_test/device/device_caps_tests.cpp @@ -180,7 +180,9 @@ TEST_F(DeviceGetCapsTest, WhenCreatingDeviceThenCapsArePopulatedCorrectly) { EXPECT_LE(sharedCaps.maxReadImageArgs * sizeof(cl_mem), sharedCaps.maxParameterSize); EXPECT_LE(sharedCaps.maxWriteImageArgs * sizeof(cl_mem), sharedCaps.maxParameterSize); EXPECT_LE(128u * MB, sharedCaps.maxMemAllocSize); - EXPECT_GE((4 * GB) - (8 * KB), sharedCaps.maxMemAllocSize); + if (!sharedCaps.sharedSystemAllocationsSupport) { + EXPECT_GE((4 * GB) - (8 * KB), sharedCaps.maxMemAllocSize); + } EXPECT_LE(65536u, sharedCaps.imageMaxBufferSize); EXPECT_GT(sharedCaps.maxWorkGroupSize, 0u); @@ -498,7 +500,9 @@ TEST_F(DeviceGetCapsTest, givenDeviceCapsWhenLocalMemoryIsEnabledThenCalculateGl EXPECT_EQ(sharedCaps.globalMemSize, expectedSize); } -TEST_F(DeviceGetCapsTest, givenGlobalMemSizeWhenCalculatingMaxAllocSizeThenAdjustToHWCap) { +TEST_F(DeviceGetCapsTest, givenGlobalMemSizeAndSharedSystemAllocationsNotSupportedWhenCalculatingMaxAllocSizeThenAdjustToHWCap) { + DebugManagerStateRestore dbgRestorer; + DebugManager.flags.EnableSharedSystemUsmSupport.set(0); auto device = std::unique_ptr(MockDevice::createWithNewExecutionEnvironment(defaultHwInfo.get())); const auto &caps = device->getDeviceInfo(); @@ -508,7 +512,20 @@ TEST_F(DeviceGetCapsTest, givenGlobalMemSizeWhenCalculatingMaxAllocSizeThenAdjus uint64_t expectedSize = std::max((caps.globalMemSize / 2), static_cast(128ULL * MemoryConstants::megaByte)); expectedSize = std::min(expectedSize, hwCaps.maxMemAllocSize); + EXPECT_EQ(caps.maxMemAllocSize, expectedSize); +} +TEST_F(DeviceGetCapsTest, givenGlobalMemSizeAndSharedSystemAllocationsSupportedWhenCalculatingMaxAllocSizeThenAdjustToGlobalMemSize) { + DebugManagerStateRestore dbgRestorer; + DebugManager.flags.EnableSharedSystemUsmSupport.set(1); + auto device = std::unique_ptr(MockDevice::createWithNewExecutionEnvironment(defaultHwInfo.get())); + const auto &caps = device->getDeviceInfo(); + + HardwareCapabilities hwCaps = {0}; + auto &hwHelper = HwHelper::get(defaultHwInfo->platform.eRenderCoreFamily); + hwHelper.setupHardwareCapabilities(&hwCaps, *defaultHwInfo); + + uint64_t expectedSize = std::max((caps.globalMemSize / 2), static_cast(128ULL * MemoryConstants::megaByte)); EXPECT_EQ(caps.maxMemAllocSize, expectedSize); } diff --git a/shared/source/device/device_caps.cpp b/shared/source/device/device_caps.cpp index 9cef7fea75..6969a67af9 100644 --- a/shared/source/device/device_caps.cpp +++ b/shared/source/device/device_caps.cpp @@ -37,6 +37,11 @@ void Device::initializeCaps() { addressing32bitAllowed = false; } + deviceInfo.sharedSystemAllocationsSupport = hwInfoConfig->getSharedSystemMemCapabilities(); + if (DebugManager.flags.EnableSharedSystemUsmSupport.get() != -1) { + deviceInfo.sharedSystemAllocationsSupport = DebugManager.flags.EnableSharedSystemUsmSupport.get(); + } + deviceInfo.vendorId = 0x8086; deviceInfo.maxReadImageArgs = 128; deviceInfo.maxWriteImageArgs = 128; @@ -67,7 +72,11 @@ void Device::initializeCaps() { deviceInfo.maxMemAllocSize = std::min(deviceInfo.globalMemSize, deviceInfo.maxMemAllocSize); // if globalMemSize was reduced for 32b // OpenCL 1.2 requires 128MB minimum - deviceInfo.maxMemAllocSize = std::min(std::max(deviceInfo.maxMemAllocSize / 2, static_cast(128llu * MB)), this->hardwareCapabilities.maxMemAllocSize); + deviceInfo.maxMemAllocSize = std::max(deviceInfo.maxMemAllocSize / 2, static_cast(128llu * MB)); + + if (!deviceInfo.sharedSystemAllocationsSupport) { + deviceInfo.maxMemAllocSize = std::min(deviceInfo.maxMemAllocSize, this->hardwareCapabilities.maxMemAllocSize); + } deviceInfo.profilingTimerResolution = getProfilingTimerResolution(); if (DebugManager.flags.OverrideProfilingTimerResolution.get() != -1) { @@ -139,11 +148,6 @@ void Device::initializeCaps() { this->preemptionMode = PreemptionMode::Disabled; } - deviceInfo.sharedSystemAllocationsSupport = hwInfoConfig->getSharedSystemMemCapabilities(); - if (DebugManager.flags.EnableSharedSystemUsmSupport.get() != -1) { - deviceInfo.sharedSystemAllocationsSupport = DebugManager.flags.EnableSharedSystemUsmSupport.get(); - } - std::stringstream deviceName; deviceName << this->getDeviceName(hwInfo);