| @@ -79,61 +79,65 @@ OpSchema &OpSchema::Attr(const Attribute &attr) { | |||||
| #endif | #endif | ||||
| #if defined(CFG_BUILD_DEBUG) | #if defined(CFG_BUILD_DEBUG) | ||||
| #define ATTR_SETTER_WITH_LIST_VALUE(Type, field, attrtype) \ | |||||
| OpSchema &OpSchema::Attr(const std::string &name, AttributeType attr_type, const std::vector<Type> &default_value) { \ | |||||
| if (attrtype != attr_type) { \ | |||||
| REPORT_INNER_ERROR("E19999", "Attribute specification vector param_type mismatch, " \ | |||||
| "input attr type %u, required attr type %u.", (uint32_t)attr_type, (uint32_t)attrtype); \ | |||||
| GELOGE(FAILED, "[Check][Param]Attribute specification vector param_type mismatch, " \ | |||||
| "input attr type %u, required attr type %u.", (uint32_t)attr_type, (uint32_t)attrtype); \ | |||||
| return *this; \ | |||||
| } \ | |||||
| domi::AttrDef vec_a; \ | |||||
| for (const auto &v : default_value) { \ | |||||
| vec_a.mutable_list()->add_##field(v); \ | |||||
| } \ | |||||
| Attr(Attribute(name, attr_type, vec_a)); \ | |||||
| return *this; \ | |||||
| } \ | |||||
| OpSchema &OpSchema::Attr(const std::string &name, AttributeType attr_type, const Tuple<Type> &default_value) { \ | |||||
| if (attrtype != attr_type) { \ | |||||
| REPORT_INNER_ERROR("E19999", "Attribute specification vector param_type mismatch, " \ | |||||
| "input attr type %u, required attr type %u.", (uint32_t)attr_type, (uint32_t)attrtype); \ | |||||
| GELOGE(FAILED, "[Check][Param]Attribute specification vector param_type mismatch, " \ | |||||
| "input attr type %u, required attr type %u.", (uint32_t)attr_type, (uint32_t)attrtype); \ | |||||
| return *this; \ | |||||
| } \ | |||||
| domi::AttrDef tuple_a; \ | |||||
| for (const auto &v : default_value) { \ | |||||
| tuple_a.mutable_list()->add_##field(v); \ | |||||
| } \ | |||||
| Attr(Attribute(name, attr_type, tuple_a)); \ | |||||
| return *this; \ | |||||
| } | |||||
| #define ATTR_SETTER_WITH_LIST_VALUE(Type, field, attrtype) \ | |||||
| do { \ | |||||
| OpSchema &OpSchema::Attr(const std::string &name, AttributeType attr_type, const std::vector<Type> &default_value) { \ | |||||
| if (attrtype != attr_type) { \ | |||||
| REPORT_INNER_ERROR("E19999", "Attribute specification vector param_type mismatch, " \ | |||||
| "input attr type %u, required attr type %u.", (uint32_t)attr_type, (uint32_t)attrtype); \ | |||||
| GELOGE(FAILED, "[Check][Param]Attribute specification vector param_type mismatch, " \ | |||||
| "input attr type %u, required attr type %u.", (uint32_t)attr_type, (uint32_t)attrtype); \ | |||||
| return *this; \ | |||||
| } \ | |||||
| domi::AttrDef vec_a; \ | |||||
| for (const auto &v : default_value) { \ | |||||
| vec_a.mutable_list()->add_##field(v); \ | |||||
| } \ | |||||
| Attr(Attribute(name, attr_type, vec_a)); \ | |||||
| return *this; \ | |||||
| } \ | |||||
| OpSchema &OpSchema::Attr(const std::string &name, AttributeType attr_type, const Tuple<Type> &default_value) { \ | |||||
| if (attrtype != attr_type) { \ | |||||
| REPORT_INNER_ERROR("E19999", "Attribute specification vector param_type mismatch, " \ | |||||
| "input attr type %u, required attr type %u.", (uint32_t)attr_type, (uint32_t)attrtype); \ | |||||
| GELOGE(FAILED, "[Check][Param]Attribute specification vector param_type mismatch, " \ | |||||
| "input attr type %u, required attr type %u.", (uint32_t)attr_type, (uint32_t)attrtype); \ | |||||
| return *this; \ | |||||
| } \ | |||||
| domi::AttrDef tuple_a; \ | |||||
| for (const auto &v : default_value) { \ | |||||
| tuple_a.mutable_list()->add_##field(v); \ | |||||
| } \ | |||||
| Attr(Attribute(name, attr_type, tuple_a)); \ | |||||
| return *this; \ | |||||
| } \ | |||||
| } while (0) | |||||
| #else | #else | ||||
| #define ATTR_SETTER_WITH_LIST_VALUE(Type, field, attrtype) \ | |||||
| OpSchema &OpSchema::Attr(const std::string &name, AttributeType attr_type, const std::vector<Type> &default_value) { \ | |||||
| if (attrtype != attr_type) { \ | |||||
| return *this; \ | |||||
| } \ | |||||
| domi::AttrDef vec_a; \ | |||||
| for (const auto &v : default_value) { \ | |||||
| vec_a.mutable_list()->add_##field(v); \ | |||||
| } \ | |||||
| Attr(Attribute(name, attr_type, vec_a)); \ | |||||
| return *this; \ | |||||
| } \ | |||||
| OpSchema &OpSchema::Attr(const std::string &name, AttributeType attr_type, const Tuple<Type> &default_value) { \ | |||||
| if (attrtype != attr_type) { \ | |||||
| return *this; \ | |||||
| } \ | |||||
| domi::AttrDef tuple_a; \ | |||||
| for (const auto &v : default_value) { \ | |||||
| tuple_a.mutable_list()->add_##field(v); \ | |||||
| } \ | |||||
| Attr(Attribute(name, attr_type, tuple_a)); \ | |||||
| return *this; \ | |||||
| } | |||||
| #define ATTR_SETTER_WITH_LIST_VALUE(Type, field, attrtype) \ | |||||
| do { \ | |||||
| OpSchema &OpSchema::Attr(const std::string &name, AttributeType attr_type, const std::vector<Type> &default_value) { \ | |||||
| if (attrtype != attr_type) { \ | |||||
| return *this; \ | |||||
| } \ | |||||
| domi::AttrDef vec_a; \ | |||||
| for (const auto &v : default_value) { \ | |||||
| vec_a.mutable_list()->add_##field(v); \ | |||||
| } \ | |||||
| Attr(Attribute(name, attr_type, vec_a)); \ | |||||
| return *this; \ | |||||
| } \ | |||||
| OpSchema &OpSchema::Attr(const std::string &name, AttributeType attr_type, const Tuple<Type> &default_value) { \ | |||||
| if (attrtype != attr_type) { \ | |||||
| return *this; \ | |||||
| } \ | |||||
| domi::AttrDef tuple_a; \ | |||||
| for (const auto &v : default_value) { \ | |||||
| tuple_a.mutable_list()->add_##field(v); \ | |||||
| } \ | |||||
| Attr(Attribute(name, attr_type, tuple_a)); \ | |||||
| return *this; \ | |||||
| } \ | |||||
| } while (0) | |||||
| #endif | #endif | ||||
| ATTR_SETTER_WITH_SINGLE_VALUE(uint32_t, u, AttributeType::UINT) | ATTR_SETTER_WITH_SINGLE_VALUE(uint32_t, u, AttributeType::UINT) | ||||
| @@ -121,25 +121,27 @@ ParserOperator &ParserOperator::Attr_bt(const std::string &name, const std::stri | |||||
| return *this; \ | return *this; \ | ||||
| } | } | ||||
| #define ATTR_SETTER_WITH_LIST_VALUE(type, field) \ | |||||
| ParserOperator &ParserOperator::Attr(const std::string &name, const std::vector<type> &value) { \ | |||||
| domi::AttrDef a; \ | |||||
| auto attr_list = a.mutable_list(); \ | |||||
| for (size_t i = 0; i < value.size(); ++i) { \ | |||||
| attr_list->add_##field(value[i]); \ | |||||
| } \ | |||||
| Attr(OpAttribute(name, a)); \ | |||||
| return *this; \ | |||||
| } \ | |||||
| ParserOperator &ParserOperator::Attr(const std::string &name, const ge::Tuple<type> &value) { \ | |||||
| domi::AttrDef a; \ | |||||
| auto attr_list = a.mutable_list(); \ | |||||
| for (uint32_t i = 0; i < value.ndim(); ++i) { \ | |||||
| attr_list->add_##field(value[i]); \ | |||||
| } \ | |||||
| Attr(OpAttribute(name, a)); \ | |||||
| return *this; \ | |||||
| } | |||||
| #define ATTR_SETTER_WITH_LIST_VALUE(type, field) \ | |||||
| do { \ | |||||
| ParserOperator &ParserOperator::Attr(const std::string &name, const std::vector<type> &value) { \ | |||||
| domi::AttrDef a; \ | |||||
| auto attr_list = a.mutable_list(); \ | |||||
| for (size_t i = 0; i < value.size(); ++i) { \ | |||||
| attr_list->add_##field(value[i]); \ | |||||
| } \ | |||||
| Attr(OpAttribute(name, a)); \ | |||||
| return *this; \ | |||||
| } \ | |||||
| ParserOperator &ParserOperator::Attr(const std::string &name, const ge::Tuple<type> &value) { \ | |||||
| domi::AttrDef a; \ | |||||
| auto attr_list = a.mutable_list(); \ | |||||
| for (uint32_t i = 0; i < value.ndim(); ++i) { \ | |||||
| attr_list->add_##field(value[i]); \ | |||||
| } \ | |||||
| Attr(OpAttribute(name, a)); \ | |||||
| return *this; \ | |||||
| } \ | |||||
| } while (0) | |||||
| ATTR_SETTER_WITH_SINGLE_VALUE(int64_t, i) | ATTR_SETTER_WITH_SINGLE_VALUE(int64_t, i) | ||||
| ATTR_SETTER_WITH_SINGLE_VALUE(bool, b) | ATTR_SETTER_WITH_SINGLE_VALUE(bool, b) | ||||
| @@ -153,44 +155,49 @@ ATTR_SETTER_WITH_LIST_VALUE(float, f) | |||||
| ATTR_SETTER_WITH_LIST_VALUE(std::string, s) | ATTR_SETTER_WITH_LIST_VALUE(std::string, s) | ||||
| ATTR_SETTER_WITH_LIST_VALUE(uint32_t, i) | ATTR_SETTER_WITH_LIST_VALUE(uint32_t, i) | ||||
| #define ATTR_GET_SINGLE_VALUE(type, field, type_name) \ | |||||
| type ParserOperator::Get##type_name##Attr(const std::string &name) const { \ | |||||
| domi::AttrDef single_val; \ | |||||
| auto it = op_attrs_.find(name); \ | |||||
| if (it != op_attrs_.end()) { \ | |||||
| single_val = it->second.value_; \ | |||||
| } else { \ | |||||
| if (op_schema_ && op_schema_->HasDefaultAttr(name)) { \ | |||||
| single_val = op_schema_->GetDefaultAttr(name); \ | |||||
| } \ | |||||
| } \ | |||||
| return single_val.field(); \ | |||||
| } | |||||
| #define ATTR_GET_SINGLE_VALUE(type, field, type_name) \ | |||||
| do { \ | |||||
| type ParserOperator::Get##type_name##Attr(const std::string &name) const { \ | |||||
| domi::AttrDef single_val; \ | |||||
| auto it = op_attrs_.find(name); \ | |||||
| if (it != op_attrs_.end()) { \ | |||||
| single_val = it->second.value_; \ | |||||
| } else { \ | |||||
| if (op_schema_ && op_schema_->HasDefaultAttr(name)) { \ | |||||
| single_val = op_schema_->GetDefaultAttr(name); \ | |||||
| } \ | |||||
| } \ | |||||
| return single_val.field(); \ | |||||
| } \ | |||||
| } while (0) | |||||
| ATTR_GET_SINGLE_VALUE(uint32_t, i, Uint) | ATTR_GET_SINGLE_VALUE(uint32_t, i, Uint) | ||||
| ATTR_GET_SINGLE_VALUE(int64_t, i, Int) | ATTR_GET_SINGLE_VALUE(int64_t, i, Int) | ||||
| ATTR_GET_SINGLE_VALUE(float, f, Float) | ATTR_GET_SINGLE_VALUE(float, f, Float) | ||||
| ATTR_GET_SINGLE_VALUE(bool, b, Bool) | ATTR_GET_SINGLE_VALUE(bool, b, Bool) | ||||
| ATTR_GET_SINGLE_VALUE(std::string, s, String) | ATTR_GET_SINGLE_VALUE(std::string, s, String) | ||||
| #define ATTR_GET_TUPLE_VALUE(type, field, tuple_type_name) \ | |||||
| tuple_type_name ParserOperator::Get##tuple_type_name##Attr(const std::string &name) const { \ | |||||
| domi::AttrDef value; \ | |||||
| auto it = op_attrs_.find(name); \ | |||||
| if (it != op_attrs_.end()) { \ | |||||
| value = it->second.value_; \ | |||||
| } else { \ | |||||
| if (op_schema_ && op_schema_->HasDefaultAttr(name)) { \ | |||||
| value = op_schema_->GetDefaultAttr(name); \ | |||||
| } \ | |||||
| } \ | |||||
| const auto attr_def = value.list(); \ | |||||
| std::size_t n = attr_def.field##_size(); \ | |||||
| std::vector<type> vec(n); \ | |||||
| for (std::size_t i = 0; i < n; i++) { \ | |||||
| vec[i] = attr_def.field(i); \ | |||||
| } \ | |||||
| return tuple_type_name(vec); \ | |||||
| } | |||||
| #define ATTR_GET_TUPLE_VALUE(type, field, tuple_type_name) \ | |||||
| do { \ | |||||
| tuple_type_name ParserOperator::Get##tuple_type_name##Attr(const std::string &name) const { \ | |||||
| domi::AttrDef value; \ | |||||
| auto it = op_attrs_.find(name); \ | |||||
| if (it != op_attrs_.end()) { \ | |||||
| value = it->second.value_; \ | |||||
| } else { \ | |||||
| if (op_schema_ && op_schema_->HasDefaultAttr(name)) { \ | |||||
| value = op_schema_->GetDefaultAttr(name); \ | |||||
| } \ | |||||
| } \ | |||||
| const auto attr_def = value.list(); \ | |||||
| std::size_t n = attr_def.field##_size(); \ | |||||
| std::vector<type> vec(n); \ | |||||
| for (std::size_t i = 0; i < n; i++) { \ | |||||
| vec[i] = attr_def.field(i); \ | |||||
| } \ | |||||
| return tuple_type_name(vec); \ | |||||
| } \ | |||||
| } while (0) | |||||
| ATTR_GET_TUPLE_VALUE(uint32_t, i, UintTuple) | ATTR_GET_TUPLE_VALUE(uint32_t, i, UintTuple) | ||||
| ATTR_GET_TUPLE_VALUE(int64_t, i, IntTuple) | ATTR_GET_TUPLE_VALUE(int64_t, i, IntTuple) | ||||