mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-05 09:09:04 +08:00
Cleanup host ptr manager
Change-Id: I0fc9df41a08255eef8072666c1c5c16806e0f7cf Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
committed by
sys_ocldev
parent
e128cb7a7c
commit
129380c1a6
@@ -17,6 +17,7 @@
|
||||
#include "runtime/helpers/ptr_math.h"
|
||||
#include "runtime/helpers/string.h"
|
||||
#include "runtime/helpers/validators.h"
|
||||
#include "runtime/memory_manager/host_ptr_manager.h"
|
||||
#include "runtime/memory_manager/memory_manager.h"
|
||||
#include "runtime/memory_manager/svm_memory_manager.h"
|
||||
#include "runtime/os_interface/debug_settings_manager.h"
|
||||
@@ -238,19 +239,19 @@ void Buffer::checkMemory(cl_mem_flags flags,
|
||||
cl_int &errcodeRet,
|
||||
bool &alignementSatisfied,
|
||||
bool ©MemoryFromHostPtr,
|
||||
MemoryManager *memMngr) {
|
||||
MemoryManager *memoryManager) {
|
||||
errcodeRet = CL_SUCCESS;
|
||||
alignementSatisfied = true;
|
||||
copyMemoryFromHostPtr = false;
|
||||
uintptr_t minAddress = 0;
|
||||
auto memRestrictions = memMngr->getAlignedMallocRestrictions();
|
||||
auto memRestrictions = memoryManager->getAlignedMallocRestrictions();
|
||||
if (memRestrictions) {
|
||||
minAddress = memRestrictions->minAddress;
|
||||
}
|
||||
|
||||
if (flags & CL_MEM_USE_HOST_PTR) {
|
||||
if (hostPtr) {
|
||||
auto fragment = memMngr->hostPtrManager.getFragment(hostPtr);
|
||||
auto fragment = memoryManager->getHostPtrManager()->getFragment(hostPtr);
|
||||
if (fragment && fragment->driverAllocation) {
|
||||
errcodeRet = CL_INVALID_HOST_PTR;
|
||||
return;
|
||||
|
||||
@@ -6,13 +6,12 @@
|
||||
*/
|
||||
|
||||
#include "runtime/command_stream/command_stream_receiver.h"
|
||||
#include "runtime/helpers/ptr_math.h"
|
||||
#include "runtime/helpers/abort.h"
|
||||
#include "runtime/memory_manager/host_ptr_manager.h"
|
||||
#include "runtime/memory_manager/memory_manager.h"
|
||||
|
||||
using namespace OCLRT;
|
||||
|
||||
std::map<const void *, FragmentStorage>::iterator HostPtrManager::findElement(const void *ptr) {
|
||||
HostPtrFragmentsContainer::iterator HostPtrManager::findElement(const void *ptr) {
|
||||
auto nextElement = partialAllocations.lower_bound(ptr);
|
||||
auto element = nextElement;
|
||||
if (element != partialAllocations.end()) {
|
||||
|
||||
@@ -7,33 +7,29 @@
|
||||
|
||||
#pragma once
|
||||
#include <map>
|
||||
#include "runtime/helpers/aligned_memory.h"
|
||||
#include "runtime/memory_manager/graphics_allocation.h"
|
||||
#include <mutex>
|
||||
#include "runtime/memory_manager/host_ptr_defines.h"
|
||||
|
||||
namespace OCLRT {
|
||||
|
||||
typedef std::map<const void *, FragmentStorage> HostPtrFragmentsContainer;
|
||||
using HostPtrFragmentsContainer = std::map<const void *, FragmentStorage>;
|
||||
class MemoryManager;
|
||||
class HostPtrManager {
|
||||
public:
|
||||
static AllocationRequirements getAllocationRequirements(const void *inputPtr, size_t size);
|
||||
OsHandleStorage populateAlreadyAllocatedFragments(AllocationRequirements &requirements, CheckedFragments *checkedFragments);
|
||||
void storeFragment(FragmentStorage &fragment);
|
||||
void storeFragment(AllocationStorageData &storageData);
|
||||
|
||||
FragmentStorage *getFragment(const void *inputPtr);
|
||||
OsHandleStorage prepareOsStorageForAllocation(MemoryManager &memoryManager, size_t size, const void *ptr);
|
||||
void releaseHandleStorage(OsHandleStorage &fragments);
|
||||
bool releaseHostPtr(const void *ptr);
|
||||
void storeFragment(AllocationStorageData &storageData);
|
||||
void storeFragment(FragmentStorage &fragment);
|
||||
|
||||
FragmentStorage *getFragment(const void *inputPtr);
|
||||
size_t getFragmentCount() { return partialAllocations.size(); }
|
||||
protected:
|
||||
static AllocationRequirements getAllocationRequirements(const void *inputPtr, size_t size);
|
||||
OsHandleStorage populateAlreadyAllocatedFragments(AllocationRequirements &requirements, CheckedFragments *checkedFragments);
|
||||
FragmentStorage *getFragmentAndCheckForOverlaps(const void *inputPtr, size_t size, OverlapStatus &overlappingStatus);
|
||||
OsHandleStorage prepareOsStorageForAllocation(MemoryManager &memoryManager, size_t size, const void *ptr);
|
||||
RequirementsStatus checkAllocationsForOverlapping(MemoryManager &memoryManager, AllocationRequirements *requirements, CheckedFragments *checkedFragments);
|
||||
|
||||
private:
|
||||
std::map<const void *, FragmentStorage>::iterator findElement(const void *ptr);
|
||||
|
||||
HostPtrFragmentsContainer::iterator findElement(const void *ptr);
|
||||
HostPtrFragmentsContainer partialAllocations;
|
||||
std::recursive_mutex allocationsMutex;
|
||||
};
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "runtime/helpers/options.h"
|
||||
#include "runtime/helpers/timestamp_packet.h"
|
||||
#include "runtime/memory_manager/deferred_deleter.h"
|
||||
#include "runtime/memory_manager/host_ptr_manager.h"
|
||||
#include "runtime/memory_manager/internal_allocation_storage.h"
|
||||
#include "runtime/os_interface/os_context.h"
|
||||
#include "runtime/utilities/stackvec.h"
|
||||
@@ -60,7 +61,8 @@ GraphicsAllocation *AllocationsList::detachAllocationImpl(GraphicsAllocation *,
|
||||
MemoryManager::MemoryManager(bool enable64kbpages, bool enableLocalMemory,
|
||||
ExecutionEnvironment &executionEnvironment) : allocator32Bit(nullptr), enable64kbpages(enable64kbpages),
|
||||
localMemorySupported(enableLocalMemory),
|
||||
executionEnvironment(executionEnvironment){};
|
||||
executionEnvironment(executionEnvironment),
|
||||
hostPtrManager(std::make_unique<HostPtrManager>()){};
|
||||
|
||||
MemoryManager::~MemoryManager() {
|
||||
for (auto osContext : registeredOsContexts) {
|
||||
@@ -119,7 +121,7 @@ GraphicsAllocation *MemoryManager::allocateGraphicsMemory(size_t size, const voi
|
||||
deferredDeleter->drain(true);
|
||||
}
|
||||
GraphicsAllocation *graphicsAllocation = nullptr;
|
||||
auto osStorage = hostPtrManager.prepareOsStorageForAllocation(*this, size, ptr);
|
||||
auto osStorage = hostPtrManager->prepareOsStorageForAllocation(*this, size, ptr);
|
||||
if (osStorage.fragmentCount > 0) {
|
||||
graphicsAllocation = createGraphicsAllocation(osStorage, size, ptr);
|
||||
}
|
||||
@@ -127,7 +129,7 @@ GraphicsAllocation *MemoryManager::allocateGraphicsMemory(size_t size, const voi
|
||||
}
|
||||
|
||||
void MemoryManager::cleanGraphicsMemoryCreatedFromHostPtr(GraphicsAllocation *graphicsAllocation) {
|
||||
hostPtrManager.releaseHandleStorage(graphicsAllocation->fragmentsStorage);
|
||||
hostPtrManager->releaseHandleStorage(graphicsAllocation->fragmentsStorage);
|
||||
cleanOsHandles(graphicsAllocation->fragmentsStorage);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
#include "runtime/helpers/aligned_memory.h"
|
||||
#include "runtime/memory_manager/graphics_allocation.h"
|
||||
#include "runtime/memory_manager/host_ptr_defines.h"
|
||||
#include "runtime/memory_manager/host_ptr_manager.h"
|
||||
#include "runtime/os_interface/32bit_memory.h"
|
||||
|
||||
#include <cstdint>
|
||||
@@ -22,6 +21,7 @@ class Device;
|
||||
class DeferredDeleter;
|
||||
class ExecutionEnvironment;
|
||||
class GraphicsAllocation;
|
||||
class HostPtrManager;
|
||||
class CommandStreamReceiver;
|
||||
class OsContext;
|
||||
class TimestampPacket;
|
||||
@@ -213,8 +213,6 @@ class MemoryManager {
|
||||
|
||||
MOCKABLE_VIRTUAL std::unique_ptr<GraphicsAllocation> obtainReusableAllocation(size_t requiredSize, bool isInternalAllocationRequired);
|
||||
|
||||
HostPtrManager hostPtrManager;
|
||||
|
||||
virtual GraphicsAllocation *createGraphicsAllocation(OsHandleStorage &handleStorage, size_t hostPtrSize, const void *hostPtr) = 0;
|
||||
|
||||
bool peek64kbPagesEnabled() const { return enable64kbpages; }
|
||||
@@ -252,6 +250,7 @@ class MemoryManager {
|
||||
void registerOsContext(OsContext *contextToRegister);
|
||||
size_t getOsContextCount() { return registeredOsContexts.size(); }
|
||||
CommandStreamReceiver *getCommandStreamReceiver(uint32_t contextId);
|
||||
HostPtrManager *getHostPtrManager() const { return hostPtrManager.get(); }
|
||||
|
||||
protected:
|
||||
static bool getAllocationData(AllocationData &allocationData, const AllocationFlags &flags, const DevicesBitfield devicesBitfield,
|
||||
@@ -271,6 +270,7 @@ class MemoryManager {
|
||||
bool localMemorySupported = false;
|
||||
ExecutionEnvironment &executionEnvironment;
|
||||
std::vector<OsContext *> registeredOsContexts;
|
||||
std::unique_ptr<HostPtrManager> hostPtrManager;
|
||||
};
|
||||
|
||||
std::unique_ptr<DeferredDeleter> createDeferredDeleter();
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "runtime/helpers/options.h"
|
||||
#include "runtime/helpers/ptr_math.h"
|
||||
#include "runtime/helpers/surface_formats.h"
|
||||
#include "runtime/memory_manager/host_ptr_manager.h"
|
||||
#include <cassert>
|
||||
|
||||
namespace OCLRT {
|
||||
@@ -132,16 +133,16 @@ void OsAgnosticMemoryManager::addAllocationToHostPtrManager(GraphicsAllocation *
|
||||
fragment.fragmentSize = alignUp(gfxAllocation->getUnderlyingBufferSize(), MemoryConstants::pageSize);
|
||||
fragment.osInternalStorage = new OsHandle();
|
||||
fragment.residency = new ResidencyData();
|
||||
hostPtrManager.storeFragment(fragment);
|
||||
hostPtrManager->storeFragment(fragment);
|
||||
}
|
||||
|
||||
void OsAgnosticMemoryManager::removeAllocationFromHostPtrManager(GraphicsAllocation *gfxAllocation) {
|
||||
auto buffer = gfxAllocation->getUnderlyingBuffer();
|
||||
auto fragment = hostPtrManager.getFragment(buffer);
|
||||
auto fragment = hostPtrManager->getFragment(buffer);
|
||||
if (fragment && fragment->driverAllocation) {
|
||||
OsHandle *osStorageToRelease = fragment->osInternalStorage;
|
||||
ResidencyData *residencyDataToRelease = fragment->residency;
|
||||
if (hostPtrManager.releaseHostPtr(buffer)) {
|
||||
if (hostPtrManager->releaseHostPtr(buffer)) {
|
||||
delete osStorageToRelease;
|
||||
delete residencyDataToRelease;
|
||||
}
|
||||
@@ -210,7 +211,7 @@ MemoryManager::AllocationStatus OsAgnosticMemoryManager::populateOsHandles(OsHan
|
||||
newFragment.fragmentSize = handleStorage.fragmentStorageData[i].fragmentSize;
|
||||
newFragment.osInternalStorage = handleStorage.fragmentStorageData[i].osHandleStorage;
|
||||
newFragment.residency = handleStorage.fragmentStorageData[i].residency;
|
||||
hostPtrManager.storeFragment(newFragment);
|
||||
hostPtrManager->storeFragment(newFragment);
|
||||
}
|
||||
}
|
||||
return AllocationStatus::Success;
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "runtime/device/device.h"
|
||||
#include "runtime/helpers/ptr_math.h"
|
||||
#include "runtime/helpers/options.h"
|
||||
#include "runtime/memory_manager/host_ptr_manager.h"
|
||||
#include "runtime/os_interface/32bit_memory.h"
|
||||
#include "runtime/os_interface/linux/drm_allocation.h"
|
||||
#include "runtime/os_interface/linux/drm_buffer_object.h"
|
||||
@@ -406,16 +407,16 @@ void DrmMemoryManager::addAllocationToHostPtrManager(GraphicsAllocation *gfxAllo
|
||||
fragment.osInternalStorage = new OsHandle();
|
||||
fragment.residency = new ResidencyData();
|
||||
fragment.osInternalStorage->bo = drmMemory->getBO();
|
||||
hostPtrManager.storeFragment(fragment);
|
||||
hostPtrManager->storeFragment(fragment);
|
||||
}
|
||||
|
||||
void DrmMemoryManager::removeAllocationFromHostPtrManager(GraphicsAllocation *gfxAllocation) {
|
||||
auto buffer = gfxAllocation->getUnderlyingBuffer();
|
||||
auto fragment = hostPtrManager.getFragment(buffer);
|
||||
auto fragment = hostPtrManager->getFragment(buffer);
|
||||
if (fragment && fragment->driverAllocation) {
|
||||
OsHandle *osStorageToRelease = fragment->osInternalStorage;
|
||||
ResidencyData *residencyDataToRelease = fragment->residency;
|
||||
if (hostPtrManager.releaseHostPtr(buffer)) {
|
||||
if (hostPtrManager->releaseHostPtr(buffer)) {
|
||||
delete osStorageToRelease;
|
||||
delete residencyDataToRelease;
|
||||
}
|
||||
@@ -509,7 +510,7 @@ MemoryManager::AllocationStatus DrmMemoryManager::populateOsHandles(OsHandleStor
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < numberOfBosAllocated; i++) {
|
||||
hostPtrManager.storeFragment(handleStorage.fragmentStorageData[indexesOfAllocatedBos[i]]);
|
||||
hostPtrManager->storeFragment(handleStorage.fragmentStorageData[indexesOfAllocatedBos[i]]);
|
||||
}
|
||||
return AllocationStatus::Success;
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "runtime/helpers/surface_formats.h"
|
||||
#include "runtime/memory_manager/deferrable_deletion.h"
|
||||
#include "runtime/memory_manager/deferred_deleter.h"
|
||||
#include "runtime/memory_manager/host_ptr_manager.h"
|
||||
#include "runtime/os_interface/windows/wddm/wddm.h"
|
||||
#include "runtime/os_interface/windows/wddm_allocation.h"
|
||||
#include "runtime/os_interface/windows/wddm_residency_controller.h"
|
||||
@@ -285,15 +286,15 @@ void WddmMemoryManager::addAllocationToHostPtrManager(GraphicsAllocation *gfxAll
|
||||
fragment.osInternalStorage->handle = wddmMemory->handle;
|
||||
fragment.osInternalStorage->gmm = gfxAllocation->gmm;
|
||||
fragment.residency = &wddmMemory->getResidencyData();
|
||||
hostPtrManager.storeFragment(fragment);
|
||||
hostPtrManager->storeFragment(fragment);
|
||||
}
|
||||
|
||||
void WddmMemoryManager::removeAllocationFromHostPtrManager(GraphicsAllocation *gfxAllocation) {
|
||||
auto buffer = gfxAllocation->getUnderlyingBuffer();
|
||||
auto fragment = hostPtrManager.getFragment(buffer);
|
||||
auto fragment = hostPtrManager->getFragment(buffer);
|
||||
if (fragment && fragment->driverAllocation) {
|
||||
OsHandle *osStorageToRelease = fragment->osInternalStorage;
|
||||
if (hostPtrManager.releaseHostPtr(buffer)) {
|
||||
if (hostPtrManager->releaseHostPtr(buffer)) {
|
||||
delete osStorageToRelease;
|
||||
}
|
||||
}
|
||||
@@ -406,7 +407,7 @@ MemoryManager::AllocationStatus WddmMemoryManager::populateOsHandles(OsHandleSto
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < allocatedFragmentsCounter; i++) {
|
||||
hostPtrManager.storeFragment(handleStorage.fragmentStorageData[allocatedFragmentIndexes[i]]);
|
||||
hostPtrManager->storeFragment(handleStorage.fragmentStorageData[allocatedFragmentIndexes[i]]);
|
||||
}
|
||||
|
||||
return AllocationStatus::Success;
|
||||
@@ -442,7 +443,7 @@ void WddmMemoryManager::cleanOsHandles(OsHandleStorage &handleStorage) {
|
||||
void WddmMemoryManager::obtainGpuAddresFromFragments(WddmAllocation *allocation, OsHandleStorage &handleStorage) {
|
||||
if (this->force32bitAllocations && (handleStorage.fragmentCount > 0)) {
|
||||
auto hostPtr = allocation->getUnderlyingBuffer();
|
||||
auto fragment = hostPtrManager.getFragment(hostPtr);
|
||||
auto fragment = hostPtrManager->getFragment(hostPtr);
|
||||
if (fragment && fragment->driverAllocation) {
|
||||
auto gpuPtr = handleStorage.fragmentStorageData[0].osHandleStorage->gpuPtr;
|
||||
for (uint32_t i = 1; i < handleStorage.fragmentCount; i++) {
|
||||
|
||||
Reference in New Issue
Block a user