From 881de45c2d3b28db099821bf37488a04c3888f94 Mon Sep 17 00:00:00 2001 From: Taehoon Lee Date: Fri, 11 Aug 2017 13:00:12 +0900 Subject: [PATCH] Add bool type supports for GPU kernels (#11927) * Add bool type supports for GPU kernels * Add bool type test codes for GPU kernels --- tensorflow/core/kernels/concat_lib_gpu.cc | 1 + tensorflow/core/kernels/concat_lib_gpu_impl.cu.cc | 4 ++++ tensorflow/core/kernels/concat_op.cc | 1 + tensorflow/core/kernels/pack_op.cc | 1 + tensorflow/core/kernels/reshape_op.cc | 1 + tensorflow/python/kernel_tests/concat_op_test.py | 1 + tensorflow/python/kernel_tests/reshape_op_test.py | 4 ++++ tensorflow/python/kernel_tests/stack_op_test.py | 4 ++-- 8 files changed, 15 insertions(+), 2 deletions(-) diff --git a/tensorflow/core/kernels/concat_lib_gpu.cc b/tensorflow/core/kernels/concat_lib_gpu.cc index 5159cdaa6ec..319ead49efd 100644 --- a/tensorflow/core/kernels/concat_lib_gpu.cc +++ b/tensorflow/core/kernels/concat_lib_gpu.cc @@ -117,6 +117,7 @@ TF_CALL_complex64(REGISTER); TF_CALL_complex128(REGISTER); TF_CALL_int64(REGISTER); REGISTER(bfloat16); +REGISTER(bool); #undef REGISTER diff --git a/tensorflow/core/kernels/concat_lib_gpu_impl.cu.cc b/tensorflow/core/kernels/concat_lib_gpu_impl.cu.cc index f971637d5db..0f7adaf24a8 100644 --- a/tensorflow/core/kernels/concat_lib_gpu_impl.cu.cc +++ b/tensorflow/core/kernels/concat_lib_gpu_impl.cu.cc @@ -203,24 +203,28 @@ TF_CALL_complex64(REGISTER_GPUCONCAT32); TF_CALL_complex128(REGISTER_GPUCONCAT32); TF_CALL_int64(REGISTER_GPUCONCAT32); REGISTER_GPUCONCAT32(bfloat16); +REGISTER_GPUCONCAT32(bool); TF_CALL_GPU_NUMBER_TYPES(REGISTER_GPUCONCAT64); TF_CALL_complex64(REGISTER_GPUCONCAT64); TF_CALL_complex128(REGISTER_GPUCONCAT64); TF_CALL_int64(REGISTER_GPUCONCAT64); REGISTER_GPUCONCAT64(bfloat16); +REGISTER_GPUCONCAT64(bool); TF_CALL_GPU_NUMBER_TYPES(REGISTER_GPU32); TF_CALL_complex64(REGISTER_GPU32); TF_CALL_complex128(REGISTER_GPU32); TF_CALL_int64(REGISTER_GPU32); REGISTER_GPU32(bfloat16); +REGISTER_GPU32(bool); TF_CALL_GPU_NUMBER_TYPES(REGISTER_GPU64); TF_CALL_complex64(REGISTER_GPU64); TF_CALL_complex128(REGISTER_GPU64); TF_CALL_int64(REGISTER_GPU64); REGISTER_GPU64(bfloat16); +REGISTER_GPU64(bool); #undef REGISTER_GPUCONCAT32 #undef REGISTER_GPUCONCAT64 diff --git a/tensorflow/core/kernels/concat_op.cc b/tensorflow/core/kernels/concat_op.cc index 01a744dc7ec..8e480aa9952 100644 --- a/tensorflow/core/kernels/concat_op.cc +++ b/tensorflow/core/kernels/concat_op.cc @@ -196,6 +196,7 @@ REGISTER_GPU(bfloat16); TF_CALL_complex64(REGISTER_GPU); TF_CALL_complex128(REGISTER_GPU); TF_CALL_int64(REGISTER_GPU); +REGISTER_GPU(bool); #undef REGISTER_GPU // A special GPU kernel for int32. diff --git a/tensorflow/core/kernels/pack_op.cc b/tensorflow/core/kernels/pack_op.cc index 75820e3106f..814128d99ac 100644 --- a/tensorflow/core/kernels/pack_op.cc +++ b/tensorflow/core/kernels/pack_op.cc @@ -158,6 +158,7 @@ REGISTER_PACK(string); TF_CALL_GPU_NUMBER_TYPES(REGISTER_GPU); TF_CALL_int64(REGISTER_GPU); +REGISTER_GPU(bool); #undef REGISTER_GPU // A special GPU kernel for int32. diff --git a/tensorflow/core/kernels/reshape_op.cc b/tensorflow/core/kernels/reshape_op.cc index 04454b76c1a..16db8a6bb13 100644 --- a/tensorflow/core/kernels/reshape_op.cc +++ b/tensorflow/core/kernels/reshape_op.cc @@ -32,6 +32,7 @@ REGISTER_KERNEL_BUILDER(Name("Reshape") .TypeConstraint("Tshape"), \ ReshapeOp); TF_CALL_NUMBER_TYPES_NO_INT32(REGISTER_GPU_KERNEL); +REGISTER_GPU_KERNEL(bool); #undef REGISTER_GPU_KERNEL #ifdef TENSORFLOW_USE_SYCL diff --git a/tensorflow/python/kernel_tests/concat_op_test.py b/tensorflow/python/kernel_tests/concat_op_test.py index aba4224dc62..a5fd3bc3345 100644 --- a/tensorflow/python/kernel_tests/concat_op_test.py +++ b/tensorflow/python/kernel_tests/concat_op_test.py @@ -138,6 +138,7 @@ class ConcatOpTest(test.TestCase): self.assertAllClose(result[ind], params[p[i]], 0.01) def testRandom(self): + self._testRandom(dtypes.bool) self._testRandom(dtypes.float32) self._testRandom(dtypes.int16) self._testRandom(dtypes.int32) diff --git a/tensorflow/python/kernel_tests/reshape_op_test.py b/tensorflow/python/kernel_tests/reshape_op_test.py index 67aeb67d8dd..9d6e7e60a4b 100644 --- a/tensorflow/python/kernel_tests/reshape_op_test.py +++ b/tensorflow/python/kernel_tests/reshape_op_test.py @@ -41,6 +41,10 @@ class ReshapeTest(test.TestCase): self._testReshape(x, y, False) self._testReshape(x, y, True) + def testBoolBasic(self): + x = np.arange(1., 7.).reshape([1, 6]) > 3 + self._testBothReshape(x, [2, 3]) + def testFloatBasic(self): x = np.arange(1., 7.).reshape([1, 6]).astype(np.float32) self._testBothReshape(x, [2, 3]) diff --git a/tensorflow/python/kernel_tests/stack_op_test.py b/tensorflow/python/kernel_tests/stack_op_test.py index 95ea3a90473..8e1f3eda7cd 100644 --- a/tensorflow/python/kernel_tests/stack_op_test.py +++ b/tensorflow/python/kernel_tests/stack_op_test.py @@ -45,7 +45,7 @@ class StackOpTest(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): - for dtype in [np.float32, np.int32, np.int64]: + for dtype in [np.bool, np.float32, np.int32, np.int64]: data = np.random.randn(*shape).astype(dtype) # Convert [data[0], data[1], ...] separately to tensorflow # TODO(irving): Remove list() once we handle maps correctly @@ -67,7 +67,7 @@ class StackOpTest(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): - for dtype in [np.float32, np.int32, np.int64]: + for dtype in [np.bool, np.float32, np.int32, np.int64]: data = np.random.randn(*shape).astype(dtype) # Pack back into a single tensorflow tensor directly using np array c = array_ops.stack(data)