MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / ParseAttributeHelper

Method ParseAttributeHelper

tensorflow/compiler/xla/service/hlo_parser.cc:2762–3038  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2760}
2761
2762bool HloParserImpl::ParseAttributeHelper(
2763 const absl::flat_hash_map<std::string, AttrConfig>& attrs,
2764 absl::flat_hash_set<std::string>* seen_attrs) {
2765 LocTy loc = lexer_.GetLoc();
2766 std::string name;
2767 if (!ParseAttributeName(&name)) {
2768 return Error(loc, "error parsing attributes");
2769 }
2770 VLOG(3) << "Parsing attribute " << name;
2771 if (!seen_attrs->insert(name).second) {
2772 return Error(loc, StrFormat("attribute %s already exists", name));
2773 }
2774 auto attr_it = attrs.find(name);
2775 if (attr_it == attrs.end()) {
2776 std::string allowed_attrs;
2777 if (attrs.empty()) {
2778 allowed_attrs = "No attributes are allowed here.";
2779 } else {
2780 allowed_attrs =
2781 StrCat("Allowed attributes: ",
2782 StrJoin(attrs, ", ",
2783 [&](std::string* out,
2784 const std::pair<std::string, AttrConfig>& kv) {
2785 StrAppend(out, kv.first);
2786 }));
2787 }
2788 return Error(loc, StrFormat("unexpected attribute \"%s\". %s", name,
2789 allowed_attrs));
2790 }
2791 AttrTy attr_type = attr_it->second.attr_type;
2792 void* attr_out_ptr = attr_it->second.result;
2793 bool success = [&] {
2794 LocTy attr_loc = lexer_.GetLoc();
2795 switch (attr_type) {
2796 case AttrTy::kBool: {
2797 bool result;
2798 if (!ParseBool(&result)) {
2799 return false;
2800 }
2801 static_cast<optional<bool>*>(attr_out_ptr)->emplace(result);
2802 return true;
2803 }
2804 case AttrTy::kInt64: {
2805 int64 result;
2806 if (!ParseInt64(&result)) {
2807 return false;
2808 }
2809 static_cast<optional<int64>*>(attr_out_ptr)->emplace(result);
2810 return true;
2811 }
2812 case AttrTy::kInt32: {
2813 int64 result;
2814 if (!ParseInt64(&result)) {
2815 return false;
2816 }
2817 if (result != static_cast<int32>(result)) {
2818 return Error(attr_loc, "value out of range for int32");
2819 }

Callers

nothing calls this directly

Calls 15

ParseWindowFunction · 0.85
ParseShardingFunction · 0.85
ParseFrontendAttributesFunction · 0.85
ParsePaddingConfigFunction · 0.85
ParseStringFunction · 0.85
GetLocMethod · 0.80
GetKindMethod · 0.80
GetStrValMethod · 0.80
LexMethod · 0.80
ErrorFunction · 0.50

Tested by

no test coverage detected