| 207 | } |
| 208 | |
| 209 | ScopedActivateContext::~ScopedActivateContext() { |
| 210 | if (FLAGS_gpuexec_rocm_sync_around_driver_calls) { |
| 211 | SynchronizeOrDie(); |
| 212 | } |
| 213 | |
| 214 | auto* tls = &tls_data.get(); |
| 215 | |
| 216 | if (kVerifyGpuContext) { |
| 217 | CHECK_EQ(CurrentDeviceOrDie(), tls->current_device_ordinal); |
| 218 | } |
| 219 | |
| 220 | tls->depth--; |
| 221 | DCHECK_GE(tls->depth, 0); |
| 222 | |
| 223 | if (to_restore_->device_ordinal() == tls->current_device_ordinal) { |
| 224 | DCHECK_EQ(CurrentDeviceOrDie(), to_restore_->device_ordinal()); |
| 225 | return; |
| 226 | } |
| 227 | |
| 228 | VLOG(3) << "ScopedActivateContext switching device from " |
| 229 | << tls->current_device_ordinal << " to " |
| 230 | << to_restore_->device_ordinal(); |
| 231 | |
| 232 | // Set context and update thread local. |
| 233 | CHECK_EQ(hipSuccess, |
| 234 | tensorflow::wrap::hipSetDevice(to_restore_->device_ordinal())); |
| 235 | tls->current_device_ordinal = to_restore_->device_ordinal(); |
| 236 | } |
| 237 | |
| 238 | namespace { |
| 239 |
nothing calls this directly
no test coverage detected