コード例 #1
0
ファイル: context.py プロジェクト: zuozi2810/tensorflow
    def set_server_def(self, server_def, keep_alive_secs=600):
        """Allow setting a server_def on the context.

    When a server def is replaced, it effectively clears a bunch of caches
    within the context. If you attempt to use a tensor object that was pointing
    to a tensor on the remote device, it will raise an error.

    Args:
      server_def: A tensorflow::ServerDef proto.
        Enables execution on remote devices.
      keep_alive_secs: Num. seconds after which the remote end will hang up.
        As long as the client is still alive, the server state for the context
        will be kept alive. If the client is killed (or there is some failure),
        the server will clean up its context keep_alive_secs after the final RPC
        it receives.

    Raises:
      ValueError: if server_def is None.
    """
        if not server_def:
            raise ValueError("server_def is None.")
        if not self._context_handle:
            self._server_def = server_def
        else:
            server_def_str = server_def.SerializeToString()
            pywrap_tensorflow.TFE_ContextSetServerDef(self._context_handle,
                                                      keep_alive_secs,
                                                      server_def_str)

            # Clear all the caches in case there are remote tensors in them.
            self._clear_caches()

            self._initialize_devices()
コード例 #2
0
    def _initialize_handle_and_devices(self):
        """Initialize handle and devices."""
        with self._initialize_lock:
            if self._context_handle is not None:
                return
            assert self._context_devices is None
            opts = pywrap_tensorflow.TFE_NewContextOptions()
            try:
                if self._config is not None:
                    config_str = self._config.SerializeToString()
                    pywrap_tensorflow.TFE_ContextOptionsSetConfig(
                        opts, config_str)
                if self._device_policy is not None:
                    pywrap_tensorflow.TFE_ContextOptionsSetDevicePlacementPolicy(
                        opts, self._device_policy)
                if self._execution_mode == ASYNC:
                    pywrap_tensorflow.TFE_ContextOptionsSetAsync(opts, True)
                self._context_handle = pywrap_tensorflow.TFE_NewContext(opts)
            finally:
                pywrap_tensorflow.TFE_DeleteContextOptions(opts)
            if self._server_def is not None:
                server_def_str = self._server_def.SerializeToString()
                pywrap_tensorflow.TFE_ContextSetServerDef(
                    self._context_handle, 600, server_def_str)

            self._initialize_devices()
コード例 #3
0
ファイル: context.py プロジェクト: zuozi2810/tensorflow
    def _initialize_handle_and_devices(self):
        """Initialize handle and devices."""
        with self._initialize_lock:
            if self._context_handle is not None:
                return
            assert self._context_devices is None
            opts = pywrap_tensorflow.TFE_NewContextOptions()
            try:
                if self._config is not None:
                    config_str = self._config.SerializeToString()
                    pywrap_tensorflow.TFE_ContextOptionsSetConfig(
                        opts, config_str)
                if self._device_policy is not None:
                    pywrap_tensorflow.TFE_ContextOptionsSetDevicePlacementPolicy(
                        opts, self._device_policy)
                if self._execution_mode == ASYNC:
                    pywrap_tensorflow.TFE_ContextOptionsSetAsync(opts, True)
                self._context_handle = pywrap_tensorflow.TFE_NewContext(opts)
            finally:
                pywrap_tensorflow.TFE_DeleteContextOptions(opts)
            assert not (
                self._server_def and self._collective_ops_server_def
            ), ("Cannot enable remote execution as well as collective ops at the "
                "moment. If this is important to you, please file an issue.")
            if self._server_def is not None:
                server_def_str = self._server_def.SerializeToString()
                pywrap_tensorflow.TFE_ContextSetServerDef(
                    self._context_handle, 600, server_def_str)
            elif self._collective_ops_server_def is not None:
                server_def_str = self._collective_ops_server_def.SerializeToString(
                )
                pywrap_tensorflow.TFE_EnableCollectiveOps(
                    self._context_handle, server_def_str)

            self._initialize_devices()
コード例 #4
0
ファイル: context.py プロジェクト: wxfwzt/tensorflow-1
    def set_server_def(self, server_def):
        """Allow setting a server_def on the context.

    When a server def is replaced, it effectively clears a bunch of caches
    within the context. If you attempt to use a tensor object that was pointing
    to a tensor on the remote device, it will raise an error.

    Args:
      server_def: A tensorflow::ServerDef proto.
        Enables execution on remote devices.

    Raises:
      ValueError: if server_def is None.
    """
        if not server_def:
            raise ValueError("server_def is None.")
        if not self._context_handle:
            self._server_def = server_def
        else:
            server_def_str = server_def.SerializeToString()
            pywrap_tensorflow.TFE_ContextSetServerDef(self._context_handle,
                                                      server_def_str)

            # Clear all the caches in case there are remote tensors in them.
            self._clear_caches()

            self._initialize_devices()