Merge pull request #13503 from dantkz/unstack_int64

Unstack int64 tensors on GPU
This commit is contained in:
Yifei Feng 2017-12-19 16:52:33 -08:00 committed by GitHub
commit ccb687421b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 9 deletions

View File

@ -154,6 +154,12 @@ REGISTER_KERNEL_BUILDER(Name("Unpack")
.HostMemory("output")
.TypeConstraint<int32>("T"),
UnpackOp<CPUDevice, int32>);
REGISTER_KERNEL_BUILDER(Name("Unpack")
.Device(DEVICE_GPU)
.HostMemory("value")
.HostMemory("output")
.TypeConstraint<int64>("T"),
UnpackOp<CPUDevice, int64>);
#endif // GOOGLE_CUDA
@ -171,6 +177,13 @@ REGISTER_KERNEL_BUILDER(Name("Unpack")
.HostMemory("output")
.TypeConstraint<int32>("T"),
UnpackOp<CPUDevice, int32>);
REGISTER_KERNEL_BUILDER(Name("Unpack")
.Device(DEVICE_SYCL)
.HostMemory("value")
.HostMemory("output")
.TypeConstraint<int64>("T"),
UnpackOp<CPUDevice, int64>);
#undef REGISTER_SYCL
#endif // TENSORFLOW_USE_SYCL

View File

@ -22,6 +22,7 @@ import numpy as np
from six.moves import xrange # pylint: disable=redefined-builtin
from tensorflow.python.framework import constant_op
from tensorflow.python.framework import test_util
from tensorflow.python.ops import array_ops
from tensorflow.python.ops import gradient_checker
from tensorflow.python.platform import test
@ -42,15 +43,33 @@ class UnstackOpTest(test.TestCase):
np.random.seed(7)
with self.test_session(use_gpu=True):
for shape in (2,), (3,), (2, 3), (3, 2), (4, 3, 2):
data = np.random.randn(*shape)
# Convert data to a single tensorflow tensor
x = constant_op.constant(data)
# Unpack into a list of tensors
cs = array_ops.unstack(x, num=shape[0])
self.assertEqual(type(cs), list)
self.assertEqual(len(cs), shape[0])
cs = [c.eval() for c in cs]
self.assertAllEqual(cs, data)
for dtype in [np.bool, np.float16, np.float32, np.float64, np.int32, np.int64]:
data = np.random.randn(*shape).astype(dtype)
# Convert data to a single tensorflow tensor
x = constant_op.constant(data)
# Unpack into a list of tensors
cs = array_ops.unstack(x, num=shape[0])
self.assertEqual(type(cs), list)
self.assertEqual(len(cs), shape[0])
cs = [c.eval() for c in cs]
self.assertAllEqual(cs, data)
def testSimpleGpu(self):
if not test_util.is_gpu_available():
self.skipTest("No GPU available")
np.random.seed(7)
with self.test_session(use_gpu=True, force_gpu=True):
for shape in (2,), (3,), (2, 3), (3, 2), (4, 3, 2):
for dtype in [np.float16, np.float32, np.float64, np.int32, np.int64]:
data = np.random.randn(*shape).astype(dtype)
# Convert data to a single tensorflow tensor
x = constant_op.constant(data)
# Unpack into a list of tensors
cs = array_ops.unstack(x, num=shape[0])
self.assertEqual(type(cs), list)
self.assertEqual(len(cs), shape[0])
cs = [c.eval() for c in cs]
self.assertAllEqual(cs, data)
def testGradientsAxis0(self):
for shape in (2,), (3,), (2, 3), (3, 2), (4, 3, 2):