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.

nn_int.h 2.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #pragma once
  2. #include "megdnn/internal/opr_header_prologue.h"
  3. namespace megdnn {
  4. /*!
  5. * \brief element-wise operator that allows input/output vars to have different
  6. * data types
  7. *
  8. * The data types are typically different int types.
  9. */
  10. class ElemwiseMultiType : public OperatorBase {
  11. DEF_OPR_PARAM(ElemwiseMultiType);
  12. DEF_OPR_IMPL(ElemwiseMultiType, OperatorBase, -1, 1);
  13. //! check dtype function
  14. using CheckDtypeFunc = thin_function<void(const DType)>;
  15. //! check the dtype if is_check is true, otherwise setup dtype.
  16. using SetOrCheckDtypeFunc = thin_function<void(DType&, bool is_check)>;
  17. public:
  18. using Mode = Param::Mode;
  19. static constexpr size_t MAX_ARITY = 6;
  20. //! information about a mode
  21. struct ModeTrait {
  22. uint32_t arity = 0; //!< number of inputs needed
  23. CheckDtypeFunc check_inp[MAX_ARITY];
  24. SetOrCheckDtypeFunc check_out; //!< dtype of output var
  25. bool need_specify_out_dtype =
  26. false; //!< the dtype should be setup externally, otherwise
  27. //!< would be inferred by check_out(dtype, false)
  28. const char* name = nullptr; //!< name of the mode
  29. //! get trait from a mode; this function is thread safe
  30. MGE_WIN_DECLSPEC_FUC static const ModeTrait& from_mode(Mode mode);
  31. };
  32. virtual void exec(_megdnn_in const TensorNDArray& src, _megdnn_tensor_out dst) = 0;
  33. //! get trait of current mode
  34. const ModeTrait& mode_trait() const { return ModeTrait::from_mode(m_param.mode); }
  35. //! deduce output layout
  36. void deduce_layout(const TensorLayoutArray& src, TensorLayout& dst);
  37. protected:
  38. //! throw exception if incorrect layout; broadcast input shape to
  39. //! output shape
  40. void check_layout_and_broadcast(
  41. const TensorLayoutPtrArray& src, const TensorLayout& dst);
  42. };
  43. } // namespace megdnn
  44. #include "megdnn/internal/opr_header_epilogue.h"
  45. // vim: syntax=cpp.doxygen