Skip to content

Commit

Permalink
Merge pull request #103 from LeelaChessZero/master
Browse files Browse the repository at this point in the history
Merge master to release for version 24.
  • Loading branch information
Tilps authored Jan 29, 2020
2 parents 33e15f9 + 743d8f8 commit c6ccfff
Showing 1 changed file with 52 additions and 5 deletions.
57 changes: 52 additions & 5 deletions lc0_main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"bytes"
"compress/gzip"
"crypto/rand"
"crypto/sha256"
"crypto/sha256"
"encoding/json"
"errors"
"flag"
Expand Down Expand Up @@ -43,8 +43,12 @@ var (
hasCudnnFp16 bool
hasOpenCL bool
hasBlas bool
hasDx bool
testedCudnnFp16 bool

localHost = "Unknown"
gpuType = "Unknown"

hostname = flag.String("hostname", "http://api.lczero.org", "Address of the server")
user = flag.String("user", "", "Username")
password = flag.String("password", "", "Password")
Expand All @@ -59,6 +63,8 @@ var (
keep = flag.Bool("keep", false, "Do not delete old network files")
version = flag.Bool("version", false, "Print version and exit.")
trainOnly = flag.Bool("train-only", false, "Do not play match games")
report_host = flag.Bool("report-host", false, "Send hostname to server for more fine-grained statistics")
report_gpu = flag.Bool("report-gpu", false, "Send gpu info to server for more fine-grained statistics")
)

// Settings holds username and password.
Expand Down Expand Up @@ -113,9 +119,12 @@ func getExtraParams() map[string]string {
return map[string]string{
"user": *user,
"password": *password,
"version": "23",
"version": "24",
"token": strconv.Itoa(randId),
"train_only": strconv.FormatBool(*trainOnly),
"hostname": localHost,
"gpu": gpuType,
"gpu_id": strconv.Itoa(*gpu),
}
}

Expand Down Expand Up @@ -211,7 +220,7 @@ func (c *cmdWrapper) openInput() {
}
}

func convertMovesToPGN(moves []string, result string) string {
func convertMovesToPGN(moves []string, result string, start_ply_count int) string {
game := chess.NewGame(chess.UseNotation(chess.LongAlgebraicNotation{}))
for _, m := range moves {
err := game.MoveStr(m)
Expand All @@ -238,7 +247,7 @@ func convertMovesToPGN(moves []string, result string) string {
b = []byte(strings.TrimRight(b_str, "*") + to_append)
}
game2.UnmarshalText(b)
return game2.String()
return game2.String() + " {OL: " + strconv.Itoa(start_ply_count) + "}"
}

func createCmdWrapper() *cmdWrapper {
Expand All @@ -262,6 +271,9 @@ func checkLc0() {
if bytes.Contains(out, []byte("blas")) {
hasBlas = true
}
if bytes.Contains(out, []byte("dx")) {
hasDx = true
}
if bytes.Contains(out, []byte("cudnn-fp16")) {
hasCudnnFp16 = true
}
Expand Down Expand Up @@ -314,6 +326,11 @@ func (c *cmdWrapper) launch(networkPath string, otherNetPath string, args []stri
}
} else if hasCudnn {
c.Cmd.Args = append(c.Cmd.Args, fmt.Sprintf("--backend-opts=backend=cudnn%v", sGpu))
} else if hasDx {
if !hasBlas {
log.Fatalf("Dx backend cannot be validated")
}
c.Cmd.Args = append(c.Cmd.Args, fmt.Sprintf("--backend-opts=check(freq=.01,atol=5e-1,dx%v)", sGpu))
} else if hasOpenCL {
c.Cmd.Args = append(c.Cmd.Args, fmt.Sprintf("--backend-opts=backend=opencl%v", sGpu))
}
Expand Down Expand Up @@ -389,6 +406,7 @@ func (c *cmdWrapper) launch(networkPath string, otherNetPath string, args []stri
}
idx4 := strings.LastIndex(line, "player1")
idx5 := strings.LastIndex(line, "result")
idx6 := strings.LastIndex(line, "play_start_ply")
result := ""
if idx5 < 0 {
idx5 = idx3
Expand All @@ -399,8 +417,12 @@ func (c *cmdWrapper) launch(networkPath string, otherNetPath string, args []stri
if idx4 >= 0 {
player = line[idx4+8 : idx5-1]
}
start_ply_count := -1
if idx6 >= 0 {
start_ply_count, err = strconv.Atoi(line[idx6+15 : idx4 - 1])
}
file := line[idx1+13 : idx2-1]
pgn := convertMovesToPGN(strings.Split(line[idx3+6:len(line)], " "), result)
pgn := convertMovesToPGN(strings.Split(line[idx3+6:len(line)], " "), result, start_ply_count)
fmt.Printf("PGN: %s\n", pgn)
c.gi <- gameInfo{pgn: pgn, fname: file, fp_threshold: last_fp_threshold, player1: player, result: result}
last_fp_threshold = -1.0
Expand All @@ -413,6 +435,24 @@ func (c *cmdWrapper) launch(networkPath string, otherNetPath string, args []stri
fmt.Println(line)
case strings.HasPrefix(line, "info"):
testedCudnnFp16 = true
case strings.HasPrefix(line, "GPU: "):
if *report_gpu && *backopts == "" {
gpuType = strings.TrimPrefix(line, "GPU: ")
}
fmt.Println(line)
case strings.HasPrefix(line, "Selected device: "):
if *report_gpu && *backopts == "" {
gpuType = strings.TrimPrefix(line, "Selected device: ")
}
fmt.Println(line)
case strings.HasPrefix(line, "BLAS"):
if *report_gpu && *backopts == "" {
gpuType = "None"
}
fmt.Println(line)
case strings.HasPrefix(line, "*** ERROR check failed"):
fmt.Println(line)
log.Fatal("The dx backend failed the self check - try updating gpu drivers")
case strings.HasPrefix(line, "GPU compute capability:"):
cc, _ := strconv.ParseFloat(strings.Split(line, " ")[3], 32)
if cc >= 7.0 {
Expand Down Expand Up @@ -1034,6 +1074,13 @@ func main() {
log.Fatal("You must specify a non-empty password")
}

if *report_host {
s, err := os.Hostname()
if err == nil {
localHost = s
}
}

httpClient := &http.Client{}
startTime = time.Now()
for i := 0; ; i++ {
Expand Down

0 comments on commit c6ccfff

Please sign in to comment.