!25235 Add some docs for PrimitiveC , OpPrimCRegister and OpPrimCRegisterHelper in r1.5

Merge pull request !25235 from LiangZhibo/code_docs_core_r1.5
This commit is contained in:
i-robot 2021-10-21 06:59:37 +00:00 committed by Gitee
commit 0622fcd40b
1 changed files with 33 additions and 0 deletions

View File

@ -25,11 +25,22 @@
#include "ir/value.h"
namespace mindspore {
namespace ops {
/// \brief PrimitiveC defines the base class for end side operators.
class MS_CORE_API PrimitiveC : public Primitive {
public:
/// \brief Constructor for PrimitiveC.
///
/// \param[in] name The name of the end side operator.
explicit PrimitiveC(const std::string &name) : Primitive(name) {}
MS_DECLARE_PARENT(PrimitiveC, Primitive);
/// \brief Destructor of PrimitiveC.
~PrimitiveC() = default;
/// \brief Derive the abstract of the PrimitiveC object.
///
/// \param[in] abstract_list The abstract of the inputs of the PrimitiveC object.
/// \return The abstract of the PrimitiveC object.
AbstractBasePtr Infer(const AbstractBasePtrList &abstract_list);
protected:
@ -37,11 +48,26 @@ class MS_CORE_API PrimitiveC : public Primitive {
};
using OpPrimCDefineFunc = std::function<std::shared_ptr<PrimitiveC>()>;
/// \brief OpPrimCRegister defines the singleton to save the end side operators.
class MS_CORE_API OpPrimCRegister {
public:
/// \brief Destructor of OpPrimCRegister.
~OpPrimCRegister() {}
/// \brief Get the OpPrimCRegister singleton.
///
/// \return The OpPrimCRegister singleton.
static OpPrimCRegister &GetInstance();
/// \brief Get PrimCMap of the OpPrimCRegister singleton.
///
/// \return The PrimCMap of the OpPrimCRegister singleton.
std::map<std::string, OpPrimCDefineFunc> GetPrimCMap();
/// \brief Add an element into the PrimCMap of the OpPrimCRegister singleton.
///
/// param[in] kname The name of the input end side operator.
/// param[in] fn The input end side operator.
void SetPrimCMap(const std::string &kname, const OpPrimCDefineFunc &fn);
private:
@ -49,11 +75,18 @@ class MS_CORE_API OpPrimCRegister {
std::map<std::string, OpPrimCDefineFunc> op_primc_fns_;
};
/// \brief OpPrimCRegisterHelper defines the helper class for the OpPrimCRegister singleton.
class MS_CORE_API OpPrimCRegisterHelper {
public:
/// \brief Constructor for OpPrimCRegisterHelper.
///
/// param[in] kname The name of the input end side operator.
/// param[in] fn The input end side operator.
OpPrimCRegisterHelper(const std::string &kname, const OpPrimCDefineFunc &fn) {
OpPrimCRegister::GetInstance().SetPrimCMap(kname, fn);
}
/// Destructor of OpPrimCRegisterHelper.
~OpPrimCRegisterHelper() = default;
private: