2020-03-06 18:09:57 +08:00
|
|
|
/*
|
2022-01-31 19:06:18 +08:00
|
|
|
* Copyright (C) 2020-2022 Intel Corporation
|
2020-03-06 18:09:57 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2020-03-19 13:21:57 +08:00
|
|
|
#include "level_zero/core/source/fence/fence.h"
|
2020-03-06 18:09:57 +08:00
|
|
|
|
|
|
|
#include "shared/source/command_stream/command_stream_receiver.h"
|
2020-04-02 17:28:38 +08:00
|
|
|
#include "shared/source/helpers/constants.h"
|
2021-03-24 04:12:41 +08:00
|
|
|
#include "shared/source/helpers/string.h"
|
2020-03-06 18:09:57 +08:00
|
|
|
#include "shared/source/memory_manager/memory_manager.h"
|
2021-03-31 02:11:00 +08:00
|
|
|
#include "shared/source/utilities/wait_util.h"
|
2020-03-06 18:09:57 +08:00
|
|
|
|
|
|
|
namespace L0 {
|
|
|
|
|
|
|
|
Fence *Fence::create(CommandQueueImp *cmdQueue, const ze_fence_desc_t *desc) {
|
|
|
|
auto fence = new FenceImp(cmdQueue);
|
|
|
|
UNRECOVERABLE_IF(fence == nullptr);
|
2022-01-31 19:06:18 +08:00
|
|
|
fence->reset();
|
2020-03-06 18:09:57 +08:00
|
|
|
return fence;
|
|
|
|
}
|
|
|
|
|
2020-05-13 17:25:29 +08:00
|
|
|
ze_result_t FenceImp::queryStatus() {
|
|
|
|
auto csr = cmdQueue->getCsr();
|
2021-11-30 22:41:26 +08:00
|
|
|
csr->downloadAllocations();
|
2020-05-13 17:25:29 +08:00
|
|
|
|
2022-01-31 19:06:18 +08:00
|
|
|
auto *hostAddr = csr->getTagAddress();
|
2020-05-13 17:25:29 +08:00
|
|
|
|
2022-01-31 19:06:18 +08:00
|
|
|
return csr->testTaskCountReady(hostAddr, taskCount) ? ZE_RESULT_SUCCESS : ZE_RESULT_NOT_READY;
|
|
|
|
}
|
2021-09-17 21:05:26 +08:00
|
|
|
|
2022-01-31 19:06:18 +08:00
|
|
|
ze_result_t FenceImp::assignTaskCountFromCsr() {
|
|
|
|
auto csr = cmdQueue->getCsr();
|
|
|
|
taskCount = csr->peekTaskCount() + 1;
|
|
|
|
return ZE_RESULT_SUCCESS;
|
2020-03-06 18:09:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ze_result_t FenceImp::reset() {
|
2022-01-31 19:06:18 +08:00
|
|
|
taskCount = std::numeric_limits<uint32_t>::max();
|
2020-03-06 18:09:57 +08:00
|
|
|
return ZE_RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2020-07-29 17:45:54 +08:00
|
|
|
ze_result_t FenceImp::hostSynchronize(uint64_t timeout) {
|
2020-03-06 18:09:57 +08:00
|
|
|
std::chrono::high_resolution_clock::time_point time1, time2;
|
2020-07-29 17:45:54 +08:00
|
|
|
uint64_t timeDiff = 0;
|
2020-03-06 18:09:57 +08:00
|
|
|
ze_result_t ret = ZE_RESULT_NOT_READY;
|
|
|
|
|
|
|
|
if (cmdQueue->getCsr()->getType() == NEO::CommandStreamReceiverType::CSR_AUB) {
|
|
|
|
return ZE_RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2022-01-31 19:06:18 +08:00
|
|
|
if (std::numeric_limits<uint32_t>::max() == taskCount) {
|
|
|
|
return ZE_RESULT_NOT_READY;
|
|
|
|
}
|
|
|
|
|
2020-03-06 18:09:57 +08:00
|
|
|
if (timeout == 0) {
|
|
|
|
return queryStatus();
|
|
|
|
}
|
|
|
|
|
|
|
|
time1 = std::chrono::high_resolution_clock::now();
|
|
|
|
while (timeDiff < timeout) {
|
|
|
|
ret = queryStatus();
|
|
|
|
if (ret == ZE_RESULT_SUCCESS) {
|
|
|
|
return ZE_RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2021-03-31 02:11:00 +08:00
|
|
|
NEO::WaitUtils::waitFunction(nullptr, 0u);
|
2020-03-06 18:09:57 +08:00
|
|
|
|
2020-07-29 17:45:54 +08:00
|
|
|
if (timeout == std::numeric_limits<uint64_t>::max()) {
|
2020-03-06 18:09:57 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
time2 = std::chrono::high_resolution_clock::now();
|
|
|
|
timeDiff = std::chrono::duration_cast<std::chrono::nanoseconds>(time2 - time1).count();
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace L0
|