2019-04-04 16:50:02 +08:00
|
|
|
/*
|
2023-01-24 23:33:52 +08:00
|
|
|
* Copyright (C) 2019-2023 Intel Corporation
|
2019-04-04 16:50:02 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/helpers/debug_helpers.h"
|
2023-01-24 23:33:52 +08:00
|
|
|
#include "shared/source/helpers/device_bitfield.h"
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/helpers/non_copyable_or_moveable.h"
|
2019-04-04 16:50:02 +08:00
|
|
|
|
|
|
|
#include <atomic>
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
namespace NEO {
|
|
|
|
class LocalMemoryUsageBankSelector : public NonCopyableOrMovableClass {
|
|
|
|
public:
|
|
|
|
LocalMemoryUsageBankSelector() = delete;
|
|
|
|
LocalMemoryUsageBankSelector(uint32_t banksCount);
|
2020-06-23 17:30:01 +08:00
|
|
|
uint32_t getLeastOccupiedBank(DeviceBitfield deviceBitfield);
|
2019-05-10 17:30:07 +08:00
|
|
|
void reserveOnBanks(uint32_t memoryBanks, uint64_t allocationSize) {
|
|
|
|
updateUsageInfo(memoryBanks, allocationSize, true);
|
|
|
|
}
|
|
|
|
void freeOnBanks(uint32_t memoryBanks, uint64_t allocationSize) {
|
|
|
|
updateUsageInfo(memoryBanks, allocationSize, false);
|
|
|
|
}
|
2019-04-04 16:50:02 +08:00
|
|
|
|
2019-05-10 17:30:07 +08:00
|
|
|
uint64_t getOccupiedMemorySizeForBank(uint32_t bankIndex) {
|
2019-04-04 16:50:02 +08:00
|
|
|
UNRECOVERABLE_IF(bankIndex >= banksCount);
|
|
|
|
return memorySizes[bankIndex].load();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
uint32_t banksCount = 0;
|
|
|
|
std::unique_ptr<std::atomic<uint64_t>[]> memorySizes = nullptr;
|
2019-05-10 17:30:07 +08:00
|
|
|
void updateUsageInfo(uint32_t memoryBanks, uint64_t allocationSize, bool reserve);
|
|
|
|
void freeOnBank(uint32_t bankIndex, uint64_t allocationSize);
|
|
|
|
void reserveOnBank(uint32_t bankIndex, uint64_t allocationSize);
|
2019-04-04 16:50:02 +08:00
|
|
|
};
|
|
|
|
} // namespace NEO
|