2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2021-05-17 02:51:16 +08:00
|
|
|
* Copyright (C) 2019-2021 Intel Corporation
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
2018-12-06 22:33:02 +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/helpers/common_types.h"
|
2020-06-29 18:47:13 +08:00
|
|
|
#include "shared/source/memory_manager/multi_graphics_allocation.h"
|
2020-03-13 07:33:22 +08:00
|
|
|
#include "shared/source/memory_manager/residency_container.h"
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/unified_memory/unified_memory.h"
|
|
|
|
#include "shared/source/utilities/spinlock.h"
|
2019-06-03 16:50:21 +08:00
|
|
|
|
2019-12-05 17:32:42 +08:00
|
|
|
#include "memory_properties_flags.h"
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
#include <cstdint>
|
|
|
|
#include <map>
|
|
|
|
#include <mutex>
|
2020-12-23 21:47:18 +08:00
|
|
|
#include <set>
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
namespace NEO {
|
2019-04-25 16:11:25 +08:00
|
|
|
class CommandStreamReceiver;
|
2017-12-21 07:45:38 +08:00
|
|
|
class GraphicsAllocation;
|
|
|
|
class MemoryManager;
|
2020-12-23 21:47:18 +08:00
|
|
|
class Device;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-03-06 23:35:21 +08:00
|
|
|
struct SvmAllocationData {
|
2020-06-29 18:47:13 +08:00
|
|
|
SvmAllocationData(uint32_t maxRootDeviceIndex) : gpuAllocations(maxRootDeviceIndex), maxRootDeviceIndex(maxRootDeviceIndex){};
|
|
|
|
SvmAllocationData(const SvmAllocationData &svmAllocData) : SvmAllocationData(svmAllocData.maxRootDeviceIndex) {
|
|
|
|
this->allocationFlagsProperty = svmAllocData.allocationFlagsProperty;
|
|
|
|
this->cpuAllocation = svmAllocData.cpuAllocation;
|
|
|
|
this->device = svmAllocData.device;
|
|
|
|
this->size = svmAllocData.size;
|
|
|
|
this->memoryType = svmAllocData.memoryType;
|
|
|
|
for (auto allocation : svmAllocData.gpuAllocations.getGraphicsAllocations()) {
|
|
|
|
if (allocation) {
|
|
|
|
this->gpuAllocations.addAllocation(allocation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-07-06 19:56:33 +08:00
|
|
|
SvmAllocationData &operator=(const SvmAllocationData &) = delete;
|
2019-03-06 23:35:21 +08:00
|
|
|
GraphicsAllocation *cpuAllocation = nullptr;
|
2020-06-29 18:47:13 +08:00
|
|
|
MultiGraphicsAllocation gpuAllocations;
|
2019-03-06 23:35:21 +08:00
|
|
|
size_t size = 0;
|
2019-06-11 17:17:01 +08:00
|
|
|
InternalMemoryType memoryType = InternalMemoryType::SVM;
|
2020-04-22 20:37:30 +08:00
|
|
|
MemoryProperties allocationFlagsProperty;
|
2020-12-23 21:47:18 +08:00
|
|
|
Device *device = nullptr;
|
2020-06-29 18:47:13 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
const uint32_t maxRootDeviceIndex;
|
2019-03-06 23:35:21 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct SvmMapOperation {
|
|
|
|
void *regionSvmPtr = nullptr;
|
|
|
|
size_t regionSize = 0;
|
|
|
|
void *baseSvmPtr = nullptr;
|
|
|
|
size_t offset = 0;
|
|
|
|
bool readOnlyMap = false;
|
|
|
|
};
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
class SVMAllocsManager {
|
|
|
|
public:
|
|
|
|
class MapBasedAllocationTracker {
|
2019-06-11 17:17:01 +08:00
|
|
|
friend class SVMAllocsManager;
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
public:
|
2019-03-06 23:35:21 +08:00
|
|
|
using SvmAllocationContainer = std::map<const void *, SvmAllocationData>;
|
|
|
|
void insert(SvmAllocationData);
|
|
|
|
void remove(SvmAllocationData);
|
|
|
|
SvmAllocationData *get(const void *);
|
|
|
|
size_t getNumAllocs() const { return allocations.size(); };
|
|
|
|
|
|
|
|
SvmAllocationContainer allocations;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct MapOperationsTracker {
|
|
|
|
using SvmMapOperationsContainer = std::map<const void *, SvmMapOperation>;
|
|
|
|
void insert(SvmMapOperation);
|
|
|
|
void remove(const void *);
|
|
|
|
SvmMapOperation *get(const void *);
|
|
|
|
size_t getNumMapOperations() const { return operations.size(); };
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
protected:
|
2019-03-06 23:35:21 +08:00
|
|
|
SvmMapOperationsContainer operations;
|
2017-12-21 07:45:38 +08:00
|
|
|
};
|
|
|
|
|
2019-04-17 16:02:31 +08:00
|
|
|
struct SvmAllocationProperties {
|
|
|
|
bool coherent = false;
|
|
|
|
bool hostPtrReadOnly = false;
|
|
|
|
bool readOnly = false;
|
|
|
|
};
|
|
|
|
|
2019-06-11 17:17:01 +08:00
|
|
|
struct UnifiedMemoryProperties {
|
2020-12-23 21:47:18 +08:00
|
|
|
UnifiedMemoryProperties(InternalMemoryType memoryType,
|
|
|
|
const std::set<uint32_t> &rootDeviceIndices,
|
|
|
|
const std::map<uint32_t, DeviceBitfield> &subdeviceBitfields) : memoryType(memoryType),
|
|
|
|
rootDeviceIndices(rootDeviceIndices),
|
|
|
|
subdeviceBitfields(subdeviceBitfields){};
|
2019-06-11 17:17:01 +08:00
|
|
|
InternalMemoryType memoryType = InternalMemoryType::NOT_SPECIFIED;
|
2020-04-22 20:37:30 +08:00
|
|
|
MemoryProperties allocationFlags;
|
2020-12-23 21:47:18 +08:00
|
|
|
Device *device = nullptr;
|
|
|
|
const std::set<uint32_t> &rootDeviceIndices;
|
|
|
|
const std::map<uint32_t, DeviceBitfield> &subdeviceBitfields;
|
2019-06-11 17:17:01 +08:00
|
|
|
};
|
|
|
|
|
2021-03-08 20:27:14 +08:00
|
|
|
SVMAllocsManager(MemoryManager *memoryManager, bool multiOsContextSupport);
|
2020-09-14 16:57:27 +08:00
|
|
|
MOCKABLE_VIRTUAL ~SVMAllocsManager() = default;
|
2020-12-23 21:47:18 +08:00
|
|
|
void *createSVMAlloc(size_t size,
|
2020-07-09 09:31:52 +08:00
|
|
|
const SvmAllocationProperties svmProperties,
|
2020-12-23 21:47:18 +08:00
|
|
|
const std::set<uint32_t> &rootDeviceIndices,
|
|
|
|
const std::map<uint32_t, DeviceBitfield> &subdeviceBitfields);
|
2021-03-16 07:46:09 +08:00
|
|
|
MOCKABLE_VIRTUAL void *createHostUnifiedMemoryAllocation(size_t size,
|
|
|
|
const UnifiedMemoryProperties &svmProperties);
|
2021-03-13 09:07:50 +08:00
|
|
|
MOCKABLE_VIRTUAL void *createUnifiedMemoryAllocation(size_t size,
|
|
|
|
const UnifiedMemoryProperties &svmProperties);
|
|
|
|
MOCKABLE_VIRTUAL void *createSharedUnifiedMemoryAllocation(size_t size,
|
|
|
|
const UnifiedMemoryProperties &svmProperties,
|
|
|
|
void *cmdQ);
|
2020-12-23 21:47:18 +08:00
|
|
|
void *createUnifiedKmdMigratedAllocation(size_t size,
|
2020-10-22 20:13:44 +08:00
|
|
|
const SvmAllocationProperties &svmProperties,
|
|
|
|
const UnifiedMemoryProperties &unifiedMemoryProperties);
|
|
|
|
void setUnifiedAllocationProperties(GraphicsAllocation *allocation, const SvmAllocationProperties &svmProperties);
|
2019-03-06 23:35:21 +08:00
|
|
|
SvmAllocationData *getSVMAlloc(const void *ptr);
|
2020-02-11 20:54:40 +08:00
|
|
|
bool freeSVMAlloc(void *ptr, bool blocking);
|
|
|
|
bool freeSVMAlloc(void *ptr) { return freeSVMAlloc(ptr, false); }
|
2020-05-07 20:38:36 +08:00
|
|
|
void insertSVMAlloc(const SvmAllocationData &svmData);
|
|
|
|
void removeSVMAlloc(const SvmAllocationData &svmData);
|
2017-12-21 07:45:38 +08:00
|
|
|
size_t getNumAllocs() const { return SVMAllocs.getNumAllocs(); }
|
2019-08-07 09:38:03 +08:00
|
|
|
MapBasedAllocationTracker *getSVMAllocs() { return &SVMAllocs; }
|
2019-03-06 23:35:21 +08:00
|
|
|
|
2020-09-14 16:57:27 +08:00
|
|
|
MOCKABLE_VIRTUAL void insertSvmMapOperation(void *regionSvmPtr, size_t regionSize, void *baseSvmPtr, size_t offset, bool readOnlyMap);
|
2019-03-06 23:35:21 +08:00
|
|
|
void removeSvmMapOperation(const void *regionSvmPtr);
|
|
|
|
SvmMapOperation *getSvmMapOperation(const void *regionPtr);
|
2020-06-15 04:18:42 +08:00
|
|
|
void addInternalAllocationsToResidencyContainer(uint32_t rootDeviceIndex,
|
|
|
|
ResidencyContainer &residencyContainer,
|
|
|
|
uint32_t requestedTypesMask);
|
2019-06-17 19:31:23 +08:00
|
|
|
void makeInternalAllocationsResident(CommandStreamReceiver &commandStreamReceiver, uint32_t requestedTypesMask);
|
2020-12-23 21:47:18 +08:00
|
|
|
void *createUnifiedAllocationWithDeviceStorage(size_t size, const SvmAllocationProperties &svmProperties, const UnifiedMemoryProperties &unifiedMemoryProperties);
|
2019-12-04 11:04:55 +08:00
|
|
|
void freeSvmAllocationWithDeviceStorage(SvmAllocationData *svmData);
|
2021-01-12 01:42:33 +08:00
|
|
|
bool hasHostAllocations();
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
protected:
|
2020-12-23 21:47:18 +08:00
|
|
|
void *createZeroCopySvmAllocation(size_t size, const SvmAllocationProperties &svmProperties,
|
|
|
|
const std::set<uint32_t> &rootDeviceIndices,
|
|
|
|
const std::map<uint32_t, DeviceBitfield> &subdeviceBitfields);
|
2020-12-14 22:06:19 +08:00
|
|
|
GraphicsAllocation::AllocationType getGraphicsAllocationType(const UnifiedMemoryProperties &unifiedMemoryProperties) const;
|
2019-06-11 17:17:01 +08:00
|
|
|
|
2019-03-06 23:35:21 +08:00
|
|
|
void freeZeroCopySvmAllocation(SvmAllocationData *svmData);
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
MapBasedAllocationTracker SVMAllocs;
|
2019-03-06 23:35:21 +08:00
|
|
|
MapOperationsTracker svmMapOperations;
|
2017-12-21 07:45:38 +08:00
|
|
|
MemoryManager *memoryManager;
|
2019-06-03 16:50:21 +08:00
|
|
|
SpinLock mtx;
|
2021-03-08 20:27:14 +08:00
|
|
|
bool multiOsContextSupport;
|
2017-12-21 07:45:38 +08:00
|
|
|
};
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|