MCPcopy Create free account
hub / github.com/ROCm/clr / terminate

Method terminate

rocclr/platform/commandqueue.cpp:64–142  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

62}
63
64bool 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

Callers

nothing calls this directly

Calls 11

as_clFunction · 0.85
notifyMethod · 0.80
notifyCmdQueueMethod · 0.80
statusMethod · 0.80
asCommandQueueMethod · 0.80
enqueueMethod · 0.45
releaseMethod · 0.45
awaitCompletionMethod · 0.45
ReleaseMethod · 0.45
stateMethod · 0.45

Tested by

no test coverage detected