2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2020-02-11 20:54:40 +08:00
|
|
|
* Copyright (C) 2017-2020 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-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>
|
|
|
|
|
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;
|
|
|
|
|
2019-03-06 23:35:21 +08:00
|
|
|
struct SvmAllocationData {
|
|
|
|
GraphicsAllocation *cpuAllocation = nullptr;
|
|
|
|
GraphicsAllocation *gpuAllocation = nullptr;
|
|
|
|
size_t size = 0;
|
2019-06-11 17:17:01 +08:00
|
|
|
InternalMemoryType memoryType = InternalMemoryType::SVM;
|
2019-12-05 17:32:42 +08:00
|
|
|
MemoryPropertiesFlags allocationFlagsProperty;
|
2019-12-04 14:46:44 +08:00
|
|
|
void *device = nullptr;
|
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(); };
|
|
|
|
|
|
|
|
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 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 {
|
2019-06-13 21:49:35 +08:00
|
|
|
UnifiedMemoryProperties() = default;
|
|
|
|
UnifiedMemoryProperties(InternalMemoryType memoryType) : memoryType(memoryType){};
|
2019-06-11 17:17:01 +08:00
|
|
|
InternalMemoryType memoryType = InternalMemoryType::NOT_SPECIFIED;
|
2019-12-05 17:32:42 +08:00
|
|
|
MemoryPropertiesFlags allocationFlags;
|
2019-12-04 14:46:44 +08:00
|
|
|
void *device = nullptr;
|
2019-11-13 17:01:52 +08:00
|
|
|
DeviceBitfield subdeviceBitfield;
|
2019-06-11 17:17:01 +08:00
|
|
|
};
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
SVMAllocsManager(MemoryManager *memoryManager);
|
2020-04-23 22:59:18 +08:00
|
|
|
void *createSVMAlloc(uint32_t rootDeviceIndex, size_t size, const SvmAllocationProperties svmProperties, const DeviceBitfield &deviceBitfield);
|
2019-11-07 21:15:04 +08:00
|
|
|
void *createUnifiedMemoryAllocation(uint32_t rootDeviceIndex, size_t size, const UnifiedMemoryProperties &svmProperties);
|
|
|
|
void *createSharedUnifiedMemoryAllocation(uint32_t rootDeviceIndex, size_t size, const UnifiedMemoryProperties &svmProperties, void *cmdQ);
|
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); }
|
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
|
|
|
|
|
|
|
void insertSvmMapOperation(void *regionSvmPtr, size_t regionSize, void *baseSvmPtr, size_t offset, bool readOnlyMap);
|
|
|
|
void removeSvmMapOperation(const void *regionSvmPtr);
|
|
|
|
SvmMapOperation *getSvmMapOperation(const void *regionPtr);
|
2020-03-13 07:33:22 +08:00
|
|
|
void addInternalAllocationsToResidencyContainer(ResidencyContainer &residencyContainer, uint32_t requestedTypesMask);
|
2019-06-17 19:31:23 +08:00
|
|
|
void makeInternalAllocationsResident(CommandStreamReceiver &commandStreamReceiver, uint32_t requestedTypesMask);
|
2019-11-13 17:01:52 +08:00
|
|
|
void *createUnifiedAllocationWithDeviceStorage(uint32_t rootDeviceIndex, size_t size, const SvmAllocationProperties &svmProperties, const UnifiedMemoryProperties &unifiedMemoryProperties);
|
2019-12-04 11:04:55 +08:00
|
|
|
void freeSvmAllocationWithDeviceStorage(SvmAllocationData *svmData);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
protected:
|
2020-04-23 22:59:18 +08:00
|
|
|
void *createZeroCopySvmAllocation(uint32_t rootDeviceIndex, size_t size, const SvmAllocationProperties &svmProperties, const DeviceBitfield &deviceBitfield);
|
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;
|
2017-12-21 07:45:38 +08:00
|
|
|
};
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|