Exemplo n.º 1
0
 def testInvalidDeviceNumber(self):
   opts = tf_session.TF_NewSessionOptions()
   c_session = tf_session.TF_NewSession(ops.get_default_graph()._c_graph, opts)
   raw_device_list = tf_session.TF_SessionListDevices(c_session)
   size = tf_session.TF_DeviceListCount(raw_device_list)
   with self.assertRaises(errors.InvalidArgumentError):
     tf_session.TF_DeviceListMemoryBytes(raw_device_list, size)
   tf_session.TF_DeleteDeviceList(raw_device_list)
   tf_session.TF_CloseSession(c_session)
Exemplo n.º 2
0
    def close(self):
        """Closes this session.

    Calling this method frees all resources associated with the session.

    Raises:
      RuntimeError: If an error occurs while closing the session.
    """
        with self._extend_lock:
            if self._opened and not self._closed:
                self._closed = True
                with errors.raise_exception_on_not_ok_status() as status:
                    tf_session.TF_CloseSession(self._session, status)
Exemplo n.º 3
0
 def testInvalidDeviceNumber(self):
     opts = tf_session.TF_NewSessionOptions()
     with errors.raise_exception_on_not_ok_status() as status:
         c_session = tf_session.TF_NewSession(
             ops.get_default_graph()._c_graph, opts, status)
         raw_device_list = tf_session.TF_SessionListDevices(
             c_session, status)
     size = tf_session.TF_DeviceListCount(raw_device_list)
     # Test that invalid device numbers return -1 rather than a Swig-wrapped
     # pointer.
     status_no_exception = c_api_util.ScopedTFStatus()
     memory = tf_session.TF_DeviceListMemoryBytes(raw_device_list, size,
                                                  status_no_exception)
     self.assertEqual(memory, -1)
     tf_session.TF_DeleteDeviceList(raw_device_list)
     with errors.raise_exception_on_not_ok_status() as status:
         tf_session.TF_CloseSession(c_session, status)
Exemplo n.º 4
0
    def close(self):
        """Closes this session.

    Calling this method frees all resources associated with the session.

    Raises:
      RuntimeError: If an error occurs while closing the session.
    """
        with self._extend_lock:
            if self._opened and not self._closed:
                self._closed = True
                try:
                    status = tf_session.TF_NewStatus()
                    tf_session.TF_CloseSession(self._session, status)
                    if tf_session.TF_GetCode(status) != 0:
                        raise RuntimeError(tf_session.TF_Message(status))
                finally:
                    tf_session.TF_DeleteStatus(status)