MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / ScopedActivateContext

Method ScopedActivateContext

tensorflow/stream_executor/cuda/cuda_driver.cc:168–191  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

166} // namespace
167
168ScopedActivateContext::ScopedActivateContext(GpuContext* cuda_context) {
169 if (FLAGS_gpuexec_cuda_sync_around_driver_calls) SynchronizeOrDie();
170
171 auto* tls = &tls_data.get();
172 tls->depth++;
173 if (tls->id == cuda_context->id()) {
174 if (kVerifyGpuContext) {
175 CHECK_EQ(CurrentContext(), cuda_context->context());
176 }
177 DCHECK_EQ(CurrentContext(), cuda_context->context());
178 return;
179 }
180
181 VLOG(3) << "ScopedActivateContext switching context from " << tls->id
182 << " to " << cuda_context->id();
183
184 to_restore_ = (tls->depth == 1 ? nullptr : tls->context);
185
186 // Set the context and update thread local.
187 FAIL_IF_CUDA_RES_ERROR(cuCtxSetCurrent(cuda_context->context()),
188 "Failed setting context");
189 tls->id = cuda_context->id();
190 tls->context = cuda_context;
191}
192
193ScopedActivateContext::~ScopedActivateContext() {
194 if (FLAGS_gpuexec_cuda_sync_around_driver_calls) SynchronizeOrDie();

Callers

nothing calls this directly

Calls 5

CurrentContextFunction · 0.85
SynchronizeOrDieFunction · 0.70
getMethod · 0.45
idMethod · 0.45
contextMethod · 0.45

Tested by

no test coverage detected