! * \brief configuration for operator nodes */
| 20 | * \brief configuration for operator nodes |
| 21 | */ |
| 22 | class OperatorNodeConfig final : public Hashable { |
| 23 | MGB_DYN_TYPE_OBJ_FINAL_DECL_WITH_EXPORT; |
| 24 | |
| 25 | public: |
| 26 | using CompNodeArray = SmallVector<CompNode, 1>; |
| 27 | |
| 28 | OperatorNodeConfig() = default; |
| 29 | MGE_WIN_DECLSPEC_FUC ~OperatorNodeConfig(); |
| 30 | |
| 31 | OperatorNodeConfig(std::string name) : m_name{std::move(name)} {} |
| 32 | |
| 33 | OperatorNodeConfig(const CompNode& cn) { comp_node(cn); } |
| 34 | |
| 35 | OperatorNodeConfig(std::string name, const CompNode& cn, DType dtype = {}) |
| 36 | : m_name{std::move(name)}, m_output_dtype{dtype} { |
| 37 | comp_node(cn); |
| 38 | } |
| 39 | |
| 40 | explicit OperatorNodeConfig(DType dtype) : m_output_dtype{dtype} {}; |
| 41 | |
| 42 | /*! |
| 43 | * \brief make a name according to default name and input vars |
| 44 | */ |
| 45 | std::string make_name( |
| 46 | std::string default_name, const VarNodeArrayView& input_var, |
| 47 | size_t opr_id) const; |
| 48 | |
| 49 | /*! |
| 50 | * \brief set node name |
| 51 | */ |
| 52 | OperatorNodeConfig& name(std::string name) { |
| 53 | m_name = std::move(name); |
| 54 | return *this; |
| 55 | } |
| 56 | |
| 57 | const Maybe<std::string>& name() const { return m_name; } |
| 58 | |
| 59 | /*! |
| 60 | * \brief update instance ID |
| 61 | * |
| 62 | * Instance ID is a hashed value used to differentiate multiple |
| 63 | * instances of the same operator (with same inputs, params and |
| 64 | * config), so the deduplication system can be bypassed. |
| 65 | * |
| 66 | * This method always updates underlying instance_id. |
| 67 | */ |
| 68 | template <typename T> |
| 69 | OperatorNodeConfig& update_instance_id(const T& p) { |
| 70 | static_assert( |
| 71 | std::is_pointer<T>::value, |
| 72 | "update_instance_id can only accept a pointer"); |
| 73 | m_instance_id_hashed = hash_pair_combine(m_instance_id_hashed, mgb::hash(p)); |
| 74 | return *this; |
| 75 | } |
| 76 | |
| 77 | /*! |
| 78 | * \brief reset instance ID to the initial value |
| 79 | */ |