2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2019-01-07 16:29:49 +08:00
|
|
|
* Copyright (C) 2017-2019 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-02-15 18:31:47 +08:00
|
|
|
#include "devices_bitfield.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
#include "runtime/helpers/debug_helpers.h"
|
2018-04-19 15:42:00 +08:00
|
|
|
#include "runtime/helpers/ptr_math.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
#include "runtime/memory_manager/host_ptr_defines.h"
|
2018-09-21 04:54:19 +08:00
|
|
|
#include "runtime/memory_manager/memory_banks.h"
|
2019-02-15 22:33:40 +08:00
|
|
|
#include "runtime/memory_manager/memory_constants.h"
|
2018-07-14 00:50:55 +08:00
|
|
|
#include "runtime/memory_manager/memory_pool.h"
|
|
|
|
#include "runtime/memory_manager/residency_container.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
#include "runtime/utilities/idlist.h"
|
2018-11-02 17:01:56 +08:00
|
|
|
#include "runtime/utilities/stackvec.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-02-11 17:02:27 +08:00
|
|
|
#include <array>
|
|
|
|
#include <cstddef>
|
|
|
|
#include <cstdint>
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
namespace OCLRT {
|
|
|
|
|
2018-09-21 12:07:50 +08:00
|
|
|
using osHandle = unsigned int;
|
2019-01-29 01:12:39 +08:00
|
|
|
|
|
|
|
enum class AllocationOrigin {
|
|
|
|
EXTERNAL_ALLOCATION,
|
|
|
|
INTERNAL_ALLOCATION
|
|
|
|
};
|
2018-09-21 12:07:50 +08:00
|
|
|
|
2019-02-15 22:33:40 +08:00
|
|
|
enum class HeapIndex : uint32_t {
|
|
|
|
HEAP_INTERNAL_DEVICE_MEMORY = 0u,
|
|
|
|
HEAP_INTERNAL = 1u,
|
|
|
|
HEAP_EXTERNAL_DEVICE_MEMORY = 2u,
|
|
|
|
HEAP_EXTERNAL = 3u,
|
|
|
|
HEAP_STANDARD,
|
|
|
|
HEAP_STANDARD64Kb,
|
|
|
|
HEAP_SVM,
|
|
|
|
HEAP_LIMITED
|
|
|
|
};
|
|
|
|
|
|
|
|
constexpr auto internalHeapIndex = is32bit ? HeapIndex::HEAP_INTERNAL : HeapIndex::HEAP_INTERNAL_DEVICE_MEMORY;
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
namespace Sharing {
|
|
|
|
constexpr auto nonSharedResource = 0u;
|
|
|
|
}
|
|
|
|
|
|
|
|
class Gmm;
|
|
|
|
|
|
|
|
class GraphicsAllocation : public IDNode<GraphicsAllocation> {
|
|
|
|
public:
|
2018-07-14 00:50:55 +08:00
|
|
|
OsHandleStorage fragmentsStorage;
|
|
|
|
bool is32BitAllocation = false;
|
|
|
|
uint64_t gpuBaseAddress = 0;
|
|
|
|
Gmm *gmm = nullptr;
|
|
|
|
uint64_t allocationOffset = 0u;
|
2018-10-30 21:44:41 +08:00
|
|
|
void *driverAllocatedCpuPointer = nullptr;
|
2019-02-15 18:31:47 +08:00
|
|
|
DevicesBitfield devicesBitfield = {};
|
2018-09-21 12:07:50 +08:00
|
|
|
bool flushL3Required = false;
|
2019-02-15 22:33:40 +08:00
|
|
|
AllocationOrigin origin = AllocationOrigin::EXTERNAL_ALLOCATION;
|
2018-07-14 00:50:55 +08:00
|
|
|
|
2018-07-20 03:34:45 +08:00
|
|
|
enum class AllocationType {
|
2018-07-05 22:31:57 +08:00
|
|
|
UNKNOWN = 0,
|
2018-07-23 01:27:33 +08:00
|
|
|
BUFFER_COMPRESSED,
|
2018-07-25 00:36:26 +08:00
|
|
|
BUFFER_HOST_MEMORY,
|
2018-07-05 22:31:57 +08:00
|
|
|
BUFFER,
|
|
|
|
IMAGE,
|
|
|
|
TAG_BUFFER,
|
|
|
|
LINEAR_STREAM,
|
|
|
|
FILL_PATTERN,
|
2018-07-09 20:12:32 +08:00
|
|
|
PIPE,
|
2019-02-08 17:27:48 +08:00
|
|
|
PROFILING_TAG_BUFFER,
|
|
|
|
TIMESTAMP_PACKET_TAG_BUFFER,
|
2018-07-09 20:12:32 +08:00
|
|
|
COMMAND_BUFFER,
|
|
|
|
PRINTF_SURFACE,
|
|
|
|
GLOBAL_SURFACE,
|
|
|
|
PRIVATE_SURFACE,
|
|
|
|
CONSTANT_SURFACE,
|
|
|
|
SCRATCH_SURFACE,
|
|
|
|
INSTRUCTION_HEAP,
|
|
|
|
INDIRECT_OBJECT_HEAP,
|
|
|
|
SURFACE_STATE_HEAP,
|
|
|
|
DYNAMIC_STATE_HEAP,
|
2019-01-28 20:59:37 +08:00
|
|
|
SHARED_RESOURCE_COPY,
|
2018-12-06 22:03:06 +08:00
|
|
|
SVM,
|
2018-12-21 17:16:27 +08:00
|
|
|
KERNEL_ISA,
|
|
|
|
INTERNAL_HEAP,
|
2018-12-06 22:03:06 +08:00
|
|
|
UNDECIDED,
|
2017-12-21 07:45:38 +08:00
|
|
|
};
|
|
|
|
|
2018-11-02 17:01:56 +08:00
|
|
|
virtual ~GraphicsAllocation();
|
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-02-11 17:02:27 +08:00
|
|
|
GraphicsAllocation(void *cpuPtrIn, uint64_t gpuAddress, uint64_t baseAddress, size_t sizeIn, bool multiOsContextCapable);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-02-11 17:02:27 +08:00
|
|
|
GraphicsAllocation(void *cpuPtrIn, size_t sizeIn, osHandle sharedHandleIn, bool multiOsContextCapable);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
void *getUnderlyingBuffer() const { return cpuPtr; }
|
|
|
|
void setCpuPtrAndGpuAddress(void *cpuPtr, uint64_t gpuAddress) {
|
|
|
|
this->cpuPtr = cpuPtr;
|
|
|
|
this->gpuAddress = gpuAddress;
|
|
|
|
}
|
|
|
|
size_t getUnderlyingBufferSize() const { return size; }
|
|
|
|
uint64_t getGpuAddress() {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isCoherent() { return coherent; };
|
|
|
|
void setCoherent(bool coherentIn) { this->coherent = coherentIn; };
|
|
|
|
void setSize(size_t size) { this->size = size; }
|
|
|
|
osHandle peekSharedHandle() { return sharedHandle; }
|
|
|
|
|
2018-12-21 00:38:38 +08:00
|
|
|
void setAllocationType(AllocationType allocationType);
|
2018-07-20 03:34:45 +08:00
|
|
|
AllocationType getAllocationType() const { return allocationType; }
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2018-07-20 03:34:45 +08:00
|
|
|
void setAubWritable(bool writable) { aubWritable = writable; }
|
|
|
|
bool isAubWritable() const { return aubWritable; }
|
2018-08-23 00:41:52 +08:00
|
|
|
void setAllocDumpable(bool dumpable) { allocDumpable = dumpable; }
|
|
|
|
bool isAllocDumpable() const { return allocDumpable; }
|
2018-07-20 03:34:45 +08:00
|
|
|
bool isMemObjectsAllocationWithWritableFlags() const { return memObjectsAllocationWithWritableFlags; }
|
|
|
|
void setMemObjectsAllocationWithWritableFlags(bool newValue) { memObjectsAllocationWithWritableFlags = newValue; }
|
2018-04-02 00:42:42 +08:00
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
bool isL3Capable();
|
2018-04-12 16:05:35 +08:00
|
|
|
void setEvictable(bool evictable) { this->evictable = evictable; }
|
|
|
|
bool peekEvictable() const { return evictable; }
|
|
|
|
|
2019-01-24 22:16:12 +08:00
|
|
|
void lock(void *ptr) { this->lockedPtr = ptr; }
|
|
|
|
void unlock() { this->lockedPtr = nullptr; }
|
|
|
|
bool isLocked() const { return lockedPtr != nullptr; }
|
|
|
|
void *getLockedPtr() const { return lockedPtr; }
|
2018-03-05 17:56:34 +08:00
|
|
|
|
|
|
|
void incReuseCount() { reuseCount++; }
|
|
|
|
void decReuseCount() { reuseCount--; }
|
|
|
|
uint32_t peekReuseCount() const { return reuseCount; }
|
2018-12-21 00:38:38 +08:00
|
|
|
MemoryPool::Type getMemoryPool() const {
|
2018-07-14 00:50:55 +08:00
|
|
|
return memoryPool;
|
|
|
|
}
|
2018-11-07 16:33:55 +08:00
|
|
|
bool isUsed() const { return registeredContextsNum > 0; }
|
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); }
|
2018-12-04 22:11:29 +08:00
|
|
|
uint32_t getInspectionId(uint32_t contextId) { return usageInfos[contextId].inspectionId; }
|
|
|
|
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); }
|
2018-12-18 21:02:08 +08:00
|
|
|
bool isResidencyTaskCountBelow(uint32_t taskCount, uint32_t contextId) { return !isResident(contextId) || getResidencyTaskCount(contextId) < taskCount; }
|
2018-11-02 17:01:56 +08:00
|
|
|
|
2019-01-07 16:29:49 +08:00
|
|
|
bool isMultiOsContextCapable() const { return multiOsContextCapable; }
|
2019-01-03 21:48:24 +08:00
|
|
|
bool isUsedByManyOsContexts() const { return registeredContextsNum > 1u; }
|
2018-12-20 15:43:57 +08:00
|
|
|
|
2018-12-21 00:38:38 +08:00
|
|
|
virtual std::string getAllocationInfoString() const;
|
|
|
|
|
2019-02-18 17:49:21 +08:00
|
|
|
static bool isCpuAccessRequired(AllocationType allocationType) {
|
|
|
|
return allocationType == AllocationType::LINEAR_STREAM ||
|
|
|
|
allocationType == AllocationType::KERNEL_ISA ||
|
|
|
|
allocationType == AllocationType::INTERNAL_HEAP ||
|
|
|
|
allocationType == AllocationType::TIMESTAMP_PACKET_TAG_BUFFER;
|
|
|
|
}
|
|
|
|
|
2018-11-06 18:38:49 +08:00
|
|
|
protected:
|
2018-11-07 16:33:55 +08:00
|
|
|
constexpr static uint32_t objectNotResident = (uint32_t)-1;
|
|
|
|
constexpr static uint32_t objectNotUsed = (uint32_t)-1;
|
|
|
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
//this variable can only be modified from SubmissionAggregator
|
|
|
|
friend class SubmissionAggregator;
|
2018-11-02 17:01:56 +08:00
|
|
|
size_t size = 0;
|
|
|
|
void *cpuPtr = nullptr;
|
|
|
|
uint64_t gpuAddress = 0;
|
|
|
|
bool coherent = false;
|
|
|
|
osHandle sharedHandle = Sharing::nonSharedResource;
|
2019-01-24 22:16:12 +08:00
|
|
|
void *lockedPtr = nullptr;
|
2018-11-02 17:01:56 +08:00
|
|
|
uint32_t reuseCount = 0; // GraphicsAllocation can be reused by shared resources
|
|
|
|
bool evictable = true;
|
|
|
|
MemoryPool::Type memoryPool = MemoryPool::MemoryNull;
|
2018-07-20 03:34:45 +08:00
|
|
|
AllocationType allocationType = AllocationType::UNKNOWN;
|
|
|
|
bool aubWritable = true;
|
2018-08-23 00:41:52 +08:00
|
|
|
bool allocDumpable = false;
|
2018-07-20 03:34:45 +08:00
|
|
|
bool memObjectsAllocationWithWritableFlags = false;
|
2019-02-11 17:02:27 +08:00
|
|
|
std::array<UsageInfo, maxOsContextCount> usageInfos;
|
2018-11-02 17:01:56 +08:00
|
|
|
std::atomic<uint32_t> registeredContextsNum{0};
|
2019-01-07 16:29:49 +08:00
|
|
|
bool multiOsContextCapable = false;
|
2017-12-21 07:45:38 +08:00
|
|
|
};
|
|
|
|
} // namespace OCLRT
|