title: TensorFlow nullptr check failed on GPU
body: <p>I am using the python API of TensorFlow to train a variant of an LSTM.
  For that purpose I use the <code>tf.while_loop</code> function to iterate over the time steps.</p>
  
  <p>When running my script on the cpu, it does not produce any error messages, but on the gpu python crashes due to:</p>
  
  <p><code>...tensorflow/tensorflow/core/framework/tensor.cc:885] Check failed: nullptr != b.buf_ (nullptr vs. 00...)</code></p>
  
  <p>The part of my code, that causes this failure (when commenting it out, it works) is in the body of the while loop:</p>
  
  <pre><code>...
  h_gathered = h_ta.gather(tf.range(time))
  h_gathered = tf.transpose(h_gathered, [1, 0, 2])
  syn_t = self.syntactic_weights_ta.read(time)[:, :time]
  syn_t = tf.expand_dims(syn_t, 1)
  syn_state_t = tf.squeeze(tf.tanh(tf.matmul(syn_t, h_gathered)), 1)
  ...
  </code></pre>
  
  <p>where <code>time</code> is zero based and incremented after each step, <code>h_ta</code> is a TensorArray</p>
  
  <pre><code>h_ta = tf.TensorArray(
          dtype=dtype,
          size=max_seq_len,
          clear_after_read=False,
          element_shape=[batch_size, num_hidden],
          tensor_array_name="fw_output")
  </code></pre>
  
  <p>and <code>self.syntactic_weights_ta</code> is also a TensorArray</p>
  
  <pre><code>self.syntactic_weights_ta = tf.TensorArray(
          dtype=dtype,
          size=max_seq_len,
          tensor_array_name="fw_syntactic_weights")
  self.syntactic_weights_ta = self.syntactic_weights_ta.unstack(syntactic_weights)
  </code></pre>
  
  <p>What I am trying to achieve in the code snippet is basically a weighted sum over the past outputs, stored in <code>h_ta</code>.
  In the end I train the network with <code>tf.train.AdamOptimizer</code>.</p>
  
  <p>I have tested the script again, but this time with <code>swap_memory</code> parameter in the while loop set to <code>False</code> and it works on GPU as well, though I'd really like to know why it does not work with <code>swap_memory=True</code>.</p>