File: host_function_worker_atomic.cpp

package info (click to toggle)
intel-compute-runtime 25.48.36300.8-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 80,652 kB
  • sloc: cpp: 939,022; lisp: 2,090; sh: 722; makefile: 162; python: 21
file content (68 lines) | stat: -rw-r--r-- 1,880 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
/*
 * Copyright (C) 2025 Intel Corporation
 *
 * SPDX-License-Identifier: MIT
 *
 */

#include "shared/source/command_stream/host_function_worker_atomic.h"

#include "shared/source/command_stream/host_function.h"

namespace NEO {
HostFunctionWorkerAtomic::HostFunctionWorkerAtomic(bool skipHostFunctionExecution,
                                                   const std::function<void(GraphicsAllocation &)> &downloadAllocationImpl,
                                                   GraphicsAllocation *allocation,
                                                   HostFunctionData *data)
    : IHostFunctionWorker(skipHostFunctionExecution, downloadAllocationImpl, allocation, data) {
}

HostFunctionWorkerAtomic::~HostFunctionWorkerAtomic() = default;

void HostFunctionWorkerAtomic::start() {

    std::lock_guard<std::mutex> lg{workerMutex};
    if (!worker) {
        worker = std::make_unique<std::jthread>([this](std::stop_token st) {
            this->workerLoop(std::move(st));
        });
    }
}

void HostFunctionWorkerAtomic::finish() {
    std::lock_guard<std::mutex> lg{workerMutex};
    if (worker) {
        worker->request_stop();
        pending.fetch_add(1u);
        pending.notify_one();
        worker.reset(nullptr);
    }
}

void HostFunctionWorkerAtomic::submit() noexcept {
    pending.fetch_add(1, std::memory_order_release);
    pending.notify_one();
}

void HostFunctionWorkerAtomic::workerLoop(std::stop_token st) noexcept {

    while (true) {

        while (pending.load(std::memory_order_acquire) == 0) {
            pending.wait(0, std::memory_order_acquire);
        }

        if (st.stop_requested()) {
            return;
        }

        pending.fetch_sub(1, std::memory_order_acq_rel);

        bool sucess = this->runHostFunction(st);
        if (!sucess) [[unlikely]] {
            return;
        }
    }
}

} // namespace NEO