diff --git a/runtime/device/device.cpp b/runtime/device/device.cpp index a266bcaad0..715e5c39e7 100644 --- a/runtime/device/device.cpp +++ b/runtime/device/device.cpp @@ -142,10 +142,7 @@ bool Device::createDeviceImpl(const HardwareInfo *pHwInfo) { executionEnvironment->memoryManager->setForce32BitAllocations(getDeviceInfo().force32BitAddressess); if (preemptionMode == PreemptionMode::MidThread || isSourceLevelDebuggerActive()) { - AllocationProperties properties(true, pHwInfo->capabilityTable.requiredPreemptionSurfaceSize, GraphicsAllocation::AllocationType::UNDECIDED); - properties.flags.uncacheable = getWaTable()->waCSRUncachable; - properties.alignment = 256 * MemoryConstants::kiloByte; - preemptionAllocation = executionEnvironment->memoryManager->allocateGraphicsMemoryWithProperties(properties); + preemptionAllocation = executionEnvironment->memoryManager->allocateGraphicsMemoryWithProperties(getAllocationPropertiesForPreemption()); if (!preemptionAllocation) { return false; } @@ -162,6 +159,12 @@ bool Device::createDeviceImpl(const HardwareInfo *pHwInfo) { return true; } +AllocationProperties Device::getAllocationPropertiesForPreemption() const { + AllocationProperties properties{true, getHardwareInfo().capabilityTable.requiredPreemptionSurfaceSize, GraphicsAllocation::AllocationType::PREEMPTION}; + properties.flags.uncacheable = getWaTable()->waCSRUncachable; + properties.alignment = 256 * MemoryConstants::kiloByte; + return properties; +} bool Device::createEngines(const HardwareInfo *pHwInfo) { auto defaultEngineType = getChosenEngineType(*pHwInfo); auto &gpgpuEngines = HwHelper::get(pHwInfo->pPlatform->eRenderCoreFamily).getGpgpuEngineInstances(); diff --git a/runtime/device/device.h b/runtime/device/device.h index 02664c053d..068c7bd178 100644 --- a/runtime/device/device.h +++ b/runtime/device/device.h @@ -139,6 +139,7 @@ class Device : public BaseObject<_cl_device_id> { MOCKABLE_VIRTUAL void initializeCaps(); void setupFp64Flags(); void appendOSExtensions(std::string &deviceExtensions); + AllocationProperties getAllocationPropertiesForPreemption() const; unsigned int enabledClVersion = 0u; diff --git a/runtime/mem_obj/image.cpp b/runtime/mem_obj/image.cpp index 3270e755aa..9878c896ef 100644 --- a/runtime/mem_obj/image.cpp +++ b/runtime/mem_obj/image.cpp @@ -237,7 +237,7 @@ Image *Image::create(Context *context, } } else { gmm = new Gmm(imgInfo); - memory = memoryManager->allocateGraphicsMemoryWithProperties({false, imgInfo.size, GraphicsAllocation::AllocationType::UNDECIDED}, hostPtr); + memory = memoryManager->allocateGraphicsMemoryWithProperties({false, imgInfo.size, GraphicsAllocation::AllocationType::SHARED_CONTEXT_IMAGE}, hostPtr); memory->setDefaultGmm(gmm); zeroCopy = true; } diff --git a/runtime/memory_manager/graphics_allocation.h b/runtime/memory_manager/graphics_allocation.h index 2f0615e945..de4dc28362 100644 --- a/runtime/memory_manager/graphics_allocation.h +++ b/runtime/memory_manager/graphics_allocation.h @@ -56,13 +56,16 @@ class GraphicsAllocation : public IDNode { INTERNAL_HOST_MEMORY, KERNEL_ISA, LINEAR_STREAM, + MCS, PIPE, + PREEMPTION, PRINTF_SURFACE, PRIVATE_SURFACE, PROFILING_TAG_BUFFER, SCRATCH_SURFACE, - SHARED_IMAGE, SHARED_BUFFER, + SHARED_CONTEXT_IMAGE, + SHARED_IMAGE, SHARED_RESOURCE_COPY, SURFACE_STATE_HEAP, SVM_CPU, diff --git a/runtime/memory_manager/memory_manager.cpp b/runtime/memory_manager/memory_manager.cpp index 30904271a5..995b427840 100644 --- a/runtime/memory_manager/memory_manager.cpp +++ b/runtime/memory_manager/memory_manager.cpp @@ -274,9 +274,12 @@ bool MemoryManager::getAllocationData(AllocationData &allocationData, const Allo case GraphicsAllocation::AllocationType::EXTERNAL_HOST_PTR: case GraphicsAllocation::AllocationType::FILL_PATTERN: case GraphicsAllocation::AllocationType::GLOBAL_SURFACE: + case GraphicsAllocation::AllocationType::MCS: case GraphicsAllocation::AllocationType::PIPE: + case GraphicsAllocation::AllocationType::PREEMPTION: case GraphicsAllocation::AllocationType::PRINTF_SURFACE: case GraphicsAllocation::AllocationType::PROFILING_TAG_BUFFER: + case GraphicsAllocation::AllocationType::SHARED_CONTEXT_IMAGE: case GraphicsAllocation::AllocationType::SVM_CPU: case GraphicsAllocation::AllocationType::SVM_ZERO_COPY: case GraphicsAllocation::AllocationType::TAG_BUFFER: diff --git a/runtime/os_interface/debug_settings_manager.cpp b/runtime/os_interface/debug_settings_manager.cpp index 912fa6c07d..8dda35358b 100644 --- a/runtime/os_interface/debug_settings_manager.cpp +++ b/runtime/os_interface/debug_settings_manager.cpp @@ -339,8 +339,12 @@ const char *DebugSettingsManager::getAllocationTypeString(GraphicsAl return "KERNEL_ISA"; case GraphicsAllocation::AllocationType::LINEAR_STREAM: return "LINEAR_STREAM"; + case GraphicsAllocation::AllocationType::MCS: + return "MCS"; case GraphicsAllocation::AllocationType::PIPE: return "PIPE"; + case GraphicsAllocation::AllocationType::PREEMPTION: + return "PREEMPTION"; case GraphicsAllocation::AllocationType::PRINTF_SURFACE: return "PRINTF_SURFACE"; case GraphicsAllocation::AllocationType::PRIVATE_SURFACE: @@ -351,6 +355,8 @@ const char *DebugSettingsManager::getAllocationTypeString(GraphicsAl return "SCRATCH_SURFACE"; case GraphicsAllocation::AllocationType::SHARED_BUFFER: return "SHARED_BUFFER"; + case GraphicsAllocation::AllocationType::SHARED_CONTEXT_IMAGE: + return "SHARED_CONTEXT_IMAGE"; case GraphicsAllocation::AllocationType::SHARED_IMAGE: return "SHARED_IMAGE"; case GraphicsAllocation::AllocationType::SHARED_RESOURCE_COPY: diff --git a/runtime/sharings/gl/gl_texture.cpp b/runtime/sharings/gl/gl_texture.cpp index d9faabedf5..dcc5fceb35 100644 --- a/runtime/sharings/gl/gl_texture.cpp +++ b/runtime/sharings/gl/gl_texture.cpp @@ -45,7 +45,7 @@ Image *GlTexture::createSharedGlTexture(Context *context, cl_mem_flags flags, cl errorCode.set(CL_SUCCESS); - AllocationProperties allocProperties(nullptr, false, GraphicsAllocation::AllocationType::SHARED_IMAGE); + AllocationProperties allocProperties(false, 0u, GraphicsAllocation::AllocationType::SHARED_IMAGE); auto alloc = memoryManager->createGraphicsAllocationFromSharedHandle(texInfo.globalShareHandle, allocProperties, false); if (alloc == nullptr) { @@ -114,7 +114,7 @@ Image *GlTexture::createSharedGlTexture(Context *context, cl_mem_flags flags, cl GraphicsAllocation *mcsAlloc = nullptr; if (texInfo.globalShareHandleMCS) { - AllocationProperties allocProperties(0, GraphicsAllocation::AllocationType::UNDECIDED); + AllocationProperties allocProperties(0, GraphicsAllocation::AllocationType::MCS); mcsAlloc = memoryManager->createGraphicsAllocationFromSharedHandle(texInfo.globalShareHandleMCS, allocProperties, false); if (texInfo.pGmmResInfoMCS) { DEBUG_BREAK_IF(mcsAlloc->getDefaultGmm() != nullptr); diff --git a/unit_tests/memory_manager/memory_manager_allocate_in_preferred_pool_tests.inl b/unit_tests/memory_manager/memory_manager_allocate_in_preferred_pool_tests.inl index e4d4bea55e..a371fa80cf 100644 --- a/unit_tests/memory_manager/memory_manager_allocate_in_preferred_pool_tests.inl +++ b/unit_tests/memory_manager/memory_manager_allocate_in_preferred_pool_tests.inl @@ -368,6 +368,24 @@ TEST(MemoryManagerTest, givenTagBufferTypeWhenGetAllocationDataIsCalledThenSyste EXPECT_TRUE(allocData.flags.useSystemMemory); } +TEST(MemoryManagerTest, givenPreemptionTypeWhenGetAllocationDataIsCalledThenSystemMemoryIsRequested) { + AllocationData allocData; + MockMemoryManager::getAllocationData(allocData, {1, GraphicsAllocation::AllocationType::PREEMPTION}, {}, nullptr); + EXPECT_TRUE(allocData.flags.useSystemMemory); +} + +TEST(MemoryManagerTest, givenSharedContextImageTypeWhenGetAllocationDataIsCalledThenSystemMemoryIsRequested) { + AllocationData allocData; + MockMemoryManager::getAllocationData(allocData, {1, GraphicsAllocation::AllocationType::SHARED_CONTEXT_IMAGE}, {}, nullptr); + EXPECT_TRUE(allocData.flags.useSystemMemory); +} + +TEST(MemoryManagerTest, givenMCSTypeWhenGetAllocationDataIsCalledThenSystemMemoryIsRequested) { + AllocationData allocData; + MockMemoryManager::getAllocationData(allocData, {1, GraphicsAllocation::AllocationType::MCS}, {}, nullptr); + EXPECT_TRUE(allocData.flags.useSystemMemory); +} + TEST(MemoryManagerTest, givenDeviceQueueBufferTypeWhenGetAllocationDataIsCalledThenSystemMemoryIsRequested) { AllocationData allocData; MockMemoryManager::getAllocationData(allocData, {1, GraphicsAllocation::AllocationType::DEVICE_QUEUE_BUFFER}, {}, nullptr); diff --git a/unit_tests/mocks/mock_device.h b/unit_tests/mocks/mock_device.h index f2fa360965..7d467a50d5 100644 --- a/unit_tests/mocks/mock_device.h +++ b/unit_tests/mocks/mock_device.h @@ -102,10 +102,7 @@ class MockDevice : public Device { void allocatePreemptionAllocationIfNotPresent() { if (this->preemptionAllocation == nullptr) { if (preemptionMode == PreemptionMode::MidThread || isSourceLevelDebuggerActive()) { - MockAllocationProperties allocationProperties(hwInfo.capabilityTable.requiredPreemptionSurfaceSize); - allocationProperties.flags.uncacheable = getWaTable()->waCSRUncachable; - allocationProperties.alignment = 256 * MemoryConstants::kiloByte; - this->preemptionAllocation = executionEnvironment->memoryManager->allocateGraphicsMemoryWithProperties(allocationProperties); + this->preemptionAllocation = executionEnvironment->memoryManager->allocateGraphicsMemoryWithProperties(getAllocationPropertiesForPreemption()); this->engines[defaultEngineIndex].commandStreamReceiver->setPreemptionCsrAllocation(preemptionAllocation); } } diff --git a/unit_tests/os_interface/debug_settings_manager_tests.cpp b/unit_tests/os_interface/debug_settings_manager_tests.cpp index ad2d065ff6..4ecbac1847 100644 --- a/unit_tests/os_interface/debug_settings_manager_tests.cpp +++ b/unit_tests/os_interface/debug_settings_manager_tests.cpp @@ -908,12 +908,15 @@ AllocationTypeTestCase allocationTypeValues[] = { {GraphicsAllocation::AllocationType::INTERNAL_HOST_MEMORY, "INTERNAL_HOST_MEMORY"}, {GraphicsAllocation::AllocationType::KERNEL_ISA, "KERNEL_ISA"}, {GraphicsAllocation::AllocationType::LINEAR_STREAM, "LINEAR_STREAM"}, + {GraphicsAllocation::AllocationType::MCS, "MCS"}, {GraphicsAllocation::AllocationType::PIPE, "PIPE"}, + {GraphicsAllocation::AllocationType::PREEMPTION, "PREEMPTION"}, {GraphicsAllocation::AllocationType::PRINTF_SURFACE, "PRINTF_SURFACE"}, {GraphicsAllocation::AllocationType::PRIVATE_SURFACE, "PRIVATE_SURFACE"}, {GraphicsAllocation::AllocationType::PROFILING_TAG_BUFFER, "PROFILING_TAG_BUFFER"}, {GraphicsAllocation::AllocationType::SCRATCH_SURFACE, "SCRATCH_SURFACE"}, {GraphicsAllocation::AllocationType::SHARED_BUFFER, "SHARED_BUFFER"}, + {GraphicsAllocation::AllocationType::SHARED_CONTEXT_IMAGE, "SHARED_CONTEXT_IMAGE"}, {GraphicsAllocation::AllocationType::SHARED_IMAGE, "SHARED_IMAGE"}, {GraphicsAllocation::AllocationType::SHARED_RESOURCE_COPY, "SHARED_RESOURCE_COPY"}, {GraphicsAllocation::AllocationType::SURFACE_STATE_HEAP, "SURFACE_STATE_HEAP"},