2019-07-04 18:17:42 +08:00
|
|
|
/*
|
2020-02-23 05:21:06 +08:00
|
|
|
* Copyright (C) 2019-2020 Intel Corporation
|
2019-07-04 18:17:42 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/helpers/non_copyable_or_moveable.h"
|
|
|
|
#include "shared/source/utilities/spinlock.h"
|
2019-07-04 18:17:42 +08:00
|
|
|
|
2020-09-14 22:39:12 +08:00
|
|
|
#include "memory_properties_flags.h"
|
|
|
|
|
2019-07-04 18:17:42 +08:00
|
|
|
#include <memory>
|
|
|
|
#include <unordered_map>
|
|
|
|
|
|
|
|
namespace NEO {
|
2020-09-15 18:35:17 +08:00
|
|
|
class GraphicsAllocation;
|
|
|
|
class Device;
|
2019-07-04 18:17:42 +08:00
|
|
|
class SVMAllocsManager;
|
|
|
|
|
|
|
|
class PageFaultManager : public NonCopyableOrMovableClass {
|
|
|
|
public:
|
|
|
|
static std::unique_ptr<PageFaultManager> create();
|
|
|
|
|
|
|
|
virtual ~PageFaultManager() = default;
|
|
|
|
|
2020-12-10 15:54:28 +08:00
|
|
|
MOCKABLE_VIRTUAL void moveAllocationToGpuDomain(void *ptr);
|
2019-07-04 18:17:42 +08:00
|
|
|
void moveAllocationsWithinUMAllocsManagerToGpuDomain(SVMAllocsManager *unifiedMemoryManager);
|
2020-09-14 22:39:12 +08:00
|
|
|
void insertAllocation(void *ptr, size_t size, SVMAllocsManager *unifiedMemoryManager, void *cmdQ, const MemoryProperties &memoryProperties);
|
2019-07-04 18:17:42 +08:00
|
|
|
void removeAllocation(void *ptr);
|
|
|
|
|
2020-09-14 22:39:12 +08:00
|
|
|
enum class AllocationDomain {
|
|
|
|
None,
|
|
|
|
Cpu,
|
|
|
|
Gpu,
|
|
|
|
};
|
|
|
|
|
2019-07-04 18:17:42 +08:00
|
|
|
protected:
|
|
|
|
struct PageFaultData {
|
|
|
|
size_t size;
|
|
|
|
SVMAllocsManager *unifiedMemoryManager;
|
|
|
|
void *cmdQ;
|
2020-09-14 22:39:12 +08:00
|
|
|
AllocationDomain domain;
|
2019-07-04 18:17:42 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
virtual void allowCPUMemoryAccess(void *ptr, size_t size) = 0;
|
|
|
|
virtual void protectCPUMemoryAccess(void *ptr, size_t size) = 0;
|
|
|
|
|
2020-09-15 18:35:17 +08:00
|
|
|
virtual void evictMemoryAfterImplCopy(GraphicsAllocation *allocation, Device *device) = 0;
|
2020-07-06 19:09:12 +08:00
|
|
|
|
2019-07-04 18:17:42 +08:00
|
|
|
MOCKABLE_VIRTUAL bool verifyPageFault(void *ptr);
|
|
|
|
MOCKABLE_VIRTUAL void transferToCpu(void *ptr, size_t size, void *cmdQ);
|
|
|
|
MOCKABLE_VIRTUAL void transferToGpu(void *ptr, void *cmdQ);
|
2019-11-13 21:19:55 +08:00
|
|
|
MOCKABLE_VIRTUAL void setAubWritable(bool writable, void *ptr, SVMAllocsManager *unifiedMemoryManager);
|
2019-07-04 18:17:42 +08:00
|
|
|
|
|
|
|
std::unordered_map<void *, PageFaultData> memoryData;
|
|
|
|
SpinLock mtx;
|
|
|
|
};
|
|
|
|
} // namespace NEO
|