Skip to content

Commit

Permalink
Register GPU device OpKernel for Mod, for int32 type.
Browse files Browse the repository at this point in the history
Change: 123160537
  • Loading branch information
keveman authored and tensorflower-gardener committed May 24, 2016
1 parent ae5c66e commit 249106f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tensorflow/core/kernels/cwise_op_mod.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,17 @@ limitations under the License.
namespace tensorflow {
REGISTER2(BinaryOp, CPU, "Mod", functor::safe_mod, int32, int64);
REGISTER2(BinaryOp, CPU, "Mod", functor::fmod, float, double);

#if GOOGLE_CUDA
// A special GPU kernel for int32.
// TODO(b/25387198): Also enable int32 in device memory. This kernel
// registration requires all int32 inputs and outputs to be in host memory.
REGISTER_KERNEL_BUILDER(Name("Mod")
.Device(DEVICE_GPU)
.HostMemory("x")
.HostMemory("y")
.HostMemory("z")
.TypeConstraint<int32>("T"),
BinaryOp<CPUDevice, functor::safe_mod<int32>>);
#endif
} // namespace tensorflow
3 changes: 3 additions & 0 deletions tensorflow/python/kernel_tests/cwise_ops_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,9 @@ def testInt32Basic(self):
self._compareBoth(x, y, np.true_divide, _TRUEDIV)
self._compareBoth(x, y, np.floor_divide, _FLOORDIV)
self._compareBoth(x, y, np.mod, _MOD)
# _compareBoth tests on GPU only for floating point types, so test
# _MOD for int32 on GPU by calling _compareGpu
self._compareGpu(x, y, np.mod, _MOD)

def testInt64Basic(self):
x = np.arange(1 << 40, 13 << 40, 2 << 40).reshape(1, 3, 2).astype(np.int64)
Expand Down

0 comments on commit 249106f

Please sign in to comment.