2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2020-02-23 05:21:06 +08:00
|
|
|
* Copyright (C) 2017-2020 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 01:46:50 +08:00
|
|
|
#include "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
|
|
|
|
2018-10-24 14:46:54 +08:00
|
|
|
using HostPtrFragmentsContainer = std::map<const void *, FragmentStorage>;
|
2018-10-23 17:42:40 +08:00
|
|
|
class MemoryManager;
|
2017-12-21 07:45:38 +08:00
|
|
|
class HostPtrManager {
|
|
|
|
public:
|
2018-10-24 14:46:54 +08:00
|
|
|
FragmentStorage *getFragment(const void *inputPtr);
|
2019-11-15 16:59:48 +08:00
|
|
|
OsHandleStorage prepareOsStorageForAllocation(MemoryManager &memoryManager, size_t size, const void *ptr, uint32_t rootDeviceIndex);
|
2017-12-21 07:45:38 +08:00
|
|
|
void releaseHandleStorage(OsHandleStorage &fragments);
|
2018-03-27 20:01:04 +08:00
|
|
|
bool releaseHostPtr(const void *ptr);
|
2018-10-24 14:46:54 +08:00
|
|
|
void storeFragment(AllocationStorageData &storageData);
|
|
|
|
void storeFragment(FragmentStorage &fragment);
|
2019-09-25 20:09:32 +08:00
|
|
|
std::unique_lock<std::recursive_mutex> obtainOwnership();
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2018-10-24 14:46:54 +08:00
|
|
|
protected:
|
|
|
|
static AllocationRequirements getAllocationRequirements(const void *inputPtr, size_t size);
|
2019-06-03 20:49:20 +08:00
|
|
|
OsHandleStorage populateAlreadyAllocatedFragments(AllocationRequirements &requirements);
|
2017-12-21 07:45:38 +08:00
|
|
|
FragmentStorage *getFragmentAndCheckForOverlaps(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
|
|
|
|
2018-10-24 14:46:54 +08:00
|
|
|
HostPtrFragmentsContainer::iterator findElement(const void *ptr);
|
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
|