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