-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
304 lines (283 loc) · 10.4 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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
package main
import (
"DES-go/metrics"
"DES-go/schedulers"
"DES-go/schedulers/allox_scheduler"
"DES-go/schedulers/hydra_scheduler"
"DES-go/schedulers/hydra_scheduler/cost"
"DES-go/schedulers/types"
"DES-go/simulator"
"DES-go/util"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
"strconv"
"strings"
"time"
)
var defaultConfig = &Config{
CasesPath: "/hydra/cases",
ReportsPath: "/hydra/data",
Workload: "heavy",
NumberOfJobs: []int{10, 400},
Algorithms: []string{
"hydra_alpha_0",
"hydra_alpha_1",
"hydra_alpha_3",
"hydra_alpha_5",
"hydra_alpha_7",
"hydra_alpha_9",
"allox",
"gavel",
"chronus",
},
}
func main() {
args := os.Args
var config *Config
if len(args) == 1 {
config = defaultConfig
} else {
path := args[1]
log.Printf("specified configuration path: %v", path)
config = loadConfig(path)
}
clusterConfig := make(map[string]int)
var caseFileName string
if config.Workload == "light" {
clusterConfig["V100"] = 15
clusterConfig["GTX2080Ti"] = 15
clusterConfig["A100"] = 15
caseFileName = "20_ddl.csv"
} else if config.Workload == "heavy" {
clusterConfig["V100"] = 20
clusterConfig["GTX2080Ti"] = 15
clusterConfig["A100"] = 10
caseFileName = "30_ddl.csv"
} else {
panic("configuration param error: Workload must be \"light\" or \"heavy\".")
}
if len(config.NumberOfJobs) != 2 {
panic("configuration param error: NumberOfJobs must be an array of 2 numbers.")
}
config.NumberOfJobs[0] = config.NumberOfJobs[0] / 10 * 10
config.NumberOfJobs[1] = config.NumberOfJobs[1] / 10 * 10
if config.NumberOfJobs[0] < 0 || config.NumberOfJobs[1] < 0 {
panic("configuration param error: NumberOfJobs must not be negative.")
}
if config.NumberOfJobs[1] > 400 {
config.NumberOfJobs[1] = 400
}
// clusterConfigs 代表集群的配置变化空间,分别传入初始的状态,以及末尾状态,以及增加步长,可以按顺序获取一批gpu配置
clusterConfigs := []map[string]int{clusterConfig}
// caseRange 表示,这个case的哪一部分用来做模拟。传入多个caseRange,即做多次实验。
caseRanges := make([][]int, 0)
for i := config.NumberOfJobs[0]; i <= config.NumberOfJobs[1]; i += 10 {
caseRanges = append(caseRanges, []int{0, i})
}
log.Printf("config.NumberOfJobs is fixed to [%d, %d]", config.NumberOfJobs[0], config.NumberOfJobs[1])
algo2type := map[string]SchedulerType {
"gavel": Gavel,
"chronus": Chronus,
"allox": Allox,
"hydra_alpha_0": HydraPureHeuristic,
"hydra_alpha_1": HydraBABWithHeuristic1s,
"hydra_alpha_3": HydraBABWithHeuristic3s,
"hydra_alpha_5": HydraBABWithHeuristic5s,
"hydra_alpha_7": HydraBABWithHeuristic7s,
"hydra_alpha_9": HydraBABWithHeuristic9s,
}
schedulerTypes := make([]SchedulerType, 0)
for _, algo := range config.Algorithms {
getSt := func(algo string) SchedulerType {
if t, ok := algo2type[algo]; ok {
return t
}
algos := make([]string, 0, len(algo2type))
for algo := range algo2type {
algos = append(algos, algo)
}
panic(fmt.Sprintf("configuration param error: algorithm %s not exists! valid algo types: %v", algo, algos))
}
schedulerTypes = append(schedulerTypes, getSt(algo))
}
reports := doSimulationForMultiClusterConfig(config, caseFileName, clusterConfigs, caseRanges, schedulerTypes)
metrics.SaveSimulationReport(config.ReportsPath, reports, &metrics.SimulationMetaConfig{
CaseFileName: caseFileName,
CaseRanges: caseRanges,
ClusterConfigs: clusterConfigs,
})
}
func doSimulationForMultiClusterConfig(config *Config, caseFileName string, clusterConfig []map[string]int, caseRanges [][]int, schedulerTypes []SchedulerType) map[string][]*metrics.Report {
result := make(map[string][]*metrics.Report)
for _, cc := range clusterConfig {
m := doSimulationForOneClusterConfig(config, caseFileName, cc, caseRanges, schedulerTypes)
for k, v := range m {
if _, ok := result[k]; !ok {
result[k] = make([]*metrics.Report, 0)
}
result[k] = append(result[k], v...)
}
}
return result
}
func doSimulationForOneClusterConfig(config *Config, caseFileName string, clusterConfig map[string]int, caseRanges [][]int, schedulerTypes []SchedulerType) map[string][]*metrics.Report {
casePath := filepath.Join(config.CasesPath, caseFileName)
schedulerType2reports := make(map[string][]*metrics.Report)
fmt.Printf("Starting simulation...\n")
bs, err := json.Marshal(clusterConfig)
if err != nil {
panic(err)
}
fmt.Printf("Case Path: %s, Cluster Config: %s\n", casePath, string(bs))
fmt.Printf("Case Ranges: %+v, SchedulerTypes: %+v\n", casePath, schedulerTypes)
timeLayout := "2006-01-02_15:04:05"
startSimulation := time.Now()
fmt.Printf("Start simulation time: %s\n", startSimulation.Format(timeLayout))
for _, schedulerType := range schedulerTypes {
schedulerStart := time.Now()
fmt.Printf("Starting Simulation For Scheduler %s, StartTime: %s\n", schedulerType, schedulerStart.Format(timeLayout))
reports := make([]*metrics.Report, 0, len(caseRanges))
for _, caseRange := range caseRanges {
start := time.Now()
fmt.Printf("Simulation For Scheduler %s, CaseRange: %d, StartTime: %s\n",
schedulerType, caseRange, start.Format(timeLayout))
scheduler := getScheduler(schedulerType)
simu := simulator.NewSimulator(scheduler,
simulator.WithOptionDataSourceRange(caseRange[0], caseRange[1]),
simulator.WithOptionLogPrintLevel(simulator.NoPrint),
simulator.WithOptionDataSourceCSVPath(casePath),
simulator.WithOptionGPUType2Count(clusterConfig))
record := simu.Run()
end := time.Now()
duration := end.Sub(start)
fmt.Printf("Simulation For Scheduler %s, CaseRange: %d Finished, EndTime: %s, RunTime: %.2f\n",
schedulerType, caseRange, end.Format(timeLayout), duration.Seconds())
record.CaseRange = caseRange
reports = append(reports, metrics.GenerateSingleSimulationReport(record))
}
schedulerType2reports[string(schedulerType)] = reports
schedulerEnd := time.Now()
fmt.Printf("Ending Simulation For Scheduler %s, EndTime: %s, RunTime: %.2f\n",
schedulerType, schedulerEnd.Format(timeLayout), schedulerEnd.Sub(schedulerStart).Seconds())
}
endSimulation := time.Now()
fmt.Printf("End Simulation Time: %s, RunTime: %.2f\n", endSimulation.Format(timeLayout), endSimulation.Sub(startSimulation).Seconds())
return schedulerType2reports
}
func getScheduler(schedulerType SchedulerType) types.Scheduler {
if strings.HasPrefix(string(schedulerType), "HydraBABWithHeuristic") {
l, _ := strconv.Atoi(strings.Split(string(schedulerType), "_")[1])
//return initHydraBABHeuristicScheduler(time.Duration(l)*time.Second)
return initHydraBABHeuristicScheduler(time.Duration(100*l)*time.Millisecond)
}
var scheduler types.Scheduler = nil
switch schedulerType {
case Dummy:
scheduler = initDummyScheduler()
case Gavel:
scheduler = initSJFScheduler()
case Chronus:
scheduler = initEDFScheduler()
case HydraPureHeuristic:
scheduler = initHydraHeuristicScheduler()
case Allox:
scheduler = initAlloxScheduler()
default:
panic("Unsupported scheduler type.")
}
return scheduler
}
type SchedulerType string
const (
Dummy SchedulerType = "Dummy"
Gavel SchedulerType = "Gavel"
Chronus SchedulerType = "Chronus"
HydraPureHeuristic SchedulerType = "HydraPureHeuristic"
HydraBABWithHeuristic1s SchedulerType = "HydraBABWithHeuristic_1"
HydraBABWithHeuristic3s SchedulerType = "HydraBABWithHeuristic_3"
HydraBABWithHeuristic5s SchedulerType = "HydraBABWithHeuristic_5"
HydraBABWithHeuristic7s SchedulerType = "HydraBABWithHeuristic_7"
HydraBABWithHeuristic9s SchedulerType = "HydraBABWithHeuristic_9"
Allox SchedulerType = "Allox"
)
func initDummyScheduler() types.Scheduler {
return schedulers.NewDummyScheduler()
}
func initSJFScheduler() types.Scheduler {
return schedulers.NewGavelScheduler()
}
func initEDFScheduler() types.Scheduler {
return schedulers.NewChronusScheduler()
}
func initAlloxScheduler() types.Scheduler {
return allox_scheduler.NewAlloxScheduler(false)
}
func initHydraScheduler() types.Scheduler {
return hydra_scheduler.New(
hydra_scheduler.WithScheme(hydra_scheduler.NewBasicScheduleScheme(true, false, -1, true)),
hydra_scheduler.WithDistanceAlgo(hydra_scheduler.NewMinCostDistanceAlgo(
cost.NewBranchAndBoundAlgo(cost.BranchAndBoundLCStandardPredictCost, cost.BranchAndBoundAlgoTypeFixNonDDL),
cost.NewSimpleAddCostSolverMaker(cost.DDLCostTypeStrict, 1e20))),
)
}
func initHydraHeuristicScheduler() types.Scheduler {
return hydra_scheduler.New(
hydra_scheduler.WithScheme(hydra_scheduler.NewBasicScheduleScheme(true, false, -1, true)),
hydra_scheduler.WithDistanceAlgo(hydra_scheduler.NewMinCostDistanceAlgo(
cost.NewSwapHeuristic(),
cost.NewSimpleAddCostSolverMaker(cost.DDLCostTypeStrict, 1e20))),
)
}
func initHydraBABHeuristicScheduler(latency time.Duration) types.Scheduler {
return hydra_scheduler.New(
hydra_scheduler.WithScheme(hydra_scheduler.NewBasicScheduleScheme(true, false, -1, true)),
hydra_scheduler.WithDistanceAlgo(hydra_scheduler.NewMinCostDistanceAlgo(
//cost.NewBranchAndBoundAlgoWithLatency(cost.BranchAndBoundLCStandardPredictCost, cost.BranchAndBoundAlgoTypeFixNonDDL, time.Duration(latencySec)*time.Second, cost.NewSwapHeuristic()),
cost.NewBranchAndBoundAlgoWithLatency(cost.BranchAndBoundLCStandardPredictCost, cost.BranchAndBoundAlgoTypeFixNonDDL, latency, cost.NewSwapHeuristic()),
cost.NewSimpleAddCostSolverMaker(cost.DDLCostTypeStrict, 1e20))),
)
}
type Config struct {
CasesPath string `json:"cases_path"`
ReportsPath string `json:"reports_path"`
Workload string `json:"workload"`
NumberOfJobs []int `json:"number_of_jobs"`
Algorithms []string `json:"algorithms"`
}
func loadConfig(configPath string) *Config {
bytes, err := ioutil.ReadFile(configPath)
if err != nil {
panic(err)
}
config := &Config{}
err = json.Unmarshal(bytes, config)
if err != nil {
panic(err)
}
return config
}
func generateGPUConfig(initConfig map[string]int, targetConfig map[string]int, step int) []map[string]int {
gpus := []string{"A100", "GTX2080Ti", "V100"}
result := make([]map[string]int, 0)
result = append(result, initConfig)
curr := util.CopyStringIntMap(initConfig)
for {
keys := util.StringIntMapLessOrEqualsKeys(curr, targetConfig)
if len(keys) == 0 {
return result
}
util.StringSliceSortBy(keys, gpus)
for _, key := range keys {
curr = util.CopyStringIntMap(curr)
curr[key] += step
if curr[key] > targetConfig[key] {
curr[key] = targetConfig[key]
}
result = append(result, curr)
}
}
}