From 1eb6355182a5124639ce9d3ff165732a94ed9a70 Mon Sep 17 00:00:00 2001 From: Bing Xu Date: Sat, 2 Jul 2022 05:00:45 -0700 Subject: [PATCH] [activation] tanh (#550) Co-authored-by: Bing Xu --- include/cutlass/epilogue/thread/activation.h | 37 ++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/include/cutlass/epilogue/thread/activation.h b/include/cutlass/epilogue/thread/activation.h index ca1f72c2..9763f5fc 100644 --- a/include/cutlass/epilogue/thread/activation.h +++ b/include/cutlass/epilogue/thread/activation.h @@ -98,6 +98,43 @@ struct ReLu> { } }; +// Tanh operator +template +struct Tanh { + CUTLASS_HOST_DEVICE + T operator()(T const &scalar) const { + return fast_tanh(scalar); + } +}; + +template +struct Tanh > { + CUTLASS_HOST_DEVICE + Array operator()(Array const &rhs) const { + Array y; + Tanh tanh_op; + + CUTLASS_PRAGMA_UNROLL + for (int i = 0; i < N; ++i) { + y[i] = tanh_op(rhs[i]); + } + + return y; + } +}; + +template +struct Tanh> { + using T = half_t; + + CUTLASS_HOST_DEVICE + Array operator()(Array const& z) const { + fast_tanh_op> tanh; + return tanh(z); + + } +}; + // Leaky Relu operator template struct LeakyReLU {