File: shared_pool_allocation.h

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 (67 lines) | stat: -rw-r--r-- 1,861 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
/*
 * Copyright (C) 2025 Intel Corporation
 *
 * SPDX-License-Identifier: MIT
 *
 */

#pragma once

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

#include <mutex>

namespace NEO {

class SharedPoolAllocation {
  public:
    SharedPoolAllocation(GraphicsAllocation *graphicsAllocation, size_t offset, size_t size, std::mutex *mtx)
        : graphicsAllocation(graphicsAllocation), offset(offset), size(size), mtx(mtx){};

    explicit SharedPoolAllocation(GraphicsAllocation *graphicsAllocation)
        : graphicsAllocation(graphicsAllocation), offset(0u), size(graphicsAllocation ? graphicsAllocation->getUnderlyingBufferSize() : 0u), mtx(nullptr){};

    GraphicsAllocation *getGraphicsAllocation() const {
        return graphicsAllocation;
    }

    size_t getOffset() const {
        return offset;
    }

    size_t getSize() const {
        return size;
    }

    uint64_t getGpuAddress() const {
        UNRECOVERABLE_IF(graphicsAllocation == nullptr);
        return graphicsAllocation->getGpuAddress() + offset;
    }

    uint64_t getGpuAddressToPatch() const {
        UNRECOVERABLE_IF(graphicsAllocation == nullptr);
        return graphicsAllocation->getGpuAddressToPatch() + offset;
    }

    void *getUnderlyingBuffer() const {
        UNRECOVERABLE_IF(graphicsAllocation == nullptr);
        return ptrOffset(graphicsAllocation->getUnderlyingBuffer(), offset);
    }

    std::unique_lock<std::mutex> obtainSharedAllocationLock() {
        if (mtx) {
            return std::unique_lock<std::mutex>(*mtx);
        } else {
            DEBUG_BREAK_IF(true);
            return std::unique_lock<std::mutex>();
        }
    }

  private:
    GraphicsAllocation *graphicsAllocation;
    const size_t offset;
    const size_t size;
    std::mutex *mtx; // This mutex is shared across all users of this GA
};

} //  namespace NEO