2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2022-09-01 23:54:57 +08:00
|
|
|
* Copyright (C) 2018-2022 Intel Corporation
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
2018-09-18 15:11:08 +08:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/memory_manager/host_ptr_defines.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
#include <map>
|
2018-10-24 14:46:54 +08:00
|
|
|
#include <mutex>
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
namespace NEO {
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2020-07-07 14:41:26 +08:00
|
|
|
struct HostPtrEntryKey {
|
|
|
|
const void *ptr = nullptr;
|
|
|
|
uint32_t rootDeviceIndex = std::numeric_limits<uint32_t>::max();
|
|
|
|
|
|
|
|
bool operator<(const HostPtrEntryKey &key) const {
|
|
|
|
return rootDeviceIndex < key.rootDeviceIndex ||
|
|
|
|
((ptr < key.ptr) && (rootDeviceIndex == key.rootDeviceIndex));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
using HostPtrFragmentsContainer = std::map<HostPtrEntryKey, FragmentStorage>;
|
2018-10-23 17:42:40 +08:00
|
|
|
class MemoryManager;
|
2017-12-21 07:45:38 +08:00
|
|
|
class HostPtrManager {
|
|
|
|
public:
|
2020-07-07 14:41:26 +08:00
|
|
|
FragmentStorage *getFragment(HostPtrEntryKey key);
|
2019-11-15 16:59:48 +08:00
|
|
|
OsHandleStorage prepareOsStorageForAllocation(MemoryManager &memoryManager, size_t size, const void *ptr, uint32_t rootDeviceIndex);
|
2020-07-07 14:41:26 +08:00
|
|
|
void releaseHandleStorage(uint32_t rootDeviceIndex, OsHandleStorage &fragments);
|
|
|
|
bool releaseHostPtr(uint32_t rootDeviceIndex, const void *ptr);
|
|
|
|
void storeFragment(uint32_t rootDeviceIndex, AllocationStorageData &storageData);
|
|
|
|
void storeFragment(uint32_t rootDeviceIndex, FragmentStorage &fragment);
|
2022-09-01 23:54:57 +08:00
|
|
|
[[nodiscard]] std::unique_lock<std::recursive_mutex> obtainOwnership();
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2018-10-24 14:46:54 +08:00
|
|
|
protected:
|
2020-07-07 14:41:26 +08:00
|
|
|
static AllocationRequirements getAllocationRequirements(uint32_t rootDeviceIndex, const void *inputPtr, size_t size);
|
2019-06-03 20:49:20 +08:00
|
|
|
OsHandleStorage populateAlreadyAllocatedFragments(AllocationRequirements &requirements);
|
2020-07-07 14:41:26 +08:00
|
|
|
FragmentStorage *getFragmentAndCheckForOverlaps(uint32_t rootDeviceIndex, const void *inputPtr, size_t size, OverlapStatus &overlappingStatus);
|
2019-06-03 20:49:20 +08:00
|
|
|
RequirementsStatus checkAllocationsForOverlapping(MemoryManager &memoryManager, AllocationRequirements *requirements);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2020-07-07 14:41:26 +08:00
|
|
|
HostPtrFragmentsContainer::iterator findElement(HostPtrEntryKey key);
|
2017-12-21 07:45:38 +08:00
|
|
|
HostPtrFragmentsContainer partialAllocations;
|
2018-10-23 17:42:40 +08:00
|
|
|
std::recursive_mutex allocationsMutex;
|
2017-12-21 07:45:38 +08:00
|
|
|
};
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|