2020-03-06 11:09:57 +01:00
|
|
|
/*
|
2022-01-31 11:06:18 +00:00
|
|
|
* Copyright (C) 2020-2022 Intel Corporation
|
2020-03-06 11:09:57 +01:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2020-03-18 22:21:57 -07:00
|
|
|
#include "level_zero/core/source/fence/fence.h"
|
2020-03-06 11:09:57 +01:00
|
|
|
|
|
|
|
|
#include "shared/source/command_stream/command_stream_receiver.h"
|
2022-08-30 11:35:43 +00:00
|
|
|
|
|
|
|
|
#include "level_zero/core/source/cmdqueue/cmdqueue_imp.h"
|
2020-03-06 11:09:57 +01:00
|
|
|
|
|
|
|
|
namespace L0 {
|
|
|
|
|
|
|
|
|
|
Fence *Fence::create(CommandQueueImp *cmdQueue, const ze_fence_desc_t *desc) {
|
2022-03-17 09:43:17 +00:00
|
|
|
auto fence = new Fence(cmdQueue);
|
2020-03-06 11:09:57 +01:00
|
|
|
UNRECOVERABLE_IF(fence == nullptr);
|
2022-03-17 09:43:17 +00:00
|
|
|
fence->reset(!!(desc->flags & ZE_FENCE_FLAG_SIGNALED));
|
2020-03-06 11:09:57 +01:00
|
|
|
return fence;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-17 09:43:17 +00:00
|
|
|
ze_result_t Fence::queryStatus() {
|
2020-05-13 11:25:29 +02:00
|
|
|
auto csr = cmdQueue->getCsr();
|
2021-11-30 14:41:26 +00:00
|
|
|
csr->downloadAllocations();
|
2020-05-13 11:25:29 +02:00
|
|
|
|
2022-01-31 11:06:18 +00:00
|
|
|
auto *hostAddr = csr->getTagAddress();
|
2020-05-13 11:25:29 +02:00
|
|
|
|
2022-01-31 11:06:18 +00:00
|
|
|
return csr->testTaskCountReady(hostAddr, taskCount) ? ZE_RESULT_SUCCESS : ZE_RESULT_NOT_READY;
|
|
|
|
|
}
|
2021-09-17 13:05:26 +00:00
|
|
|
|
2022-03-17 09:43:17 +00:00
|
|
|
ze_result_t Fence::assignTaskCountFromCsr() {
|
2022-01-31 11:06:18 +00:00
|
|
|
auto csr = cmdQueue->getCsr();
|
|
|
|
|
taskCount = csr->peekTaskCount() + 1;
|
|
|
|
|
return ZE_RESULT_SUCCESS;
|
2020-03-06 11:09:57 +01:00
|
|
|
}
|
|
|
|
|
|
2022-03-17 09:43:17 +00:00
|
|
|
ze_result_t Fence::reset(bool signaled) {
|
|
|
|
|
if (signaled) {
|
|
|
|
|
taskCount = 0;
|
|
|
|
|
} else {
|
|
|
|
|
taskCount = std::numeric_limits<uint32_t>::max();
|
|
|
|
|
}
|
2020-03-06 11:09:57 +01:00
|
|
|
return ZE_RESULT_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-17 09:43:17 +00:00
|
|
|
ze_result_t Fence::hostSynchronize(uint64_t timeout) {
|
2022-02-16 10:22:03 +00:00
|
|
|
std::chrono::high_resolution_clock::time_point waitStartTime, lastHangCheckTime, currentTime;
|
2020-07-29 02:45:54 -07:00
|
|
|
uint64_t timeDiff = 0;
|
2020-03-06 11:09:57 +01:00
|
|
|
ze_result_t ret = ZE_RESULT_NOT_READY;
|
2022-02-16 10:22:03 +00:00
|
|
|
const auto csr = cmdQueue->getCsr();
|
2020-03-06 11:09:57 +01:00
|
|
|
|
2022-02-16 10:22:03 +00:00
|
|
|
if (csr->getType() == NEO::CommandStreamReceiverType::CSR_AUB) {
|
2020-03-06 11:09:57 +01:00
|
|
|
return ZE_RESULT_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-31 11:06:18 +00:00
|
|
|
if (std::numeric_limits<uint32_t>::max() == taskCount) {
|
|
|
|
|
return ZE_RESULT_NOT_READY;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-06 11:09:57 +01:00
|
|
|
if (timeout == 0) {
|
|
|
|
|
return queryStatus();
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-16 10:22:03 +00:00
|
|
|
waitStartTime = std::chrono::high_resolution_clock::now();
|
|
|
|
|
lastHangCheckTime = waitStartTime;
|
2020-03-06 11:09:57 +01:00
|
|
|
while (timeDiff < timeout) {
|
|
|
|
|
ret = queryStatus();
|
|
|
|
|
if (ret == ZE_RESULT_SUCCESS) {
|
|
|
|
|
return ZE_RESULT_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-16 10:22:03 +00:00
|
|
|
currentTime = std::chrono::high_resolution_clock::now();
|
2022-09-19 10:20:14 +00:00
|
|
|
if (csr->checkGpuHangDetected(currentTime, lastHangCheckTime)) {
|
|
|
|
|
return ZE_RESULT_ERROR_DEVICE_LOST;
|
2022-02-16 10:22:03 +00:00
|
|
|
}
|
|
|
|
|
|
2020-07-29 02:45:54 -07:00
|
|
|
if (timeout == std::numeric_limits<uint64_t>::max()) {
|
2020-03-06 11:09:57 +01:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-16 10:22:03 +00:00
|
|
|
timeDiff = std::chrono::duration_cast<std::chrono::nanoseconds>(currentTime - waitStartTime).count();
|
2020-03-06 11:09:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace L0
|