2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2018-09-18 15:11:08 +08:00
|
|
|
* Copyright (C) 2017-2018 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
|
|
|
|
#include <map>
|
|
|
|
#include "runtime/helpers/aligned_memory.h"
|
|
|
|
#include "runtime/memory_manager/graphics_allocation.h"
|
|
|
|
#include "runtime/memory_manager/host_ptr_defines.h"
|
|
|
|
|
|
|
|
namespace OCLRT {
|
|
|
|
|
2018-03-27 20:01:04 +08:00
|
|
|
typedef std::map<const void *, FragmentStorage> HostPtrFragmentsContainer;
|
2018-10-23 17:42:40 +08:00
|
|
|
class MemoryManager;
|
2017-12-21 07:45:38 +08:00
|
|
|
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);
|
|
|
|
|
|
|
|
void releaseHandleStorage(OsHandleStorage &fragments);
|
2018-03-27 20:01:04 +08:00
|
|
|
bool releaseHostPtr(const void *ptr);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2018-03-27 20:01:04 +08:00
|
|
|
FragmentStorage *getFragment(const void *inputPtr);
|
2017-12-21 07:45:38 +08:00
|
|
|
size_t getFragmentCount() { return partialAllocations.size(); }
|
|
|
|
FragmentStorage *getFragmentAndCheckForOverlaps(const void *inputPtr, size_t size, OverlapStatus &overlappingStatus);
|
2018-10-23 17:42:40 +08:00
|
|
|
OsHandleStorage prepareOsStorageForAllocation(MemoryManager &memoryManager, size_t size, const void *ptr);
|
|
|
|
RequirementsStatus checkAllocationsForOverlapping(MemoryManager &memoryManager, AllocationRequirements *requirements, CheckedFragments *checkedFragments);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
private:
|
2018-03-27 20:01:04 +08:00
|
|
|
std::map<const void *, FragmentStorage>::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
|
|
|
};
|
|
|
|
} // namespace OCLRT
|