2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2020-01-20 22:00:07 +08:00
|
|
|
* Copyright (C) 2017-2020 Intel Corporation
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
2018-09-20 11:54:29 +08:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2019-09-05 15:35:56 +08:00
|
|
|
#include "core/helpers/debug_helpers.h"
|
2019-05-29 10:09:40 +08:00
|
|
|
#include "core/helpers/ptr_math.h"
|
2019-10-07 15:22:25 +08:00
|
|
|
#include "core/memory_manager/host_ptr_defines.h"
|
|
|
|
#include "core/memory_manager/memory_constants.h"
|
|
|
|
#include "core/memory_manager/memory_pool.h"
|
2019-09-11 15:26:24 +08:00
|
|
|
#include "core/utilities/idlist.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-03-25 20:21:48 +08:00
|
|
|
#include "engine_limits.h"
|
2019-02-28 23:12:23 +08:00
|
|
|
#include "storage_info.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
|
2019-02-11 17:02:27 +08:00
|
|
|
#include <array>
|
2019-07-26 17:08:22 +08:00
|
|
|
#include <atomic>
|
2019-02-11 17:02:27 +08:00
|
|
|
#include <cstddef>
|
|
|
|
#include <cstdint>
|
2019-07-26 17:08:22 +08:00
|
|
|
#include <limits>
|
2019-08-20 03:54:53 +08:00
|
|
|
#include <mutex>
|
2019-12-17 15:11:16 +08:00
|
|
|
#include <vector>
|
2019-02-11 17:02:27 +08:00
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
namespace NEO {
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2018-09-21 12:07:50 +08:00
|
|
|
using osHandle = unsigned int;
|
2020-01-20 22:00:07 +08:00
|
|
|
inline osHandle toOsHandle(const void *handle) {
|
|
|
|
return static_cast<osHandle>(castToUint64(handle));
|
|
|
|
}
|
|
|
|
|
2019-03-01 23:14:28 +08:00
|
|
|
enum class HeapIndex : uint32_t;
|
2019-02-15 22:33:40 +08:00
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
namespace Sharing {
|
|
|
|
constexpr auto nonSharedResource = 0u;
|
|
|
|
}
|
|
|
|
|
|
|
|
class Gmm;
|
2019-06-06 22:26:47 +08:00
|
|
|
class MemoryManager;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
class GraphicsAllocation : public IDNode<GraphicsAllocation> {
|
|
|
|
public:
|
2018-07-20 03:34:45 +08:00
|
|
|
enum class AllocationType {
|
2018-07-05 22:31:57 +08:00
|
|
|
UNKNOWN = 0,
|
2019-02-27 21:59:46 +08:00
|
|
|
BUFFER,
|
2018-07-23 01:27:33 +08:00
|
|
|
BUFFER_COMPRESSED,
|
2018-07-25 00:36:26 +08:00
|
|
|
BUFFER_HOST_MEMORY,
|
2019-02-27 21:59:46 +08:00
|
|
|
COMMAND_BUFFER,
|
|
|
|
CONSTANT_SURFACE,
|
2019-04-15 19:10:26 +08:00
|
|
|
DEVICE_QUEUE_BUFFER,
|
2019-02-27 21:59:46 +08:00
|
|
|
EXTERNAL_HOST_PTR,
|
|
|
|
FILL_PATTERN,
|
|
|
|
GLOBAL_SURFACE,
|
2018-07-05 22:31:57 +08:00
|
|
|
IMAGE,
|
2019-02-27 21:59:46 +08:00
|
|
|
INDIRECT_OBJECT_HEAP,
|
|
|
|
INSTRUCTION_HEAP,
|
|
|
|
INTERNAL_HEAP,
|
2019-04-16 17:29:19 +08:00
|
|
|
INTERNAL_HOST_MEMORY,
|
2019-02-27 21:59:46 +08:00
|
|
|
KERNEL_ISA,
|
2018-07-05 22:31:57 +08:00
|
|
|
LINEAR_STREAM,
|
2019-12-04 20:42:41 +08:00
|
|
|
MAP_ALLOCATION,
|
2019-04-16 21:59:23 +08:00
|
|
|
MCS,
|
2018-07-09 20:12:32 +08:00
|
|
|
PIPE,
|
2019-04-16 21:59:23 +08:00
|
|
|
PREEMPTION,
|
2018-07-09 20:12:32 +08:00
|
|
|
PRINTF_SURFACE,
|
|
|
|
PRIVATE_SURFACE,
|
2019-02-27 21:59:46 +08:00
|
|
|
PROFILING_TAG_BUFFER,
|
2018-07-09 20:12:32 +08:00
|
|
|
SCRATCH_SURFACE,
|
2019-04-01 20:04:50 +08:00
|
|
|
SHARED_BUFFER,
|
2019-04-16 21:59:23 +08:00
|
|
|
SHARED_CONTEXT_IMAGE,
|
|
|
|
SHARED_IMAGE,
|
2019-01-28 20:59:37 +08:00
|
|
|
SHARED_RESOURCE_COPY,
|
2019-02-27 21:59:46 +08:00
|
|
|
SURFACE_STATE_HEAP,
|
2019-03-06 23:35:21 +08:00
|
|
|
SVM_CPU,
|
|
|
|
SVM_GPU,
|
|
|
|
SVM_ZERO_COPY,
|
2019-02-27 21:59:46 +08:00
|
|
|
TAG_BUFFER,
|
|
|
|
TIMESTAMP_PACKET_TAG_BUFFER,
|
2019-07-02 22:39:32 +08:00
|
|
|
WRITE_COMBINED
|
2017-12-21 07:45:38 +08:00
|
|
|
};
|
|
|
|
|
2019-11-20 19:23:06 +08:00
|
|
|
~GraphicsAllocation() override;
|
2018-03-01 17:08:20 +08:00
|
|
|
GraphicsAllocation &operator=(const GraphicsAllocation &) = delete;
|
|
|
|
GraphicsAllocation(const GraphicsAllocation &) = delete;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-11-04 23:03:30 +08:00
|
|
|
GraphicsAllocation(uint32_t rootDeviceIndex, AllocationType allocationType, void *cpuPtrIn, uint64_t gpuAddress, uint64_t baseAddress, size_t sizeIn, MemoryPool::Type pool);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-11-04 23:03:30 +08:00
|
|
|
GraphicsAllocation(uint32_t rootDeviceIndex, AllocationType allocationType, void *cpuPtrIn, size_t sizeIn, osHandle sharedHandleIn, MemoryPool::Type pool);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-11-15 16:59:48 +08:00
|
|
|
uint32_t getRootDeviceIndex() const { return rootDeviceIndex; }
|
2017-12-21 07:45:38 +08:00
|
|
|
void *getUnderlyingBuffer() const { return cpuPtr; }
|
2019-02-27 21:59:46 +08:00
|
|
|
void *getDriverAllocatedCpuPtr() const { return driverAllocatedCpuPointer; }
|
|
|
|
void setDriverAllocatedCpuPtr(void *allocatedCpuPtr) { driverAllocatedCpuPointer = allocatedCpuPtr; }
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
void setCpuPtrAndGpuAddress(void *cpuPtr, uint64_t gpuAddress) {
|
|
|
|
this->cpuPtr = cpuPtr;
|
|
|
|
this->gpuAddress = gpuAddress;
|
|
|
|
}
|
|
|
|
size_t getUnderlyingBufferSize() const { return size; }
|
2019-02-27 21:59:46 +08:00
|
|
|
void setSize(size_t size) { this->size = size; }
|
|
|
|
|
|
|
|
uint64_t getAllocationOffset() const {
|
|
|
|
return allocationOffset;
|
|
|
|
}
|
|
|
|
void setAllocationOffset(uint64_t offset) {
|
|
|
|
allocationOffset = offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t getGpuBaseAddress() const {
|
|
|
|
return gpuBaseAddress;
|
|
|
|
}
|
|
|
|
void setGpuBaseAddress(uint64_t baseAddress) {
|
|
|
|
gpuBaseAddress = baseAddress;
|
|
|
|
}
|
|
|
|
uint64_t getGpuAddress() const {
|
2017-12-21 07:45:38 +08:00
|
|
|
DEBUG_BREAK_IF(gpuAddress < gpuBaseAddress);
|
|
|
|
return gpuAddress + allocationOffset;
|
|
|
|
}
|
2018-01-08 10:25:27 +08:00
|
|
|
uint64_t getGpuAddressToPatch() const {
|
2017-12-21 07:45:38 +08:00
|
|
|
DEBUG_BREAK_IF(gpuAddress < gpuBaseAddress);
|
|
|
|
return gpuAddress + allocationOffset - gpuBaseAddress;
|
|
|
|
}
|
|
|
|
|
2019-02-28 23:12:23 +08:00
|
|
|
void lock(void *ptr) { lockedPtr = ptr; }
|
|
|
|
void unlock() { lockedPtr = nullptr; }
|
2019-01-24 22:16:12 +08:00
|
|
|
bool isLocked() const { return lockedPtr != nullptr; }
|
|
|
|
void *getLockedPtr() const { return lockedPtr; }
|
2018-03-05 17:56:34 +08:00
|
|
|
|
2019-02-27 21:59:46 +08:00
|
|
|
bool isCoherent() const { return allocationInfo.flags.coherent; }
|
2019-02-28 23:12:23 +08:00
|
|
|
void setCoherent(bool coherentIn) { allocationInfo.flags.coherent = coherentIn; }
|
2019-02-27 21:59:46 +08:00
|
|
|
void setEvictable(bool evictable) { allocationInfo.flags.evictable = evictable; }
|
|
|
|
bool peekEvictable() const { return allocationInfo.flags.evictable; }
|
|
|
|
bool isFlushL3Required() const { return allocationInfo.flags.flushL3Required; }
|
2019-02-28 23:12:23 +08:00
|
|
|
void setFlushL3Required(bool flushL3Required) { allocationInfo.flags.flushL3Required = flushL3Required; }
|
2019-02-27 21:59:46 +08:00
|
|
|
bool is32BitAllocation() const { return allocationInfo.flags.is32BitAllocation; }
|
|
|
|
void set32BitAllocation(bool is32BitAllocation) { allocationInfo.flags.is32BitAllocation = is32BitAllocation; }
|
|
|
|
|
2019-08-07 00:01:26 +08:00
|
|
|
void setAubWritable(bool writable, uint32_t banks);
|
|
|
|
bool isAubWritable(uint32_t banks) const;
|
|
|
|
void setTbxWritable(bool writable, uint32_t banks);
|
|
|
|
bool isTbxWritable(uint32_t banks) const;
|
2019-02-27 21:59:46 +08:00
|
|
|
void setAllocDumpable(bool dumpable) { aubInfo.allocDumpable = dumpable; }
|
|
|
|
bool isAllocDumpable() const { return aubInfo.allocDumpable; }
|
|
|
|
bool isMemObjectsAllocationWithWritableFlags() const { return aubInfo.memObjectsAllocationWithWritableFlags; }
|
|
|
|
void setMemObjectsAllocationWithWritableFlags(bool newValue) { aubInfo.memObjectsAllocationWithWritableFlags = newValue; }
|
|
|
|
|
|
|
|
void incReuseCount() { sharingInfo.reuseCount++; }
|
|
|
|
void decReuseCount() { sharingInfo.reuseCount--; }
|
|
|
|
uint32_t peekReuseCount() const { return sharingInfo.reuseCount; }
|
|
|
|
osHandle peekSharedHandle() const { return sharingInfo.sharedHandle; }
|
|
|
|
|
|
|
|
void setAllocationType(AllocationType allocationType);
|
|
|
|
AllocationType getAllocationType() const { return allocationType; }
|
|
|
|
|
2019-02-26 18:37:51 +08:00
|
|
|
MemoryPool::Type getMemoryPool() const { return memoryPool; }
|
2019-02-27 21:59:46 +08:00
|
|
|
|
2018-11-07 16:33:55 +08:00
|
|
|
bool isUsed() const { return registeredContextsNum > 0; }
|
2019-02-27 21:59:46 +08:00
|
|
|
bool isUsedByManyOsContexts() const { return registeredContextsNum > 1u; }
|
2019-01-07 16:29:49 +08:00
|
|
|
bool isUsedByOsContext(uint32_t contextId) const { return objectNotUsed != getTaskCount(contextId); }
|
2018-11-02 17:01:56 +08:00
|
|
|
void updateTaskCount(uint32_t newTaskCount, uint32_t contextId);
|
2018-11-06 18:38:49 +08:00
|
|
|
uint32_t getTaskCount(uint32_t contextId) const { return usageInfos[contextId].taskCount; }
|
2019-01-07 16:29:49 +08:00
|
|
|
void releaseUsageInOsContext(uint32_t contextId) { updateTaskCount(objectNotUsed, contextId); }
|
2019-02-26 18:37:51 +08:00
|
|
|
uint32_t getInspectionId(uint32_t contextId) const { return usageInfos[contextId].inspectionId; }
|
2018-12-04 22:11:29 +08:00
|
|
|
void setInspectionId(uint32_t newInspectionId, uint32_t contextId) { usageInfos[contextId].inspectionId = newInspectionId; }
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-01-24 22:16:12 +08:00
|
|
|
bool isResident(uint32_t contextId) const { return GraphicsAllocation::objectNotResident != getResidencyTaskCount(contextId); }
|
2018-11-07 16:33:55 +08:00
|
|
|
void updateResidencyTaskCount(uint32_t newTaskCount, uint32_t contextId) { usageInfos[contextId].residencyTaskCount = newTaskCount; }
|
|
|
|
uint32_t getResidencyTaskCount(uint32_t contextId) const { return usageInfos[contextId].residencyTaskCount; }
|
2019-01-07 16:29:49 +08:00
|
|
|
void releaseResidencyInOsContext(uint32_t contextId) { updateResidencyTaskCount(objectNotResident, contextId); }
|
2019-02-27 21:59:46 +08:00
|
|
|
bool isResidencyTaskCountBelow(uint32_t taskCount, uint32_t contextId) const { return !isResident(contextId) || getResidencyTaskCount(contextId) < taskCount; }
|
2018-12-20 15:43:57 +08:00
|
|
|
|
2018-12-21 00:38:38 +08:00
|
|
|
virtual std::string getAllocationInfoString() const;
|
2019-06-06 22:26:47 +08:00
|
|
|
virtual uint64_t peekInternalHandle(MemoryManager *memoryManager) { return 0llu; }
|
2018-12-21 00:38:38 +08:00
|
|
|
|
2019-02-18 17:49:21 +08:00
|
|
|
static bool isCpuAccessRequired(AllocationType allocationType) {
|
2019-06-13 16:58:38 +08:00
|
|
|
return allocationType == AllocationType::COMMAND_BUFFER ||
|
|
|
|
allocationType == AllocationType::CONSTANT_SURFACE ||
|
2019-06-19 16:47:03 +08:00
|
|
|
allocationType == AllocationType::GLOBAL_SURFACE ||
|
2019-02-18 17:49:21 +08:00
|
|
|
allocationType == AllocationType::INTERNAL_HEAP ||
|
2019-06-13 16:58:38 +08:00
|
|
|
allocationType == AllocationType::LINEAR_STREAM ||
|
2019-06-19 16:47:03 +08:00
|
|
|
allocationType == AllocationType::PIPE ||
|
2019-09-04 21:20:50 +08:00
|
|
|
allocationType == AllocationType::PRINTF_SURFACE ||
|
2019-06-13 16:58:38 +08:00
|
|
|
allocationType == AllocationType::TIMESTAMP_PACKET_TAG_BUFFER;
|
2019-02-18 17:49:21 +08:00
|
|
|
}
|
2019-03-13 22:31:46 +08:00
|
|
|
void *getReservedAddressPtr() const {
|
|
|
|
return this->reservedAddressRangeInfo.addressPtr;
|
|
|
|
}
|
|
|
|
size_t getReservedAddressSize() const {
|
|
|
|
return this->reservedAddressRangeInfo.rangeSize;
|
|
|
|
}
|
|
|
|
void setReservedAddressRange(void *reserveAddress, size_t size) {
|
|
|
|
this->reservedAddressRangeInfo.addressPtr = reserveAddress;
|
|
|
|
this->reservedAddressRangeInfo.rangeSize = size;
|
|
|
|
}
|
2019-02-18 17:49:21 +08:00
|
|
|
|
2019-03-12 20:24:58 +08:00
|
|
|
Gmm *getDefaultGmm() const {
|
|
|
|
return getGmm(0u);
|
|
|
|
}
|
|
|
|
Gmm *getGmm(uint32_t handleId) const {
|
|
|
|
return gmms[handleId];
|
|
|
|
}
|
|
|
|
void setDefaultGmm(Gmm *gmm) {
|
2019-04-11 07:14:19 +08:00
|
|
|
setGmm(gmm, 0u);
|
2019-03-12 20:24:58 +08:00
|
|
|
}
|
|
|
|
void setGmm(Gmm *gmm, uint32_t handleId) {
|
|
|
|
gmms[handleId] = gmm;
|
|
|
|
}
|
2019-10-07 15:22:25 +08:00
|
|
|
|
2019-03-26 21:40:43 +08:00
|
|
|
uint32_t getNumHandles() const { return storageInfo.getNumHandles(); }
|
2019-06-13 18:29:21 +08:00
|
|
|
uint32_t getUsedPageSize() const;
|
2019-03-12 20:24:58 +08:00
|
|
|
|
2019-02-27 21:59:46 +08:00
|
|
|
OsHandleStorage fragmentsStorage;
|
2019-02-28 23:12:23 +08:00
|
|
|
StorageInfo storageInfo = {};
|
2019-02-27 21:59:46 +08:00
|
|
|
|
2019-08-07 00:01:26 +08:00
|
|
|
static constexpr uint32_t defaultBank = 0b1u;
|
2019-11-13 21:19:55 +08:00
|
|
|
static constexpr uint32_t allBanks = 0xffffffff;
|
2019-02-27 21:59:46 +08:00
|
|
|
constexpr static uint32_t objectNotResident = std::numeric_limits<uint32_t>::max();
|
|
|
|
constexpr static uint32_t objectNotUsed = std::numeric_limits<uint32_t>::max();
|
2018-11-07 16:33:55 +08:00
|
|
|
|
2020-01-24 18:47:19 +08:00
|
|
|
protected:
|
2018-11-07 16:33:55 +08:00
|
|
|
struct UsageInfo {
|
|
|
|
uint32_t taskCount = objectNotUsed;
|
|
|
|
uint32_t residencyTaskCount = objectNotResident;
|
2018-12-04 22:11:29 +08:00
|
|
|
uint32_t inspectionId = 0u;
|
2018-11-07 16:33:55 +08:00
|
|
|
};
|
2019-02-27 21:59:46 +08:00
|
|
|
struct AubInfo {
|
2019-11-28 01:00:52 +08:00
|
|
|
uint32_t aubWritable = std::numeric_limits<uint32_t>::max();
|
|
|
|
uint32_t tbxWritable = std::numeric_limits<uint32_t>::max();
|
2019-02-27 21:59:46 +08:00
|
|
|
bool allocDumpable = false;
|
|
|
|
bool memObjectsAllocationWithWritableFlags = false;
|
|
|
|
};
|
|
|
|
struct SharingInfo {
|
|
|
|
uint32_t reuseCount = 0;
|
|
|
|
osHandle sharedHandle = Sharing::nonSharedResource;
|
|
|
|
};
|
|
|
|
struct AllocationInfo {
|
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
uint32_t coherent : 1;
|
|
|
|
uint32_t evictable : 1;
|
|
|
|
uint32_t flushL3Required : 1;
|
|
|
|
uint32_t is32BitAllocation : 1;
|
2019-09-12 20:38:46 +08:00
|
|
|
uint32_t reserved : 28;
|
2019-02-27 21:59:46 +08:00
|
|
|
} flags;
|
|
|
|
uint32_t allFlags = 0u;
|
|
|
|
};
|
|
|
|
static_assert(sizeof(AllocationInfo::flags) == sizeof(AllocationInfo::allFlags), "");
|
|
|
|
AllocationInfo() {
|
|
|
|
flags.coherent = false;
|
|
|
|
flags.evictable = true;
|
2019-08-30 19:27:56 +08:00
|
|
|
flags.flushL3Required = true;
|
2019-02-27 21:59:46 +08:00
|
|
|
flags.is32BitAllocation = false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-03-13 22:31:46 +08:00
|
|
|
struct ReservedAddressRange {
|
|
|
|
void *addressPtr = nullptr;
|
|
|
|
size_t rangeSize = 0;
|
|
|
|
};
|
2018-11-07 16:33:55 +08:00
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
friend class SubmissionAggregator;
|
2019-03-13 22:31:46 +08:00
|
|
|
|
2019-11-04 23:03:30 +08:00
|
|
|
const uint32_t rootDeviceIndex;
|
2019-03-13 22:31:46 +08:00
|
|
|
AllocationInfo allocationInfo;
|
|
|
|
AubInfo aubInfo;
|
|
|
|
SharingInfo sharingInfo;
|
|
|
|
ReservedAddressRange reservedAddressRangeInfo;
|
|
|
|
|
|
|
|
uint64_t allocationOffset = 0u;
|
2019-02-27 21:59:46 +08:00
|
|
|
uint64_t gpuBaseAddress = 0;
|
2018-11-02 17:01:56 +08:00
|
|
|
uint64_t gpuAddress = 0;
|
2019-03-13 22:31:46 +08:00
|
|
|
void *driverAllocatedCpuPointer = nullptr;
|
|
|
|
size_t size = 0;
|
|
|
|
void *cpuPtr = nullptr;
|
2019-01-24 22:16:12 +08:00
|
|
|
void *lockedPtr = nullptr;
|
2019-02-27 21:59:46 +08:00
|
|
|
|
2018-11-02 17:01:56 +08:00
|
|
|
MemoryPool::Type memoryPool = MemoryPool::MemoryNull;
|
2018-07-20 03:34:45 +08:00
|
|
|
AllocationType allocationType = AllocationType::UNKNOWN;
|
2019-02-27 21:59:46 +08:00
|
|
|
|
2019-12-17 15:11:16 +08:00
|
|
|
std::vector<UsageInfo> usageInfos;
|
2018-11-02 17:01:56 +08:00
|
|
|
std::atomic<uint32_t> registeredContextsNum{0};
|
2019-12-17 15:11:16 +08:00
|
|
|
std::array<Gmm *, EngineLimits::maxHandleCount> gmms{};
|
2017-12-21 07:45:38 +08:00
|
|
|
};
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|