0
votes

I'm trying to get TensorFlow's random_poisson function to run on my GPU; given that this TensorFlow source page has a function testCPUGPUMatch that compares the outputs of random_poisson when run on the CPU and on the GPU, it seems like it should be possible. However, when testing with the code:

import tensorflow as tf

with tf.Session() as sess:
    with tf.device("/gpu:0"):
        test = sess.run(tf.random_poisson(1.0, [], dtype=tf.float64))
print(test)

I get the error:

InvalidArgumentError: Cannot assign a device for operation 'random_poisson/RandomPoissonV2': Could not satisfy explicit device specification '/device:GPU:0' because no supported kernel for GPU devices is available. Registered kernels: device='CPU'; R in [DT_INT64]; dtype in [DT_INT64] device='CPU'; R in [DT_INT64]; dtype in [DT_INT32] device='CPU'; R in [DT_INT64]; dtype in [DT_DOUBLE]
device='CPU'; R in [DT_INT64]; dtype in [DT_FLOAT] device='CPU'; R in [DT_INT64]; dtype in [DT_HALF] device='CPU'; R in [DT_INT32]; dtype in [DT_INT64] device='CPU'; R in [DT_INT32]; dtype in [DT_INT32] device='CPU'; R in [DT_INT32]; dtype in [DT_DOUBLE]
device='CPU'; R in [DT_INT32]; dtype in [DT_FLOAT] device='CPU'; R in [DT_INT32]; dtype in [DT_HALF] device='CPU'; R in [DT_DOUBLE]; dtype in [DT_INT64] device='CPU'; R in [DT_DOUBLE]; dtype in [DT_INT32] device='CPU'; R in [DT_DOUBLE]; dtype in [DT_DOUBLE]
device='CPU'; R in [DT_DOUBLE]; dtype in [DT_FLOAT] device='CPU'; R in [DT_DOUBLE]; dtype in [DT_HALF] device='CPU'; R in [DT_FLOAT]; dtype in [DT_INT64] device='CPU'; R in [DT_FLOAT]; dtype in [DT_INT32] device='CPU'; R in [DT_FLOAT]; dtype in [DT_DOUBLE]
device='CPU'; R in [DT_FLOAT]; dtype in [DT_FLOAT] device='CPU'; R in [DT_FLOAT]; dtype in [DT_HALF] device='CPU'; R in [DT_HALF]; dtype in [DT_INT64] device='CPU'; R in [DT_HALF]; dtype in [DT_INT32] device='CPU'; R in [DT_HALF]; dtype in [DT_DOUBLE]
device='CPU'; R in [DT_HALF]; dtype in [DT_FLOAT] device='CPU'; R in [DT_HALF]; dtype in [DT_HALF]

[[Node: random_poisson/RandomPoissonV2 = RandomPoissonV2[R=DT_DOUBLE, S=DT_INT32, dtype=DT_DOUBLE, seed=0, seed2=0, _device="/device:GPU:0"](random_poisson/shape, random_poisson/RandomPoissonV2/rate)]]

which lists no registered GPU kernels. The code behaves as expected when run on my CPU, as does similar code with uniform_random when run on my GPU. Am I somehow missing the GPU kernel for random_poisson? Does one not exist, even though the linked source page implies that one does? And if one does not exist, is there an implementation that runs on the GPU? This is currently the bottleneck in a fairly complicated model I've implemented, so it'd be nice to get it fixed. I'm running version 1.8.0 of TensorFlow (installed from pip) on Python 3.6.4 on Arch Linux, with CUDA version 9.0 and cuDNN version 7.0 on a GeForce GTX 1050.

Thanks!

2

2 Answers

1
votes

There is no GPU kernel for random poisson. In random_poisson_op.cc, only the CPU kernel is registered.

If you look at the testCPUGPUMatch code that you linked, it invokes self.test_session(use_gpu=True, ...), which tries to run ops on GPU if possible. Under the hood, test_session uses allow_soft_placement to do this, which falls back to CPU if it is not possible to run an op on GPU. So the test actually runs the op on CPU.

[Aside: Why do we have a test that doesn't really do anything? It appears that testCPUGPUMatch is a test for many different random ops (see test_random_ops.py), and the implementer of RandomPoisson may have added it for that reason. It seems like it would be better named testCPUGPUMatchIfGPUImplementationExists...]

Feel free to submit a feature request for a GPU kernel via a github issue, or submit a PR with an implementation.

0
votes
import tensorflow as tf
config = tf.ConfigProto(allow_soft_placement=True)

with tf.Session(config=config) as sess:
    with tf.device("/gpu:0"):
        test = sess.run(tf.random_poisson(1.0, [], dtype=tf.float64))
print(test)