2020-05-26 18:25:27 +08:00
|
|
|
/*
|
2023-02-04 00:43:19 +08:00
|
|
|
* Copyright (C) 2020-2023 Intel Corporation
|
2020-05-26 18:25:27 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "shared/source/memory_manager/multi_graphics_allocation.h"
|
|
|
|
|
2022-07-27 23:41:20 +08:00
|
|
|
#include "shared/source/memory_manager/graphics_allocation.h"
|
2021-07-02 00:00:22 +08:00
|
|
|
#include "shared/source/memory_manager/migration_sync_data.h"
|
|
|
|
|
2020-05-26 18:25:27 +08:00
|
|
|
namespace NEO {
|
|
|
|
|
|
|
|
MultiGraphicsAllocation::MultiGraphicsAllocation(uint32_t maxRootDeviceIndex) {
|
|
|
|
graphicsAllocations.resize(maxRootDeviceIndex + 1);
|
2022-03-16 05:35:00 +08:00
|
|
|
for (auto &allocation : graphicsAllocations) {
|
|
|
|
allocation = nullptr;
|
|
|
|
}
|
2020-05-26 18:25:27 +08:00
|
|
|
}
|
|
|
|
|
2021-07-02 00:00:22 +08:00
|
|
|
MultiGraphicsAllocation::MultiGraphicsAllocation(const MultiGraphicsAllocation &multiGraphicsAllocation) {
|
|
|
|
this->graphicsAllocations = multiGraphicsAllocation.graphicsAllocations;
|
|
|
|
this->migrationSyncData = multiGraphicsAllocation.migrationSyncData;
|
|
|
|
this->isMultiStorage = multiGraphicsAllocation.isMultiStorage;
|
|
|
|
if (migrationSyncData) {
|
|
|
|
migrationSyncData->incRefInternal();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
MultiGraphicsAllocation::MultiGraphicsAllocation(MultiGraphicsAllocation &&multiGraphicsAllocation) {
|
|
|
|
this->graphicsAllocations = std::move(multiGraphicsAllocation.graphicsAllocations);
|
|
|
|
std::swap(this->migrationSyncData, multiGraphicsAllocation.migrationSyncData);
|
|
|
|
this->isMultiStorage = multiGraphicsAllocation.isMultiStorage;
|
|
|
|
};
|
|
|
|
|
|
|
|
MultiGraphicsAllocation::~MultiGraphicsAllocation() {
|
|
|
|
if (migrationSyncData) {
|
|
|
|
migrationSyncData->decRefInternal();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-26 18:25:27 +08:00
|
|
|
GraphicsAllocation *MultiGraphicsAllocation::getDefaultGraphicsAllocation() const {
|
|
|
|
for (auto &allocation : graphicsAllocations) {
|
|
|
|
if (allocation) {
|
|
|
|
return allocation;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MultiGraphicsAllocation::addAllocation(GraphicsAllocation *graphicsAllocation) {
|
|
|
|
UNRECOVERABLE_IF(graphicsAllocation == nullptr);
|
|
|
|
UNRECOVERABLE_IF(graphicsAllocations.size() < graphicsAllocation->getRootDeviceIndex() + 1);
|
|
|
|
graphicsAllocations[graphicsAllocation->getRootDeviceIndex()] = graphicsAllocation;
|
|
|
|
}
|
|
|
|
|
2020-06-02 19:38:13 +08:00
|
|
|
void MultiGraphicsAllocation::removeAllocation(uint32_t rootDeviceIndex) {
|
|
|
|
graphicsAllocations[rootDeviceIndex] = nullptr;
|
|
|
|
}
|
|
|
|
|
2020-05-26 18:25:27 +08:00
|
|
|
GraphicsAllocation *MultiGraphicsAllocation::getGraphicsAllocation(uint32_t rootDeviceIndex) const {
|
2022-03-16 05:35:00 +08:00
|
|
|
if (rootDeviceIndex >= graphicsAllocations.size()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2020-05-26 18:25:27 +08:00
|
|
|
return graphicsAllocations[rootDeviceIndex];
|
|
|
|
}
|
|
|
|
|
2022-02-04 21:59:01 +08:00
|
|
|
AllocationType MultiGraphicsAllocation::getAllocationType() const {
|
2020-05-26 18:25:27 +08:00
|
|
|
return getDefaultGraphicsAllocation()->getAllocationType();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MultiGraphicsAllocation::isCoherent() const {
|
|
|
|
return getDefaultGraphicsAllocation()->isCoherent();
|
|
|
|
}
|
|
|
|
|
2020-08-04 17:53:49 +08:00
|
|
|
StackVec<GraphicsAllocation *, 1> const &MultiGraphicsAllocation::getGraphicsAllocations() const {
|
2020-06-29 18:47:13 +08:00
|
|
|
return graphicsAllocations;
|
|
|
|
}
|
|
|
|
|
2021-07-02 00:00:22 +08:00
|
|
|
void MultiGraphicsAllocation::setMultiStorage(bool value) {
|
|
|
|
isMultiStorage = value;
|
|
|
|
if (isMultiStorage && !migrationSyncData) {
|
2021-07-23 01:48:33 +08:00
|
|
|
auto graphicsAllocation = getDefaultGraphicsAllocation();
|
|
|
|
UNRECOVERABLE_IF(!graphicsAllocation);
|
|
|
|
migrationSyncData = createMigrationSyncDataFunc(graphicsAllocation->getUnderlyingBufferSize());
|
2021-07-02 00:00:22 +08:00
|
|
|
migrationSyncData->incRefInternal();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MultiGraphicsAllocation::requiresMigrations() const {
|
|
|
|
if (migrationSyncData && migrationSyncData->isMigrationInProgress()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return isMultiStorage;
|
|
|
|
}
|
|
|
|
|
|
|
|
decltype(MultiGraphicsAllocation::createMigrationSyncDataFunc) MultiGraphicsAllocation::createMigrationSyncDataFunc = [](size_t size) -> MigrationSyncData * {
|
|
|
|
return new MigrationSyncData(size);
|
|
|
|
};
|
2020-05-26 18:25:27 +08:00
|
|
|
} // namespace NEO
|