forked from rai-project/dlframework
/
gpu_kernel_layer_aggre_info.go
120 lines (104 loc) · 3.07 KB
/
gpu_kernel_layer_aggre_info.go
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package cmd
import (
"fmt"
"os"
"path/filepath"
"sort"
"strings"
"github.com/c3sr/dlframework/evaluation"
"github.com/spf13/cobra"
)
var gpuKernelLayerAggreInfoCmd = &cobra.Command{
Use: "layer_aggre_info",
Aliases: []string{},
Short: "Get gpu information aggregated within each layer from system library traces in a database. Specify model name as `all` to list information of all the models.",
PreRunE: func(cmd *cobra.Command, args []string) error {
if databaseName == "" {
databaseName = defaultDatabaseName["cuda_kernel"]
}
err := rootSetup()
if err != nil {
return err
}
if modelName == "all" && outputFormat == "json" && outputFileName == "" {
outputFileName = filepath.Join(mlArcWebAssetsPath, "cuda_kernel_launch")
}
if overwrite && isExists(outputFileName) {
os.RemoveAll(outputFileName)
}
if kernelNameFilterString != "" {
kernelNameFilterList = strings.Split(kernelNameFilterString, ",")
}
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
run := func() error {
evals, err := getEvaluations()
if err != nil {
return err
}
summary0, err := evals.SummaryGPUKernelLayerAggreInformations(performanceCollection)
if err != nil {
return err
}
if sortOutput || topKernels != -1 {
sort.Sort(summary0)
if topKernels != -1 {
if topKernels >= len(summary0) {
topKernels = len(summary0)
}
summary0 = summary0[:topKernels]
}
}
if plotAll {
plotPath = outputFileName + "_flops.html"
summary1 := evaluation.SummaryGPUKernelLayerFlopsInformations(summary0)
err := summary1.WriteBarPlot(plotPath)
if err != nil {
return err
}
fmt.Println("Created plot in " + plotPath)
plotPath = outputFileName + "_dram_read.html"
summary2 := evaluation.SummaryGPUKernelLayerDramReadInformations(summary0)
err = summary2.WriteBarPlot(plotPath)
if err != nil {
return err
}
fmt.Println("Created plot in " + plotPath)
plotPath = outputFileName + "_dram_write.html"
summary3 := evaluation.SummaryGPUKernelLayerDramWriteInformations(summary0)
err = summary3.WriteBarPlot(plotPath)
if err != nil {
return err
}
fmt.Println("Created plot in " + plotPath)
plotPath = outputFileName + "_achieved_occupancy.html"
summary4 := evaluation.SummaryGPUKernelLayerAchievedOccupancyInformations(summary0)
err = summary4.WriteBarPlot(plotPath)
if err != nil {
return err
}
fmt.Println("Created plot in " + plotPath)
plotPath = outputFileName + "_gpu_cpu.html"
summary5 := evaluation.SummaryGPUKernelLayerGPUCPUInformations(summary0)
err = summary5.WriteBarPlot(plotPath)
if err != nil {
return err
}
fmt.Println("Created plot in " + plotPath)
}
var writer *Writer
if len(summary0) == 0 {
writer = NewWriter(evaluation.SummaryGPUKernelLayerAggreInformation{})
defer writer.Close()
}
writer = NewWriter(summary0[0])
defer writer.Close()
for _, elem := range summary0 {
writer.Row(elem)
}
return nil
}
return forallmodels(run)
},
}