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

Method ParseLayout

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

layout ::= '{' int64_list (':' tiles element_size_in_bits memory_space)? '}' element_size_in_bits ::= /*empty*/ ::= 'E' '(' int64 ')' memory_space ::= /*empty*/ ::= 'S' '(' int64 ')'

Source from the content-addressed store, hash-verified

3665// ::= /*empty*/
3666// ::= 'S' '(' int64 ')'
3667bool HloParserImpl::ParseLayout(Layout* layout) {
3668 std::vector<int64> minor_to_major;
3669 std::vector<Tile> tiles;
3670 tensorflow::int64 element_size_in_bits = 0;
3671 tensorflow::int64 memory_space = 0;
3672
3673 auto parse_and_add_item = [&]() {
3674 int64 i;
3675 if (!ParseInt64(&i)) {
3676 return false;
3677 }
3678 minor_to_major.push_back(i);
3679 return true;
3680 };
3681
3682 if (!ParseToken(TokKind::kLbrace,
3683 StrCat("expects layout to start with ",
3684 TokKindToString(TokKind::kLbrace)))) {
3685 return false;
3686 }
3687 if (lexer_.GetKind() != TokKind::kRbrace) {
3688 if (lexer_.GetKind() == TokKind::kInt) {
3689 // Parse minor to major.
3690 do {
3691 if (!parse_and_add_item()) {
3692 return false;
3693 }
3694 } while (EatIfPresent(TokKind::kComma));
3695 }
3696
3697 if (lexer_.GetKind() == TokKind::kColon) {
3698 lexer_.Lex();
3699 if (lexer_.GetKind() == TokKind::kIdent && lexer_.GetStrVal() == "T") {
3700 lexer_.Lex();
3701 ParseTiles(&tiles);
3702 }
3703
3704 if (lexer_.GetKind() == TokKind::kIdent && lexer_.GetStrVal() == "E") {
3705 lexer_.Lex();
3706 ParseLayoutIntAttribute(&element_size_in_bits, "element size in bits");
3707 }
3708
3709 if (lexer_.GetKind() == TokKind::kIdent && lexer_.GetStrVal() == "S") {
3710 lexer_.Lex();
3711 ParseLayoutIntAttribute(&memory_space, "memory space");
3712 }
3713 }
3714 }
3715 if (!ParseToken(TokKind::kRbrace,
3716 StrCat("expects layout to end with ",
3717 TokKindToString(TokKind::kRbrace)))) {
3718 return false;
3719 }
3720
3721 std::vector<Tile> vec_tiles(tiles.size());
3722 for (int i = 0; i < tiles.size(); i++) {
3723 vec_tiles[i] = Tile(tiles[i]);
3724 }

Callers

nothing calls this directly

Calls 9

TokKindToStringFunction · 0.85
GetKindMethod · 0.80
LexMethod · 0.80
GetStrValMethod · 0.80
StrCatFunction · 0.50
TileFunction · 0.50
MakeLayoutFunction · 0.50
push_backMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected