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.3 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /**
  2. * \file dnn/include/megdnn/oprs/nn_int.h
  3. * MegEngine is Licensed under the Apache License, Version 2.0 (the "License")
  4. *
  5. * Copyright (c) 2014-2021 Megvii Inc. All rights reserved.
  6. *
  7. * Unless required by applicable law or agreed to in writing,
  8. * software distributed under the License is distributed on an
  9. * "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. */
  11. #pragma once
  12. #include "megdnn/internal/opr_header_prologue.h"
  13. namespace megdnn {
  14. /*!
  15. * \brief element-wise operator that allows input/output vars to have different
  16. * data types
  17. *
  18. * The data types are typically different int types.
  19. */
  20. class ElemwiseMultiType : public OperatorBase {
  21. DEF_OPR_PARAM(ElemwiseMultiType);
  22. DEF_OPR_IMPL(ElemwiseMultiType, OperatorBase, -1, 1);
  23. //! check dtype function
  24. using CheckDtypeFunc = thin_function<void(const DType)>;
  25. //! check the dtype if is_check is true, otherwise setup dtype.
  26. using SetOrCheckDtypeFunc = thin_function<void(DType&, bool is_check)>;
  27. public:
  28. using Mode = Param::Mode;
  29. static constexpr size_t MAX_ARITY = 6;
  30. //! information about a mode
  31. struct ModeTrait {
  32. uint32_t arity = 0; //!< number of inputs needed
  33. CheckDtypeFunc check_inp[MAX_ARITY];
  34. SetOrCheckDtypeFunc check_out; //!< dtype of output var
  35. bool need_specify_out_dtype =
  36. false; //!< the dtype should be setup externally, otherwise
  37. //!< would be inferred by check_out(dtype, false)
  38. const char* name = nullptr; //!< name of the mode
  39. //! get trait from a mode; this function is thread safe
  40. static const ModeTrait& from_mode(Mode mode);
  41. };
  42. virtual void exec(_megdnn_in const TensorNDArray& src, _megdnn_tensor_out dst) = 0;
  43. //! get trait of current mode
  44. const ModeTrait& mode_trait() const { return ModeTrait::from_mode(m_param.mode); }
  45. //! deduce output layout
  46. void deduce_layout(const TensorLayoutArray& src, TensorLayout& dst);
  47. protected:
  48. //! throw exception if incorrect layout; broadcast input shape to
  49. //! output shape
  50. void check_layout_and_broadcast(
  51. const TensorLayoutPtrArray& src, const TensorLayout& dst);
  52. };
  53. } // namespace megdnn
  54. #include "megdnn/internal/opr_header_epilogue.h"
  55. // vim: syntax=cpp.doxygen

MegEngine 安装包中集成了使用 GPU 运行代码所需的 CUDA 环境,不用区分 CPU 和 GPU 版。 如果想要运行 GPU 程序,请确保机器本身配有 GPU 硬件设备并安装好驱动。 如果你想体验在云端 GPU 算力平台进行深度学习开发的感觉,欢迎访问 MegStudio 平台