File: multi_graphics_allocation.cpp

package info (click to toggle)
intel-compute-runtime 25.35.35096.9-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 79,324 kB
  • sloc: cpp: 926,243; lisp: 3,433; sh: 715; makefile: 162; python: 21
file content (100 lines) | stat: -rw-r--r-- 3,552 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
 * Copyright (C) 2020-2025 Intel Corporation
 *
 * SPDX-License-Identifier: MIT
 *
 */

#include "shared/source/memory_manager/multi_graphics_allocation.h"

#include "shared/source/memory_manager/graphics_allocation.h"
#include "shared/source/memory_manager/migration_sync_data.h"

namespace NEO {

MultiGraphicsAllocation::MultiGraphicsAllocation(uint32_t maxRootDeviceIndex) {
    graphicsAllocations.resize(maxRootDeviceIndex + 1);
    for (auto &allocation : graphicsAllocations) {
        allocation = nullptr;
    }
}

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) noexcept {
    this->graphicsAllocations = std::move(multiGraphicsAllocation.graphicsAllocations);
    std::swap(this->migrationSyncData, multiGraphicsAllocation.migrationSyncData);
    this->isMultiStorage = multiGraphicsAllocation.isMultiStorage;
};

MultiGraphicsAllocation::~MultiGraphicsAllocation() {
    if (migrationSyncData) {
        migrationSyncData->decRefInternal();
    }
}

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;
}

void MultiGraphicsAllocation::removeAllocation(uint32_t rootDeviceIndex) {
    graphicsAllocations[rootDeviceIndex] = nullptr;
}

GraphicsAllocation *MultiGraphicsAllocation::getGraphicsAllocation(uint32_t rootDeviceIndex) const {
    if (rootDeviceIndex >= graphicsAllocations.size()) {
        return nullptr;
    }
    return graphicsAllocations[rootDeviceIndex];
}

AllocationType MultiGraphicsAllocation::getAllocationType() const {
    return getDefaultGraphicsAllocation()->getAllocationType();
}

bool MultiGraphicsAllocation::isCoherent() const {
    return getDefaultGraphicsAllocation()->isCoherent();
}

StackVec<GraphicsAllocation *, 1> const &MultiGraphicsAllocation::getGraphicsAllocations() const {
    return graphicsAllocations;
}

void MultiGraphicsAllocation::setMultiStorage(bool value) {
    isMultiStorage = value;
    if (isMultiStorage && !migrationSyncData) {
        auto graphicsAllocation = getDefaultGraphicsAllocation();
        UNRECOVERABLE_IF(!graphicsAllocation);
        migrationSyncData = createMigrationSyncDataFunc(graphicsAllocation->getUnderlyingBufferSize());
        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);
};
} // namespace NEO