You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

exp.h 2.7 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /**
  2. * \file dnn/src/fallback/elemwise_helper/kimpl/exp.h
  3. */
  4. #pragma once
  5. #include "src/fallback/elemwise_helper/kimpl/op_base.h"
  6. namespace megdnn {
  7. namespace fallback {
  8. template <typename src_ctype, typename dst_ctype = src_ctype>
  9. struct ExpOpBase : UnaryOpBase<src_ctype, dst_ctype> {
  10. using UnaryOpBase<src_ctype, dst_ctype>::UnaryOpBase;
  11. void operator()(const src_ctype& src, dst_ctype* dst) const {
  12. *dst = operator()(src);
  13. }
  14. dst_ctype operator()(const src_ctype& src) const {
  15. float tmp = src;
  16. return exp(tmp);
  17. }
  18. };
  19. template <typename src_ctype, typename dst_ctype = src_ctype>
  20. struct ExpOp;
  21. #define OP(_ctype, _simd_type, _func_suffix, _simd_width) \
  22. template <> \
  23. struct ExpOp<_ctype> : ExpOpBase<_ctype> { \
  24. using ExpOpBase::ExpOpBase; \
  25. using ExpOpBase::operator(); \
  26. constexpr static size_t SIMD_WIDTH = _simd_width; \
  27. void operator()(const _simd_type& src, _ctype* dst) const { \
  28. auto vitem = operator()(src); \
  29. GiStore##_func_suffix(dst, GiGetSubVector##_func_suffix##V2(vitem, 0)); \
  30. GiStore##_func_suffix( \
  31. dst + SIMD_WIDTH, GiGetSubVector##_func_suffix##V2(vitem, 1)); \
  32. } \
  33. _simd_type operator()(const _simd_type& src) const { \
  34. auto vitem0 = \
  35. GiExpPs##_func_suffix(GiGetSubVector##_func_suffix##V2(src, 0)); \
  36. auto vitem1 = \
  37. GiExpPs##_func_suffix(GiGetSubVector##_func_suffix##V2(src, 1)); \
  38. _simd_type ret; \
  39. GiSetSubVector##_func_suffix##V2(ret, 0, vitem0); \
  40. GiSetSubVector##_func_suffix##V2(ret, 1, vitem1); \
  41. return ret; \
  42. } \
  43. };
  44. OP(dt_float32, GI_FLOAT32_V2_t, Float32, GI_SIMD_LEN_BYTE / sizeof(float))
  45. #undef OP
  46. } // namespace fallback
  47. } // namespace megdnn
  48. // vim: syntax=cpp.doxygen