refactor: use DeviceBitfield where appropriate
Replace less type-safe uint32_t and reduce conversions between both types. Related-To: NEO-9754 Signed-off-by: Maciej Bielski <maciej.bielski@intel.com>
This commit is contained in:
parent
2c488d9e84
commit
014720fc29
|
@ -680,7 +680,7 @@ GraphicsAllocation *DrmMemoryManager::allocateMemoryByKMD(const AllocationData &
|
|||
}
|
||||
BufferObject::BOType boType{};
|
||||
if (tryToUseGemCreateExt && drm.getMemoryInfo()) {
|
||||
ret = drm.getMemoryInfo()->createGemExtWithSingleRegion(allocationData.storageInfo.getMemoryBanks(), bufferSize, handle, patIndex, -1, allocationData.flags.isUSMHostAllocation);
|
||||
ret = drm.getMemoryInfo()->createGemExtWithSingleRegion(allocationData.storageInfo.memoryBanks, bufferSize, handle, patIndex, -1, allocationData.flags.isUSMHostAllocation);
|
||||
boType = getBOTypeFromPatIndex(patIndex, productHelper.isVmBindPatIndexProgrammingSupported());
|
||||
}
|
||||
|
||||
|
@ -1924,7 +1924,7 @@ GraphicsAllocation *DrmMemoryManager::allocateGraphicsMemoryInDevicePool(const A
|
|||
}
|
||||
|
||||
BufferObject *DrmMemoryManager::createBufferObjectInMemoryRegion(uint32_t rootDeviceIndex, Gmm *gmm, AllocationType allocationType, uint64_t gpuAddress,
|
||||
size_t size, uint32_t memoryBanks, size_t maxOsContextCount, int32_t pairHandle, bool isSystemMemoryPool, bool isUsmHostAllocation) {
|
||||
size_t size, DeviceBitfield memoryBanks, size_t maxOsContextCount, int32_t pairHandle, bool isSystemMemoryPool, bool isUsmHostAllocation) {
|
||||
auto drm = &getDrm(rootDeviceIndex);
|
||||
auto memoryInfo = drm->getMemoryInfo();
|
||||
if (!memoryInfo) {
|
||||
|
@ -1936,8 +1936,7 @@ BufferObject *DrmMemoryManager::createBufferObjectInMemoryRegion(uint32_t rootDe
|
|||
|
||||
auto patIndex = drm->getPatIndex(gmm, allocationType, CacheRegion::defaultRegion, CachePolicy::writeBack, false, isSystemMemoryPool);
|
||||
|
||||
auto banks = std::bitset<4>(memoryBanks);
|
||||
if (banks.count() > 1) {
|
||||
if (memoryBanks.count() > 1) {
|
||||
ret = memoryInfo->createGemExtWithMultipleRegions(memoryBanks, size, handle, patIndex, isUsmHostAllocation);
|
||||
} else {
|
||||
ret = memoryInfo->createGemExtWithSingleRegion(memoryBanks, size, handle, patIndex, pairHandle, isUsmHostAllocation);
|
||||
|
@ -2008,13 +2007,12 @@ bool DrmMemoryManager::createDrmChunkedAllocation(Drm *drm, DrmAllocation *alloc
|
|||
auto &storageInfo = allocation->storageInfo;
|
||||
auto memoryInfo = drm->getMemoryInfo();
|
||||
uint32_t handle = 0;
|
||||
auto memoryBanks = static_cast<uint32_t>(storageInfo.memoryBanks.to_ulong());
|
||||
auto alignSize = alignUp(boSize, MemoryConstants::pageSize64k);
|
||||
uint32_t numOfChunks = static_cast<uint32_t>(alignSize / getSizeOfChunk(alignSize));
|
||||
|
||||
auto gmm = allocation->getGmm(0u);
|
||||
auto patIndex = drm->getPatIndex(gmm, allocation->getAllocationType(), CacheRegion::defaultRegion, CachePolicy::writeBack, false, !allocation->isAllocatedInLocalMemoryPool());
|
||||
int ret = memoryInfo->createGemExtWithMultipleRegions(memoryBanks, boSize, handle, patIndex, -1, true, numOfChunks, allocation->isUsmHostAllocation());
|
||||
int ret = memoryInfo->createGemExtWithMultipleRegions(storageInfo.memoryBanks, boSize, handle, patIndex, -1, true, numOfChunks, allocation->isUsmHostAllocation());
|
||||
if (ret != 0) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -73,7 +73,7 @@ class DrmMemoryManager : public MemoryManager {
|
|||
size_t selectAlignmentAndHeap(size_t size, HeapIndex *heap) override;
|
||||
void freeGpuAddress(AddressRange addressRange, uint32_t rootDeviceIndex) override;
|
||||
MOCKABLE_VIRTUAL BufferObject *createBufferObjectInMemoryRegion(uint32_t rootDeviceIndex, Gmm *gmm, AllocationType allocationType, uint64_t gpuAddress, size_t size,
|
||||
uint32_t memoryBanks, size_t maxOsContextCount, int32_t pairHandle, bool isSystemMemoryPool, bool isUsmHostAllocation);
|
||||
DeviceBitfield memoryBanks, size_t maxOsContextCount, int32_t pairHandle, bool isSystemMemoryPool, bool isUsmHostAllocation);
|
||||
|
||||
bool hasPageFaultsEnabled(const Device &neoDevice) override;
|
||||
bool isKmdMigrationAvailable(uint32_t rootDeviceIndex) override;
|
||||
|
|
|
@ -131,13 +131,13 @@ void MemoryInfo::printRegionSizes() const {
|
|||
}
|
||||
}
|
||||
|
||||
int MemoryInfo::createGemExtWithSingleRegion(uint32_t memoryBanks, size_t allocSize, uint32_t &handle, uint64_t patIndex, int32_t pairHandle, bool isUSMHostAllocation) {
|
||||
int MemoryInfo::createGemExtWithSingleRegion(DeviceBitfield memoryBanks, size_t allocSize, uint32_t &handle, uint64_t patIndex, int32_t pairHandle, bool isUSMHostAllocation) {
|
||||
auto pHwInfo = this->drm.getRootDeviceEnvironment().getHardwareInfo();
|
||||
auto regionClassAndInstance = getMemoryRegionClassAndInstance(memoryBanks, *pHwInfo);
|
||||
MemRegionsVec region = {regionClassAndInstance};
|
||||
std::optional<uint32_t> vmId;
|
||||
if (!this->drm.isPerContextVMRequired()) {
|
||||
if (memoryBanks != 0 && debugManager.flags.EnablePrivateBO.get()) {
|
||||
if (memoryBanks.count() && debugManager.flags.EnablePrivateBO.get()) {
|
||||
auto tileIndex = getLocalMemoryRegionIndex(memoryBanks);
|
||||
vmId = this->drm.getVirtualMemoryAddressSpace(tileIndex);
|
||||
}
|
||||
|
@ -147,7 +147,7 @@ int MemoryInfo::createGemExtWithSingleRegion(uint32_t memoryBanks, size_t allocS
|
|||
return ret;
|
||||
}
|
||||
|
||||
int MemoryInfo::createGemExtWithMultipleRegions(uint32_t memoryBanks, size_t allocSize, uint32_t &handle, uint64_t patIndex, bool isUSMHostAllocation) {
|
||||
int MemoryInfo::createGemExtWithMultipleRegions(DeviceBitfield memoryBanks, size_t allocSize, uint32_t &handle, uint64_t patIndex, bool isUSMHostAllocation) {
|
||||
auto pHwInfo = this->drm.getRootDeviceEnvironment().getHardwareInfo();
|
||||
auto banks = std::bitset<4>(memoryBanks);
|
||||
MemRegionsVec memRegions{};
|
||||
|
@ -166,14 +166,13 @@ int MemoryInfo::createGemExtWithMultipleRegions(uint32_t memoryBanks, size_t all
|
|||
return ret;
|
||||
}
|
||||
|
||||
int MemoryInfo::createGemExtWithMultipleRegions(uint32_t memoryBanks, size_t allocSize, uint32_t &handle, uint64_t patIndex, int32_t pairHandle, bool isChunked, uint32_t numOfChunks, bool isUSMHostAllocation) {
|
||||
int MemoryInfo::createGemExtWithMultipleRegions(DeviceBitfield memoryBanks, size_t allocSize, uint32_t &handle, uint64_t patIndex, int32_t pairHandle, bool isChunked, uint32_t numOfChunks, bool isUSMHostAllocation) {
|
||||
auto pHwInfo = this->drm.getRootDeviceEnvironment().getHardwareInfo();
|
||||
auto banks = std::bitset<4>(memoryBanks);
|
||||
MemRegionsVec memRegions{};
|
||||
size_t currentBank = 0;
|
||||
size_t i = 0;
|
||||
while (i < banks.count()) {
|
||||
if (banks.test(currentBank)) {
|
||||
while (i < memoryBanks.count()) {
|
||||
if (memoryBanks.test(currentBank)) {
|
||||
auto regionClassAndInstance = getMemoryRegionClassAndInstance(1u << currentBank, *pHwInfo);
|
||||
memRegions.push_back(regionClassAndInstance);
|
||||
i++;
|
||||
|
|
|
@ -38,9 +38,9 @@ class MemoryInfo {
|
|||
|
||||
uint32_t getLocalMemoryRegionIndex(DeviceBitfield deviceBitfield) const;
|
||||
|
||||
MOCKABLE_VIRTUAL int createGemExtWithSingleRegion(uint32_t memoryBanks, size_t allocSize, uint32_t &handle, uint64_t patIndex, int32_t pairHandle, bool isUSMHostAllocation);
|
||||
MOCKABLE_VIRTUAL int createGemExtWithMultipleRegions(uint32_t memoryBanks, size_t allocSize, uint32_t &handle, uint64_t patIndex, bool isUSMHostAllocation);
|
||||
MOCKABLE_VIRTUAL int createGemExtWithMultipleRegions(uint32_t memoryBanks, size_t allocSize, uint32_t &handle, uint64_t patIndex, int32_t pairHandle, bool isChunked, uint32_t numOfChunks, bool isUSMHostAllocation);
|
||||
MOCKABLE_VIRTUAL int createGemExtWithSingleRegion(DeviceBitfield memoryBanks, size_t allocSize, uint32_t &handle, uint64_t patIndex, int32_t pairHandle, bool isUSMHostAllocation);
|
||||
MOCKABLE_VIRTUAL int createGemExtWithMultipleRegions(DeviceBitfield memoryBanks, size_t allocSize, uint32_t &handle, uint64_t patIndex, bool isUSMHostAllocation);
|
||||
MOCKABLE_VIRTUAL int createGemExtWithMultipleRegions(DeviceBitfield memoryBanks, size_t allocSize, uint32_t &handle, uint64_t patIndex, int32_t pairHandle, bool isChunked, uint32_t numOfChunks, bool isUSMHostAllocation);
|
||||
void populateTileToLocalMemoryRegionIndexMap();
|
||||
|
||||
const RegionContainer &getLocalMemoryRegions() const { return localMemoryRegions; }
|
||||
|
|
|
@ -76,7 +76,7 @@ struct MockedMemoryInfo : public NEO::MemoryInfo {
|
|||
handle = 1u;
|
||||
return 0;
|
||||
}
|
||||
int createGemExtWithSingleRegion(uint32_t memoryBanks, size_t allocSize, uint32_t &handle, uint64_t patIndex, int32_t pairHandle, bool isUSMHostAllocation) override {
|
||||
int createGemExtWithSingleRegion(DeviceBitfield memoryBanks, size_t allocSize, uint32_t &handle, uint64_t patIndex, int32_t pairHandle, bool isUSMHostAllocation) override {
|
||||
if (allocSize == 0) {
|
||||
return EINVAL;
|
||||
}
|
||||
|
@ -84,15 +84,15 @@ struct MockedMemoryInfo : public NEO::MemoryInfo {
|
|||
pairHandlePassed = pairHandle;
|
||||
return 0;
|
||||
}
|
||||
int createGemExtWithMultipleRegions(uint32_t memoryBanks, size_t allocSize, uint32_t &handle, uint64_t patIndex, bool isUSMHostAllocation) override {
|
||||
int createGemExtWithMultipleRegions(DeviceBitfield memoryBanks, size_t allocSize, uint32_t &handle, uint64_t patIndex, bool isUSMHostAllocation) override {
|
||||
if (allocSize == 0) {
|
||||
return EINVAL;
|
||||
}
|
||||
handle = 1u;
|
||||
banks = memoryBanks;
|
||||
banks = static_cast<uint32_t>(memoryBanks.to_ulong());
|
||||
return 0;
|
||||
}
|
||||
int createGemExtWithMultipleRegions(uint32_t memoryBanks, size_t allocSize, uint32_t &handle, uint64_t patIndex, int32_t pairHandle, bool isChunked, uint32_t numOfChunks, bool isUSMHostAllocation) override {
|
||||
int createGemExtWithMultipleRegions(DeviceBitfield memoryBanks, size_t allocSize, uint32_t &handle, uint64_t patIndex, int32_t pairHandle, bool isChunked, uint32_t numOfChunks, bool isUSMHostAllocation) override {
|
||||
if (allocSize == 0) {
|
||||
return EINVAL;
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ struct MockedMemoryInfo : public NEO::MemoryInfo {
|
|||
return -1;
|
||||
}
|
||||
handle = 1u;
|
||||
banks = memoryBanks;
|
||||
banks = static_cast<uint32_t>(memoryBanks.to_ulong());
|
||||
isChunkedUsed = isChunked;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -447,11 +447,11 @@ class DrmMemoryManagerLocalMemoryMemoryBankMock : public TestedDrmMemoryManager
|
|||
AllocationType allocationType,
|
||||
uint64_t gpuAddress,
|
||||
size_t size,
|
||||
uint32_t memoryBanks,
|
||||
DeviceBitfield memoryBanks,
|
||||
size_t maxOsContextCount,
|
||||
int32_t pairHandle,
|
||||
bool isSystemMemoryPool, bool isUSMHostAllocation) override {
|
||||
memoryBankIsOne = (memoryBanks == 1) ? true : false;
|
||||
memoryBankIsOne = (memoryBanks.to_ulong() == 1u) ? true : false;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue