Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GPU: Add Complex kernel for tf.exp() #15182

Merged
merged 2 commits into from
Dec 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion tensorflow/core/kernels/cwise_op_exp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ REGISTER5(UnaryOp, CPU, "Exp", functor::exp, float, Eigen::half, double,
complex64, complex128);

#if GOOGLE_CUDA
REGISTER3(UnaryOp, GPU, "Exp", functor::exp, float, Eigen::half, double);
REGISTER5(UnaryOp, GPU, "Exp", functor::exp, float, Eigen::half, double,
complex64, complex128);
#endif

#if TENSORFLOW_USE_SYCL
Expand Down
2 changes: 1 addition & 1 deletion tensorflow/core/kernels/cwise_op_gpu_exp.cu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ limitations under the License.

namespace tensorflow {
namespace functor {
DEFINE_UNARY3(exp, Eigen::half, float, double);
DEFINE_UNARY5(exp, Eigen::half, float, double, complex64, complex128);
} // namespace functor
} // namespace tensorflow

Expand Down
19 changes: 19 additions & 0 deletions tensorflow/core/kernels/cwise_ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,25 @@ limitations under the License.
#include "tensorflow/core/kernels/bounds_check.h"

namespace Eigen {
namespace numext {
#if GOOGLE_CUDA
template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
std::complex<float> exp(const std::complex<float> &x) {
auto com = ::expf(x.real());
auto res_real = com * ::cosf(x.imag());
auto res_imag = com * ::sinf(x.imag());
return std::complex<float>(res_real, res_imag);
}
template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
std::complex<double> exp(const std::complex<double> &x) {
auto com = ::exp(x.real());
auto res_real = com * ::cos(x.imag());
auto res_imag = com * ::sin(x.imag());
return std::complex<double>(res_real, res_imag);
}
#endif
}

namespace internal {

// TODO(rmlarsen): Get rid of fmod2 once fmod is upstreamed to Eigen.
Expand Down
4 changes: 2 additions & 2 deletions tensorflow/python/kernel_tests/cwise_ops_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ def testComplex64Basic(self):
self._compareCpu(x, np.square, math_ops.square)
self._compareCpu(y, np.sqrt, math_ops.sqrt)
self._compareCpu(y, self._rsqrt, math_ops.rsqrt)
self._compareCpu(x, np.exp, math_ops.exp)
self._compareBoth(x, np.exp, math_ops.exp)
self._compareCpu(x, np.expm1, math_ops.expm1)
self._compareCpu(y, np.log, math_ops.log)
self._compareCpu(y, np.log1p, math_ops.log1p)
Expand Down Expand Up @@ -460,7 +460,7 @@ def testComplex128Basic(self):
self._compareCpu(x, np.square, math_ops.square)
self._compareCpu(y, np.sqrt, math_ops.sqrt)
self._compareCpu(y, self._rsqrt, math_ops.rsqrt)
self._compareCpu(x, np.exp, math_ops.exp)
self._compareBoth(x, np.exp, math_ops.exp)
self._compareCpu(x, np.expm1, math_ops.expm1)
self._compareCpu(y, np.log, math_ops.log)
self._compareCpu(y, np.log1p, math_ops.log1p)
Expand Down