File: unified_memory_reuse_cleaner.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 (54 lines) | stat: -rw-r--r-- 1,566 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
/*
 * Copyright (C) 2024-2025 Intel Corporation
 *
 * SPDX-License-Identifier: MIT
 *
 */

#pragma once

#include "shared/source/helpers/non_copyable_or_moveable.h"
#include "shared/source/memory_manager/unified_memory_manager.h"

#include <chrono>
#include <memory>
#include <mutex>
#include <vector>
namespace NEO {
class Thread;
class UnifiedMemoryReuseCleaner : NEO::NonCopyableAndNonMovableClass {
    using SvmAllocationCache = SVMAllocsManager::SvmAllocationCache;

  public:
    static constexpr auto sleepTime = std::chrono::milliseconds(15u);
    static constexpr auto maxHoldTime = std::chrono::seconds(10u);
    static constexpr auto limitedHoldTime = std::chrono::seconds(2u);
    UnifiedMemoryReuseCleaner(bool trimAllAllocations);
    virtual ~UnifiedMemoryReuseCleaner();

    MOCKABLE_VIRTUAL void startThread();
    void stopThread();

    static bool isSupported();

    void registerSvmAllocationCache(SvmAllocationCache *cache);
    void unregisterSvmAllocationCache(SvmAllocationCache *cache);

  protected:
    void startCleaning() { runCleaning.store(true); };
    static void *cleanUnifiedMemoryReuse(void *self);
    MOCKABLE_VIRTUAL void trimOldInCaches();
    std::unique_ptr<Thread> unifiedMemoryReuseCleanerThread;

    std::vector<SvmAllocationCache *> svmAllocationCaches;
    std::mutex svmAllocationCachesMutex;

    std::atomic_bool runCleaning = false;
    std::atomic_bool keepCleaning = true;

    bool trimAllAllocations = false;
};

static_assert(NEO::NonCopyableAndNonMovable<UnifiedMemoryReuseCleaner>);

} // namespace NEO