diff --git a/runtime/device/device.cpp b/runtime/device/device.cpp index cb8b464ca6..f959736fb9 100644 --- a/runtime/device/device.cpp +++ b/runtime/device/device.cpp @@ -139,7 +139,7 @@ bool Device::createDeviceImpl(const HardwareInfo *pHwInfo, Device &outDevice) { outDevice.executionEnvironment->commandStreamReceiver.reset(commandStreamReceiver); if (!outDevice.executionEnvironment->memoryManager) { - outDevice.executionEnvironment->memoryManager.reset(commandStreamReceiver->createMemoryManager(outDevice.deviceInfo.enabled64kbPages)); + outDevice.executionEnvironment->memoryManager.reset(commandStreamReceiver->createMemoryManager(outDevice.getEnabled64kbPages())); } else { commandStreamReceiver->setMemoryManager(outDevice.executionEnvironment->memoryManager.get()); } diff --git a/runtime/device/device_caps.cpp b/runtime/device/device_caps.cpp index f035743067..b7e2792b10 100644 --- a/runtime/device/device_caps.cpp +++ b/runtime/device/device_caps.cpp @@ -351,7 +351,6 @@ void Device::initializeCaps() { deviceInfo.platformHostTimerResolution = getPlatformHostTimerResolution(); deviceInfo.internalDriverVersion = CL_DEVICE_DRIVER_VERSION_INTEL_NEO1; - deviceInfo.enabled64kbPages = getEnabled64kbPages(); deviceInfo.preferredGlobalAtomicAlignment = MemoryConstants::cacheLineSize; deviceInfo.preferredLocalAtomicAlignment = MemoryConstants::cacheLineSize; diff --git a/runtime/device/device_info.h b/runtime/device/device_info.h index 08addd83d8..9583e1c404 100644 --- a/runtime/device/device_info.h +++ b/runtime/device/device_info.h @@ -149,7 +149,6 @@ struct DeviceInfo { bool cpuCopyAllowed; bool packedYuvExtension; cl_uint internalDriverVersion; - bool enabled64kbPages; bool sourceLevelDebuggerActive; }; // clang-format on diff --git a/runtime/memory_manager/memory_manager.cpp b/runtime/memory_manager/memory_manager.cpp index 4d71f5ed86..667c4e0e99 100644 --- a/runtime/memory_manager/memory_manager.cpp +++ b/runtime/memory_manager/memory_manager.cpp @@ -113,7 +113,7 @@ void *MemoryManager::allocateSystemMemory(size_t size, size_t alignment) { GraphicsAllocation *MemoryManager::allocateGraphicsMemoryForSVM(size_t size, bool coherent) { GraphicsAllocation *graphicsAllocation = nullptr; - if (enable64kbpages) { + if (peek64kbPagesEnabled()) { graphicsAllocation = allocateGraphicsMemory64kb(size, MemoryConstants::pageSize64k, false); } else { graphicsAllocation = allocateGraphicsMemory(size); @@ -424,7 +424,7 @@ GraphicsAllocation *MemoryManager::allocateGraphicsMemory(const AllocationData & if (allocationData.hostPtr) { return allocateGraphicsMemory(allocationData.size, allocationData.hostPtr, allocationData.flags.forcePin); } - if (enable64kbpages && allocationData.flags.allow64kbPages) { + if (peek64kbPagesEnabled() && allocationData.flags.allow64kbPages) { return allocateGraphicsMemory64kb(allocationData.size, MemoryConstants::pageSize64k, allocationData.flags.forcePin); } return allocateGraphicsMemory(allocationData.size, MemoryConstants::pageSize, allocationData.flags.forcePin, allocationData.flags.uncacheable); diff --git a/runtime/memory_manager/memory_manager.h b/runtime/memory_manager/memory_manager.h index 83cd650fb1..27191da558 100644 --- a/runtime/memory_manager/memory_manager.h +++ b/runtime/memory_manager/memory_manager.h @@ -193,6 +193,7 @@ class MemoryManager { virtual GraphicsAllocation *createGraphicsAllocation(OsHandleStorage &handleStorage, size_t hostPtrSize, const void *hostPtr) = 0; + bool peek64kbPagesEnabled() const { return enable64kbpages; } bool peekForce32BitAllocations() { return force32bitAllocations; } void setForce32BitAllocations(bool newValue); diff --git a/unit_tests/api/cl_enqueue_svm_migrate_mem_tests.cpp b/unit_tests/api/cl_enqueue_svm_migrate_mem_tests.cpp index 9d9d4463b6..f3c8680479 100644 --- a/unit_tests/api/cl_enqueue_svm_migrate_mem_tests.cpp +++ b/unit_tests/api/cl_enqueue_svm_migrate_mem_tests.cpp @@ -24,6 +24,7 @@ #include "unit_tests/mocks/mock_context.h" #include "runtime/command_queue/command_queue.h" #include "runtime/device/device.h" +#include "runtime/memory_manager/svm_memory_manager.h" using namespace OCLRT; @@ -108,8 +109,12 @@ TEST_F(clEnqueueSVMMigrateMemTests, invalidValue_NonZeroSizeIsNotContainedWithin void *ptrSvm = clSVMAlloc(pContext, CL_MEM_READ_WRITE, 256, 4); ASSERT_NE(nullptr, ptrSvm); + auto svmAlloc = pContext->getSVMAllocsManager()->getSVMAlloc(ptrSvm); + EXPECT_NE(nullptr, svmAlloc); + size_t allocSize = svmAlloc->getUnderlyingBufferSize(); + const void *svmPtrs[] = {ptrSvm}; - const size_t sizes[] = {256 + 1}; + const size_t sizes[] = {allocSize + 1}; auto retVal = clEnqueueSVMMigrateMem( pCommandQueue, // cl_command_queue command_queue 1, // cl_uint num_svm_pointers diff --git a/unit_tests/api/cl_set_kernel_arg_svm_pointer_tests.cpp b/unit_tests/api/cl_set_kernel_arg_svm_pointer_tests.cpp index ec96bcde68..0b1f6f78aa 100644 --- a/unit_tests/api/cl_set_kernel_arg_svm_pointer_tests.cpp +++ b/unit_tests/api/cl_set_kernel_arg_svm_pointer_tests.cpp @@ -20,6 +20,7 @@ * OTHER DEALINGS IN THE SOFTWARE. */ +#include "runtime/memory_manager/svm_memory_manager.h" #include "cl_api_tests.h" #include "unit_tests/fixtures/device_fixture.h" #include "unit_tests/mocks/mock_kernel.h" @@ -193,8 +194,10 @@ TEST_F(clSetKernelArgSVMPointer_, SetKernelArgSVMPointerWithOffset_invalidArgVal const DeviceInfo &devInfo = pDevice->getDeviceInfo(); if (devInfo.svmCapabilities != 0) { void *ptrSvm = clSVMAlloc(pContext, CL_MEM_READ_WRITE, 256, 4); - size_t offset = alignUp(512, MemoryConstants::pageSize) + 1; - EXPECT_NE(nullptr, ptrSvm); + auto svmAlloc = pContext->getSVMAllocsManager()->getSVMAlloc(ptrSvm); + EXPECT_NE(nullptr, svmAlloc); + + size_t offset = svmAlloc->getUnderlyingBufferSize() + 1; auto retVal = clSetKernelArgSVMPointer( pMockKernel, // cl_kernel kernel diff --git a/unit_tests/memory_manager/memory_manager_tests.cpp b/unit_tests/memory_manager/memory_manager_tests.cpp index cbb80d6f01..bad3201ba6 100644 --- a/unit_tests/memory_manager/memory_manager_tests.cpp +++ b/unit_tests/memory_manager/memory_manager_tests.cpp @@ -25,8 +25,10 @@ #include "runtime/event/event.h" #include "runtime/mem_obj/image.h" #include "runtime/utilities/tag_allocator.h" +#include "runtime/os_interface/os_interface.h" #include "unit_tests/helpers/debug_manager_state_restore.h" #include "unit_tests/helpers/memory_management.h" +#include "unit_tests/helpers/variable_backup.h" #include "unit_tests/utilities/containers_tests_helpers.h" #include "unit_tests/fixtures/memory_allocator_fixture.h" #include "unit_tests/fixtures/memory_manager_fixture.h" @@ -863,6 +865,26 @@ TEST(OsAgnosticMemoryManager, givenMemoryManagerWith64KBPagesDisabledWhenAllocat memoryManager.freeGraphicsMemory(svmAllocation); } +TEST(OsAgnosticMemoryManager, givenDeviceWith64kbPagesEnabledWhenCreatingMemoryManagerThenAllowFor64kbAllocations) { + VariableBackup os64kbPagesEnabled(&OSInterface::osEnabled64kbPages, true); + + HardwareInfo localHwInfo = *platformDevices[0]; + localHwInfo.capabilityTable.ftr64KBpages = true; + + std::unique_ptr device(MockDevice::createWithNewExecutionEnvironment(&localHwInfo)); + EXPECT_TRUE(device->getEnabled64kbPages()); + EXPECT_TRUE(device->getMemoryManager()->peek64kbPagesEnabled()); +} + +TEST(OsAgnosticMemoryManager, givenDeviceWith64kbPagesDisbledWhenCreatingMemoryManagerThenDisallowFor64kbAllocations) { + HardwareInfo localHwInfo = *platformDevices[0]; + localHwInfo.capabilityTable.ftr64KBpages = false; + + std::unique_ptr device(MockDevice::createWithNewExecutionEnvironment(&localHwInfo)); + EXPECT_FALSE(device->getEnabled64kbPages()); + EXPECT_FALSE(device->getMemoryManager()->peek64kbPagesEnabled()); +} + TEST(OsAgnosticMemoryManager, givenMemoryManagerWith64KBPagesEnabledWhenAllocateGraphicsMemoryForSVMIsCalledThen64KBGraphicsAllocationIsReturned) { OsAgnosticMemoryManager memoryManager(true); auto size = 4096u;