net-detail.awk 2.0 KB
Newer Older
D
dolphin8 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
BEGIN {
print "digraph G {"
}
/op:/ {
    id++
    opname[id] = $NF
}
/input/ {
    type = "input"
    para = $NF
    if (input[id]) {
        input[id] = input[id] "|"
    }
    input[id] = input[id] "<" para ">" para
}
/output/ {
    type = "output"
    para = $NF
    if (output[id]) {
        output[id] = output[id] "|"
    }
    output[id] = output[id] "<" para ">" para
}
/attr/ {
    type = "attr"
    aname = $NF
    if (attr_key[id]) {
        attr_key[id] = attr_key[id] "|"
        attr_value[id] = attr_value[id] "|"
    }
    attr_key[id] = attr_key[id] $NF
}
/argument/ {
    if (type == "attr") {
        split($0, arr, " - ")
        attr_value[id] = attr_value[id] arr[2]
    } else if ((type == "input") || (type == "output")) {
        if (!var2id[$NF]) {
            var_id++
            var[var_id] = $NF
            var2id[$NF] = var_id
        }
        varid = var2id[$NF]
        lid++
        if (type == "input") {
            line[lid] = "var_" varid " -> " "op_" id ":<" para ">"
            if (xout[$NF]) {
                xi++
                xline[xi] = "xop_" xout[$NF] " -> " "xop_" id
            }
        } else if (type == "output") {
            line[lid] = "op_" id ":<" para ">" " -> " "var_" varid
            xout[$NF] = id
        }
    }
}
/var name/ {
    varname = $NF
    vid = var2id[varname]
}
/var tensor desc dim / {
    if (tensor[vid]) tensor[vid] = tensor[vid] " x "
    tensor[vid] = tensor[vid] $NF
}
END {

print "subgraph cluster_G0 {"
for (i = 1; i <= id; i++) {
    print "xop_" i "[label=\"" i ". " opname[i] "\"]"
}
for (i = 1; i <= xi; i++) {
    print xline[i]
}
print "}"

for (i = 1; i <= id; i++) {
print "op_" i "[group=op;shape=record;label=\"{{" input[i] "}|<op>" i ". " opname[i] "|{" output[i] "}}\"]"
}
for (i = 1; i <= var_id; i++) {
print "var_" i "[label=\"" var[i] " [" tensor[i] "]\"]"
}
for (i = 1; i <= lid; i++) {
print line[i]
}
for (i = 1; i <= id; i++) {
print "attr_" i "[shape=record;label=\"{" attr_key[i] "}|{" attr_value[i] "}\"]"
print "attr_" i " -> " "op_" i ":<op>"
}
print "}"
}