/* * Copyright (C) 2025 Intel Corporation * * SPDX-License-Identifier: MIT * */ #include "shared/source/command_stream/host_function_worker_interface.h" #include "shared/source/command_stream/host_function.h" #include "shared/source/utilities/wait_util.h" #include #include namespace NEO { IHostFunctionWorker::IHostFunctionWorker(bool skipHostFunctionExecution, const std::function &downloadAllocationImpl, GraphicsAllocation *allocation, HostFunctionData *data) : downloadAllocationImpl(downloadAllocationImpl), allocation(allocation), data(data), skipHostFunctionExecution(skipHostFunctionExecution) { } IHostFunctionWorker::~IHostFunctionWorker() = default; bool IHostFunctionWorker::runHostFunction(std::stop_token st) noexcept { using tagStatusT = std::underlying_type_t; const auto start = std::chrono::steady_clock::now(); std::chrono::microseconds waitTime{0}; if (!this->skipHostFunctionExecution) { while (true) { if (this->downloadAllocationImpl) [[unlikely]] { this->downloadAllocationImpl(*this->allocation); } const volatile uint32_t *hostFuntionTagAddress = this->data->internalTag; waitTime = std::chrono::duration_cast(std::chrono::steady_clock::now() - start); bool pendingJobFound = WaitUtils::waitFunctionWithPredicate(hostFuntionTagAddress, static_cast(HostFunctionTagStatus::pending), std::equal_to(), waitTime.count()); if (pendingJobFound) { break; } if (st.stop_requested()) { return false; } } using CallbackT = void (*)(void *); CallbackT callback = reinterpret_cast(*this->data->entry); void *callbackData = reinterpret_cast(*this->data->userData); callback(callbackData); } *this->data->internalTag = static_cast(HostFunctionTagStatus::completed); return true; } } // namespace NEO