| 191 | } |
| 192 | |
| 193 | ScopedActivateContext::~ScopedActivateContext() { |
| 194 | if (FLAGS_gpuexec_cuda_sync_around_driver_calls) SynchronizeOrDie(); |
| 195 | |
| 196 | auto* tls = &tls_data.get(); |
| 197 | |
| 198 | if (kVerifyGpuContext) { |
| 199 | // Note that if kVerifyGpuContext is used, and contexts are deleted, it's |
| 200 | // possible this could fail in the CurrentContext() call. |
| 201 | CHECK_EQ(CurrentContext(), |
| 202 | tls->context == nullptr ? nullptr : tls->context->context()); |
| 203 | } |
| 204 | |
| 205 | tls->depth--; |
| 206 | DCHECK_GE(tls->depth, 0); |
| 207 | if (to_restore_ == nullptr) { |
| 208 | // Leave context, tls->id, and tls->context set. |
| 209 | return; |
| 210 | } |
| 211 | |
| 212 | // Set context and update thread local. |
| 213 | FAIL_IF_CUDA_RES_ERROR(cuCtxSetCurrent(to_restore_->context()), |
| 214 | "Failed setting context"); |
| 215 | tls->id = to_restore_->id(); |
| 216 | tls->context = to_restore_; |
| 217 | } |
| 218 | |
| 219 | namespace { |
| 220 |
nothing calls this directly
no test coverage detected