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

Method ensure_initialized

tensorflow/python/eager/context.py:472–509  ·  view source on GitHub ↗

Initialize handle and devices if not already done so.

(self)

Source from the content-addressed store, hash-verified

470 pywrap_tensorflow.TF_DeleteDeviceList(device_list)
471
472 def ensure_initialized(self):
473 """Initialize handle and devices if not already done so."""
474 if self._initialized:
475 return
476 with self._initialize_lock:
477 if self._initialized:
478 return
479 assert self._context_devices is None
480 opts = pywrap_tensorflow.TFE_NewContextOptions()
481 try:
482 config_str = self.config.SerializeToString()
483 pywrap_tensorflow.TFE_ContextOptionsSetConfig(opts, config_str)
484 if self._device_policy is not None:
485 pywrap_tensorflow.TFE_ContextOptionsSetDevicePlacementPolicy(
486 opts, self._device_policy)
487 if self._mirroring_policy is not None:
488 pywrap_tensorflow.TFE_ContextOptionsSetMirroringPolicy(
489 opts, self._mirroring_policy)
490 if self._default_is_async == ASYNC:
491 pywrap_tensorflow.TFE_ContextOptionsSetAsync(opts, True)
492 context_handle = pywrap_tensorflow.TFE_NewContext(opts)
493 finally:
494 pywrap_tensorflow.TFE_DeleteContextOptions(opts)
495 assert not (self._server_def and self._collective_ops_server_def), (
496 "Cannot enable remote execution as well as collective ops at the "
497 "moment. If this is important to you, please file an issue.")
498 if self._server_def is not None:
499 server_def_str = self._server_def.SerializeToString()
500 pywrap_tensorflow.TFE_ContextSetServerDef(context_handle, 600,
501 server_def_str)
502 elif self._collective_ops_server_def is not None:
503 server_def_str = self._collective_ops_server_def.SerializeToString()
504 pywrap_tensorflow.TFE_EnableCollectiveOps(context_handle,
505 server_def_str)
506
507 self._context_handle = context_handle
508 self._initialize_logical_devices()
509 self._initialized = True
510
511 def _clear_caches(self):
512 self.ones_rank_cache().flush()

Callers 15

num_gpusMethod · 0.95
add_functionMethod · 0.95
add_function_defMethod · 0.95
remove_functionMethod · 0.95
has_functionMethod · 0.95
list_logical_devicesMethod · 0.95
enable_run_metadataMethod · 0.95
testAsyncBasicMethod · 0.95
_ctxMethod · 0.80
__init__Method · 0.80

Calls 2

SerializeToStringMethod · 0.45