-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.go
170 lines (158 loc) · 4.31 KB
/
main.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*
* Copyright (c) 2019, Aditya Rohan
* Copyright (c) 2019, Aniket Pandey
*
* Submitted to:
* CS622A: 2019-20 Fall Semester. Course Project
*/
package main
import (
"fmt"
"io"
"io/ioutil"
"log"
"os"
"os/exec"
"path"
"strings"
)
type prefetch struct {
name string
l1d, l2c, llc string
}
// var prefetchers []prefetch
func main() {
// Initialize info about all prefetchers
prefetchers := []prefetch{
{"berti", "berti+", "berti", "next_line_no"},
{"bingo", "bingo_dpc3", "next_line", "next_line"},
{"bouquet", "ipcp", "ipcp", "ipcp"},
{"default", "no", "no", "no"},
//{"dsp", "dsp", "dsp", "no"},
{"enhancing", "team_12", "team_12", "team_12"},
//{"ipcp++", "ipcp++", "cs622_sangam++", "team_12"},
{"multi-lop", "mlop_dpc3", "next_line", "next_line"},
{"next-line", "next_line", "next_line", "next_line"},
{"pangloss", "pangloss", "pangloss", "no"},
{"sangam", "sangam_dpc3", "sangam_dpc3", "sangam_dpc3"},
{"sangam++", "cs622_sangam++", "cs622_sangam++", "cs622_sangam++"},
{"t-skid", "spp", "spp", "no"},
}
// Need current directory to build single-core CPUs
currDir, err := os.Getwd()
if err != nil {
log.Fatal(err)
}
if len(os.Args) == 1 {
if err := buildCPUs(currDir, prefetchers); err != nil {
log.Fatal("Could not build champsim CPUs\n" + err.Error())
}
}
if err := runTraces(currDir, prefetchers); err != nil {
log.Fatal("Could not run simulation\n" + err.Error())
}
}
func cleanPrefetchers(prefetchDir string) {
dir, _ := ioutil.ReadDir(prefetchDir)
for _, d := range dir {
os.RemoveAll(path.Join([]string{prefetchDir, d.Name()}...))
}
}
// Source: https://stackoverflow.com/a/21067803
func copyFileContents(src, dst string) (err error) {
in, err := os.Open(src)
if err != nil {
return
}
defer in.Close()
out, err := os.Create(dst)
if err != nil {
return
}
defer func() {
cerr := out.Close()
if err == nil {
err = cerr
}
}()
if _, err = io.Copy(out, in); err != nil {
return
}
err = out.Sync()
return
}
// Build CPUs corresponding to each prefetcher
func buildCPUs(currDir string, prefetchers []prefetch) (err error) {
prefetchDir := currDir + "/champsim/prefetcher/"
cleanPrefetchers(prefetchDir)
for _, prefetcher := range prefetchers {
// Move prefetching algorithms for L1, L2, LLC to champsim
fileDir := currDir + "/prefetchers/" + prefetcher.name + "/"
files, err := ioutil.ReadDir(fileDir)
if err != nil {
return err
}
for _, file := range files {
destFile := strings.TrimSuffix(prefetchDir+file.Name(), ".cpp")
if err := copyFileContents(fileDir+file.Name(),
destFile); err != nil {
return err
}
}
coreName := "perceptron-" + prefetcher.l1d + "-" +
prefetcher.l2c + "-" + prefetcher.llc + "-lru-1core"
fmt.Println("Building executable: " + coreName)
cmd := exec.Command("./build_champsim.sh", "perceptron",
prefetcher.l1d, prefetcher.l2c, prefetcher.llc, "lru", "1")
cmd.Dir = currDir + "/champsim/"
if err := cmd.Run(); err != nil {
return err
}
// Remove prefetchers
for _, file := range files {
destFile := strings.TrimSuffix(prefetchDir+file.Name(), ".cpp")
err := os.Remove(destFile)
if err != nil {
return err
}
}
}
return nil
}
// Run Champsim simulator on all traces for all submissions
func runTraces(currDir string, prefetchers []prefetch) (err error) {
traceDir := currDir + "/champsim/dpc3_traces/"
files, err := ioutil.ReadDir(traceDir)
if err != nil {
log.Fatal(err)
}
for _, prefetcher := range prefetchers {
coreName := "perceptron-" + prefetcher.l1d + "-" +
prefetcher.l2c + "-" + prefetcher.llc + "-lru-1core"
for _, traceFile := range files {
fmt.Println("Running " + coreName + " on " + traceFile.Name())
cmd := exec.Command("./run_champsim.sh", coreName,
"1", "10", traceFile.Name())
cmd.Dir = currDir + "/champsim/"
if err := cmd.Run(); err != nil {
return err
}
}
}
// Move all results to current directory
resultDir := currDir + "/champsim/results_10M/"
resultFiles, err := ioutil.ReadDir(resultDir)
if err != nil {
return err
}
finalDir := currDir + "/results/"
os.Mkdir(finalDir, os.ModePerm)
for _, file := range resultFiles {
if err := copyFileContents(resultDir+file.Name(),
finalDir+file.Name()); err != nil {
return err
}
}
fmt.Println("\nAll result files stored in " + finalDir + " directory")
return nil
}