-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse.go
More file actions
84 lines (78 loc) · 2.18 KB
/
parse.go
File metadata and controls
84 lines (78 loc) · 2.18 KB
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
package dnnl
import (
"bufio"
"fmt"
"log"
"os"
"regexp"
"strings"
"time"
)
/* ParseVerbose: parse the dnnl verbose mode output text file
* input: filename
* output: slice of TraceEvent struct
* metadata description: ic, oc Input/Output channels (aka feature maps)
* id, ih, iw Input depth, height and width
* od, oh, ow Output depth, height and width
* kd, kh, kw Kernel (filter, weights) depth, height and width
* sd, sh, sw Convolution stride over depth, height and width
* pd, ph, pw Convolution front, top and left padding
* mb Minibatch (amount of images processed at once)
* g Groups (a way to reduce the amount of computations, see Alexnet topology)
* example: mb1_ic3oc64_ih224oh55kh11sh4dh0ph2_iw224ow55kw11sw4dw0pw2
*/
func ParseVerbose(fName string) TraceEvents {
f, err := os.Open(fName)
if err != nil {
log.Fatal(err)
}
defer f.Close()
verboseOut := TraceEvents{}
s := bufio.NewScanner(f)
for s.Scan() {
line := strings.Split(s.Text(), ",")
if strings.Compare(line[0], DNNLMARKER) == 0 && strings.Compare(line[1], INFO) == 0 {
fmt.Println("verbose mode header, start to parse verbose output...")
continue
} else if strings.Compare(line[0], DNNLMARKER) == 0 && strings.Compare(line[1], OP) == 0 {
layer := new(TraceEvent)
layer.OpName = line[2]
//f, _ := strconv.ParseFloat(line[len(line)-1], 64)
layer.ExeTime, err = time.ParseDuration(line[len(line)-1] + "ms")
if err != nil {
panic(err)
}
layer.Propogation = line[4]
layer.DataFormat = line[5]
meta := make(map[string]string)
if len(line[6]) != 0 {
temp := strings.Split(line[6], ":")
meta[temp[0]] = temp[1]
}
if len(line[7]) != 0 {
match, _ := regexp.MatchString("([0-9]+)x", line[7])
if match {
meta["dimension"] = line[7]
} else {
dim := strings.Join(strings.Split(line[7], "_"), "")
re := regexp.MustCompile("\\D+|\\d+")
details := re.FindAllString(dim, -1)
i := 0
for i < len(details) {
meta[details[i]] = details[i+1]
i += 2
}
}
}
layer.MetaData = meta
verboseOut = append(verboseOut, layer)
} else {
break
}
}
err = s.Err()
if err != nil {
log.Fatal(err)
}
return verboseOut
}