| 62 | } |
| 63 | |
| 64 | bool HostQueue::terminate() { |
| 65 | // incase of force destroy skip checking on the last command |
| 66 | if (AMD_DIRECT_DISPATCH) { |
| 67 | if (!forceDestroy_ && vdev() != nullptr) { |
| 68 | // If the queue still has the last command, then wait and release it |
| 69 | // We must be in protected way to get last command when calling |
| 70 | // awaitCompletion() where lastCommand will be released and possibly |
| 71 | // destroyed. |
| 72 | Command* lastCommand = getLastQueuedCommand(true); |
| 73 | if (lastCommand != nullptr) { |
| 74 | // Check if CPU batch wasn't flushed for completion with the last command |
| 75 | if (GetSubmissionBatchSize() != 0) { |
| 76 | auto command = new Marker(*this, false); |
| 77 | if (command != nullptr) { |
| 78 | ClPrint(LOG_DETAIL_DEBUG, LOG_CMD, "Marker queued to ensure finish"); |
| 79 | command->enqueue(); |
| 80 | lastCommand->release(); |
| 81 | lastCommand = command; |
| 82 | } |
| 83 | } |
| 84 | if (device_.gpu_error_ == CL_SUCCESS) { |
| 85 | lastCommand->awaitCompletion(); |
| 86 | } |
| 87 | // Note that if lastCommand isn't a marker, it may not be lastEnqueueCommand_ now |
| 88 | // after lastCommand->awaitCompletion() is called. |
| 89 | if (lastEnqueueCommand_ != nullptr) { |
| 90 | lastEnqueueCommand_->release(); // lastEnqueueCommand_ should be a marker |
| 91 | lastEnqueueCommand_ = nullptr; |
| 92 | } |
| 93 | lastCommand->release(); |
| 94 | } |
| 95 | } |
| 96 | thread_.Release(); |
| 97 | thread_.acceptingCommands_ = false; |
| 98 | } else { |
| 99 | if (Os::isThreadAlive(thread_)) { |
| 100 | Command* marker = nullptr; |
| 101 | // Send a finish if the queue is still accepting commands. |
| 102 | if (lastEnqueueCommand_ != nullptr || !amd::IS_HIP) { |
| 103 | ScopedLock sl(queueLock_); |
| 104 | if (thread_.acceptingCommands_) { |
| 105 | marker = new Marker(*this, false); |
| 106 | if (marker != nullptr) { |
| 107 | append(*marker); |
| 108 | queueLock_.notify(); |
| 109 | } |
| 110 | } |
| 111 | } |
| 112 | if (marker != nullptr) { |
| 113 | if (marker->notifyCmdQueue()) { |
| 114 | while (marker->status() > CL_COMPLETE && Os::isThreadAlive(thread_)) { |
| 115 | amd::Os::yield(); |
| 116 | } |
| 117 | } |
| 118 | marker->release(); |
| 119 | } |
| 120 | |
| 121 | // Wake-up the command loop, so it can exit |
nothing calls this directly
no test coverage detected