2017-12-21 00:45:38 +01:00
|
|
|
/*
|
2018-09-19 20:54:29 -07:00
|
|
|
* Copyright (C) 2017-2018 Intel Corporation
|
2017-12-21 00:45:38 +01:00
|
|
|
*
|
2018-09-19 20:54:29 -07:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 00:45:38 +01:00
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
#include <cstddef>
|
|
|
|
|
#include <cstdint>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
#include "runtime/helpers/debug_helpers.h"
|
2018-04-19 09:42:00 +02:00
|
|
|
#include "runtime/helpers/ptr_math.h"
|
2017-12-21 00:45:38 +01:00
|
|
|
#include "runtime/memory_manager/host_ptr_defines.h"
|
2018-09-20 13:54:19 -07:00
|
|
|
#include "runtime/memory_manager/memory_banks.h"
|
2018-07-13 18:50:55 +02:00
|
|
|
#include "runtime/memory_manager/memory_pool.h"
|
|
|
|
|
#include "runtime/memory_manager/residency_container.h"
|
2017-12-21 00:45:38 +01:00
|
|
|
#include "runtime/utilities/idlist.h"
|
2018-11-02 10:01:56 +01:00
|
|
|
#include "runtime/utilities/stackvec.h"
|
2017-12-21 00:45:38 +01:00
|
|
|
|
|
|
|
|
namespace OCLRT {
|
|
|
|
|
|
2018-09-20 21:07:50 -07:00
|
|
|
using osHandle = unsigned int;
|
2018-09-23 06:47:27 -07:00
|
|
|
using DevicesBitfield = uint32_t;
|
2018-09-20 21:07:50 -07:00
|
|
|
|
2017-12-21 00:45:38 +01:00
|
|
|
namespace Sharing {
|
|
|
|
|
constexpr auto nonSharedResource = 0u;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-19 20:54:29 -07:00
|
|
|
constexpr uint32_t maxOsContextCount = 4u;
|
2017-12-21 00:45:38 +01:00
|
|
|
const int ObjectNotResident = -1;
|
|
|
|
|
const uint32_t ObjectNotUsed = (uint32_t)-1;
|
|
|
|
|
|
|
|
|
|
class Gmm;
|
|
|
|
|
|
2018-11-06 11:38:49 +01:00
|
|
|
struct UsageInfo {
|
|
|
|
|
uint32_t taskCount = ObjectNotUsed;
|
|
|
|
|
int residencyTaskCount = ObjectNotResident;
|
|
|
|
|
};
|
|
|
|
|
|
2017-12-21 00:45:38 +01:00
|
|
|
class GraphicsAllocation : public IDNode<GraphicsAllocation> {
|
|
|
|
|
public:
|
2018-07-13 18:50:55 +02:00
|
|
|
OsHandleStorage fragmentsStorage;
|
|
|
|
|
bool is32BitAllocation = false;
|
|
|
|
|
uint64_t gpuBaseAddress = 0;
|
|
|
|
|
Gmm *gmm = nullptr;
|
|
|
|
|
uint64_t allocationOffset = 0u;
|
2018-10-30 14:44:41 +01:00
|
|
|
void *driverAllocatedCpuPointer = nullptr;
|
2018-09-23 06:47:27 -07:00
|
|
|
DevicesBitfield devicesBitfield = 0;
|
2018-09-20 21:07:50 -07:00
|
|
|
bool flushL3Required = false;
|
2018-07-13 18:50:55 +02:00
|
|
|
|
2018-07-19 21:34:45 +02:00
|
|
|
enum class AllocationType {
|
2018-07-05 16:31:57 +02:00
|
|
|
UNKNOWN = 0,
|
2018-07-22 19:27:33 +02:00
|
|
|
BUFFER_COMPRESSED,
|
2018-07-24 18:36:26 +02:00
|
|
|
BUFFER_HOST_MEMORY,
|
2018-07-05 16:31:57 +02:00
|
|
|
BUFFER,
|
|
|
|
|
IMAGE,
|
|
|
|
|
TAG_BUFFER,
|
|
|
|
|
LINEAR_STREAM,
|
|
|
|
|
FILL_PATTERN,
|
2018-07-09 14:12:32 +02:00
|
|
|
PIPE,
|
2018-11-14 15:26:23 +01:00
|
|
|
TIMESTAMP_TAG_BUFFER,
|
2018-07-09 14:12:32 +02:00
|
|
|
COMMAND_BUFFER,
|
|
|
|
|
PRINTF_SURFACE,
|
|
|
|
|
GLOBAL_SURFACE,
|
|
|
|
|
PRIVATE_SURFACE,
|
|
|
|
|
CONSTANT_SURFACE,
|
|
|
|
|
SCRATCH_SURFACE,
|
|
|
|
|
INSTRUCTION_HEAP,
|
|
|
|
|
INDIRECT_OBJECT_HEAP,
|
|
|
|
|
SURFACE_STATE_HEAP,
|
|
|
|
|
DYNAMIC_STATE_HEAP,
|
|
|
|
|
SHARED_RESOURCE,
|
2017-12-21 00:45:38 +01:00
|
|
|
};
|
|
|
|
|
|
2018-11-02 10:01:56 +01:00
|
|
|
virtual ~GraphicsAllocation();
|
2018-03-01 10:08:20 +01:00
|
|
|
GraphicsAllocation &operator=(const GraphicsAllocation &) = delete;
|
|
|
|
|
GraphicsAllocation(const GraphicsAllocation &) = delete;
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2018-11-02 10:01:56 +01:00
|
|
|
GraphicsAllocation(void *cpuPtrIn, uint64_t gpuAddress, uint64_t baseAddress, size_t sizeIn);
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2018-11-02 10:01:56 +01:00
|
|
|
GraphicsAllocation(void *cpuPtrIn, size_t sizeIn, osHandle sharedHandleIn);
|
2017-12-21 00:45:38 +01: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 03:25:27 +01:00
|
|
|
uint64_t getGpuAddressToPatch() const {
|
2017-12-21 00:45:38 +01: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-07-19 21:34:45 +02:00
|
|
|
void setAllocationType(AllocationType allocationType) { this->allocationType = allocationType; }
|
|
|
|
|
AllocationType getAllocationType() const { return allocationType; }
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2018-07-19 21:34:45 +02:00
|
|
|
void setAubWritable(bool writable) { aubWritable = writable; }
|
|
|
|
|
bool isAubWritable() const { return aubWritable; }
|
2018-08-22 18:41:52 +02:00
|
|
|
void setAllocDumpable(bool dumpable) { allocDumpable = dumpable; }
|
|
|
|
|
bool isAllocDumpable() const { return allocDumpable; }
|
2018-07-19 21:34:45 +02:00
|
|
|
bool isMemObjectsAllocationWithWritableFlags() const { return memObjectsAllocationWithWritableFlags; }
|
|
|
|
|
void setMemObjectsAllocationWithWritableFlags(bool newValue) { memObjectsAllocationWithWritableFlags = newValue; }
|
2018-04-01 18:42:42 +02:00
|
|
|
|
2017-12-21 00:45:38 +01:00
|
|
|
bool isL3Capable();
|
2018-04-12 10:05:35 +02:00
|
|
|
void setEvictable(bool evictable) { this->evictable = evictable; }
|
|
|
|
|
bool peekEvictable() const { return evictable; }
|
|
|
|
|
|
2018-11-06 11:38:49 +01:00
|
|
|
bool isResident(uint32_t contextId) const { return ObjectNotResident != getResidencyTaskCount(contextId); }
|
2018-03-05 10:56:34 +01:00
|
|
|
void setLocked(bool locked) { this->locked = locked; }
|
|
|
|
|
bool isLocked() const { return locked; }
|
|
|
|
|
|
|
|
|
|
void incReuseCount() { reuseCount++; }
|
|
|
|
|
void decReuseCount() { reuseCount--; }
|
|
|
|
|
uint32_t peekReuseCount() const { return reuseCount; }
|
2018-07-13 18:50:55 +02:00
|
|
|
MemoryPool::Type getMemoryPool() {
|
|
|
|
|
return memoryPool;
|
|
|
|
|
}
|
2018-11-06 11:38:49 +01:00
|
|
|
bool peekWasUsed() const { return registeredContextsNum > 0; }
|
2018-11-02 10:01:56 +01:00
|
|
|
void updateTaskCount(uint32_t newTaskCount, uint32_t contextId);
|
2018-11-06 11:38:49 +01:00
|
|
|
uint32_t getTaskCount(uint32_t contextId) const { return usageInfos[contextId].taskCount; }
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2018-11-06 11:38:49 +01:00
|
|
|
void updateResidencyTaskCount(int newTaskCount, uint32_t contextId) { usageInfos[contextId].residencyTaskCount = newTaskCount; }
|
|
|
|
|
int getResidencyTaskCount(uint32_t contextId) const { return usageInfos[contextId].residencyTaskCount; }
|
|
|
|
|
void resetResidencyTaskCount(uint32_t contextId) { updateResidencyTaskCount(ObjectNotResident, contextId); }
|
2018-11-02 10:01:56 +01:00
|
|
|
|
2018-11-06 11:38:49 +01:00
|
|
|
protected:
|
2017-12-21 00:45:38 +01:00
|
|
|
//this variable can only be modified from SubmissionAggregator
|
|
|
|
|
friend class SubmissionAggregator;
|
2018-11-02 10:01:56 +01:00
|
|
|
size_t size = 0;
|
|
|
|
|
void *cpuPtr = nullptr;
|
|
|
|
|
uint64_t gpuAddress = 0;
|
|
|
|
|
bool coherent = false;
|
|
|
|
|
osHandle sharedHandle = Sharing::nonSharedResource;
|
|
|
|
|
bool locked = false;
|
|
|
|
|
uint32_t reuseCount = 0; // GraphicsAllocation can be reused by shared resources
|
|
|
|
|
bool evictable = true;
|
|
|
|
|
MemoryPool::Type memoryPool = MemoryPool::MemoryNull;
|
2017-12-21 00:45:38 +01:00
|
|
|
uint32_t inspectionId = 0;
|
2018-07-19 21:34:45 +02:00
|
|
|
AllocationType allocationType = AllocationType::UNKNOWN;
|
|
|
|
|
bool aubWritable = true;
|
2018-08-22 18:41:52 +02:00
|
|
|
bool allocDumpable = false;
|
2018-07-19 21:34:45 +02:00
|
|
|
bool memObjectsAllocationWithWritableFlags = false;
|
2018-11-06 11:38:49 +01:00
|
|
|
StackVec<UsageInfo, maxOsContextCount> usageInfos{maxOsContextCount};
|
2018-11-02 10:01:56 +01:00
|
|
|
std::atomic<uint32_t> registeredContextsNum{0};
|
2017-12-21 00:45:38 +01:00
|
|
|
};
|
|
|
|
|
} // namespace OCLRT
|