Skip to content

Commit 2ae1b90

Browse files
authored
Merge pull request #106 from LeelaChessZero/master
Merge master into release
2 parents c6ccfff + 254194d commit 2ae1b90

File tree

1 file changed

+58
-32
lines changed

1 file changed

+58
-32
lines changed

lc0_main.go

+58-32
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,11 @@ var (
4646
hasDx bool
4747
testedCudnnFp16 bool
4848

49-
localHost = "Unknown"
49+
settingsPath = "settings.json"
50+
defaultLocalHost = "Unknown"
5051
gpuType = "Unknown"
5152

53+
localHost = flag.String("localhost", "", "Localhost name to send to the server when reporting (defaults to Unknown, overridden by settings.json)")
5254
hostname = flag.String("hostname", "http://api.lczero.org", "Address of the server")
5355
user = flag.String("user", "", "Username")
5456
password = flag.String("password", "", "Password")
@@ -71,58 +73,67 @@ var (
7173
type Settings struct {
7274
User string
7375
Pass string
76+
Localhost string
7477
}
7578

7679
const inf = "inf"
7780

7881
/*
7982
Reads the user and password from a config file and returns empty strings if anything went wrong.
80-
If the config file does not exists, it prompts the user for a username and password and creates the config file.
8183
*/
82-
func readSettings(path string) (string, string) {
84+
func readSettings(path string) (string, string, string) {
8385
settings := Settings{}
8486
file, err := os.Open(path)
8587
if err != nil {
8688
// File was not found
87-
fmt.Printf("Please enter your username and password, an account will be automatically created.\n")
88-
fmt.Printf("Note that this password will be stored in plain text, so avoid a password that is\n")
89-
fmt.Printf("also used for sensitive applications. It also cannot be recovered.\n")
90-
fmt.Printf("Enter username : ")
91-
fmt.Scanf("%s\n", &settings.User)
92-
fmt.Printf("Enter password : ")
93-
fmt.Scanf("%s\n", &settings.Pass)
94-
jsonSettings, err := json.Marshal(settings)
95-
if err != nil {
96-
log.Fatal("Cannot encode settings to JSON ", err)
97-
return "", ""
98-
}
99-
settingsFile, err := os.Create(path)
100-
defer settingsFile.Close()
101-
if err != nil {
102-
log.Fatal("Could not create output file ", err)
103-
return "", ""
104-
}
105-
settingsFile.Write(jsonSettings)
106-
return settings.User, settings.Pass
89+
return "", "", ""
10790
}
10891
defer file.Close()
10992
decoder := json.NewDecoder(file)
11093
err = decoder.Decode(&settings)
11194
if err != nil {
11295
log.Fatal("Error decoding JSON ", err)
96+
return "", "", ""
97+
}
98+
return settings.User, settings.Pass, settings.Localhost
99+
}
100+
101+
/*
102+
Prompts the user for a username and password and creates the config file.
103+
*/
104+
func createSettings(path string) (string, string) {
105+
settings := Settings{}
106+
107+
fmt.Printf("Please enter your username and password, an account will be automatically created.\n")
108+
fmt.Printf("Note that this password will be stored in plain text, so avoid a password that is\n")
109+
fmt.Printf("also used for sensitive applications. It also cannot be recovered.\n")
110+
fmt.Printf("Enter username : ")
111+
fmt.Scanf("%s\n", &settings.User)
112+
fmt.Printf("Enter password : ")
113+
fmt.Scanf("%s\n", &settings.Pass)
114+
jsonSettings, err := json.Marshal(settings)
115+
if err != nil {
116+
log.Fatal("Cannot encode settings to JSON ", err)
117+
return "", ""
118+
}
119+
settingsFile, err := os.Create(path)
120+
defer settingsFile.Close()
121+
if err != nil {
122+
log.Fatal("Could not create output file ", err)
113123
return "", ""
114124
}
125+
settingsFile.Write(jsonSettings)
115126
return settings.User, settings.Pass
116127
}
117128

118129
func getExtraParams() map[string]string {
119130
return map[string]string{
120131
"user": *user,
121132
"password": *password,
122-
"version": "24",
133+
"version": "25",
123134
"token": strconv.Itoa(randId),
124135
"train_only": strconv.FormatBool(*trainOnly),
125-
"hostname": localHost,
136+
"hostname": *localHost,
126137
"gpu": gpuType,
127138
"gpu_id": strconv.Itoa(*gpu),
128139
}
@@ -271,7 +282,7 @@ func checkLc0() {
271282
if bytes.Contains(out, []byte("blas")) {
272283
hasBlas = true
273284
}
274-
if bytes.Contains(out, []byte("dx")) {
285+
if bytes.Contains(out, []byte("dx12")) {
275286
hasDx = true
276287
}
277288
if bytes.Contains(out, []byte("cudnn-fp16")) {
@@ -328,9 +339,9 @@ func (c *cmdWrapper) launch(networkPath string, otherNetPath string, args []stri
328339
c.Cmd.Args = append(c.Cmd.Args, fmt.Sprintf("--backend-opts=backend=cudnn%v", sGpu))
329340
} else if hasDx {
330341
if !hasBlas {
331-
log.Fatalf("Dx backend cannot be validated")
342+
log.Fatalf("Dx12 backend cannot be validated")
332343
}
333-
c.Cmd.Args = append(c.Cmd.Args, fmt.Sprintf("--backend-opts=check(freq=.01,atol=5e-1,dx%v)", sGpu))
344+
c.Cmd.Args = append(c.Cmd.Args, fmt.Sprintf("--backend-opts=check(freq=.01,atol=5e-1,dx12%v)", sGpu))
334345
} else if hasOpenCL {
335346
c.Cmd.Args = append(c.Cmd.Args, fmt.Sprintf("--backend-opts=backend=opencl%v", sGpu))
336347
}
@@ -452,7 +463,7 @@ func (c *cmdWrapper) launch(networkPath string, otherNetPath string, args []stri
452463
fmt.Println(line)
453464
case strings.HasPrefix(line, "*** ERROR check failed"):
454465
fmt.Println(line)
455-
log.Fatal("The dx backend failed the self check - try updating gpu drivers")
466+
log.Fatal("The dx12 backend failed the self check - try updating gpu drivers")
456467
case strings.HasPrefix(line, "GPU compute capability:"):
457468
cc, _ := strconv.ParseFloat(strings.Split(line, " ")[3], 32)
458469
if cc >= 7.0 {
@@ -1063,8 +1074,19 @@ func main() {
10631074
}
10641075

10651076
log.SetFlags(log.LstdFlags | log.Lshortfile)
1077+
1078+
settingsUser, settingsPassword, settingsHost := readSettings(settingsPath)
10661079
if len(*user) == 0 || len(*password) == 0 {
1067-
*user, *password = readSettings("settings.json")
1080+
*user = settingsUser
1081+
*password = settingsPassword
1082+
1083+
if len(*user) == 0 || len(*password) == 0 {
1084+
*user, *password = createSettings(settingsPath)
1085+
}
1086+
}
1087+
1088+
if (len(settingsHost) != 0 && len(*localHost) == 0) {
1089+
*localHost = settingsHost
10681090
}
10691091

10701092
if len(*user) == 0 {
@@ -1074,13 +1096,17 @@ func main() {
10741096
log.Fatal("You must specify a non-empty password")
10751097
}
10761098

1077-
if *report_host {
1099+
if *report_host && len(*localHost) == 0 {
10781100
s, err := os.Hostname()
10791101
if err == nil {
1080-
localHost = s
1102+
*localHost = s
10811103
}
10821104
}
10831105

1106+
if len(*localHost) == 0 {
1107+
*localHost = defaultLocalHost
1108+
}
1109+
10841110
httpClient := &http.Client{}
10851111
startTime = time.Now()
10861112
for i := 0; ; i++ {

0 commit comments

Comments
 (0)