-
Notifications
You must be signed in to change notification settings - Fork 73
/
main.go
120 lines (103 loc) · 3.24 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
package main
import (
"flag"
"fmt"
"log"
"math"
"os"
"strconv"
"strings"
"github.com/robvanmieghem/go-opencl/cl"
"github.com/robvanmieghem/gominer/algorithms/sia"
"github.com/robvanmieghem/gominer/mining"
)
//Version is the released version string of gominer
var Version = "0.6.2-Dev"
var intensity = 28
var devicesTypesForMining = cl.DeviceTypeGPU
func main() {
log.SetOutput(os.Stdout)
printVersion := flag.Bool("v", false, "Show version and exit")
useCPU := flag.Bool("cpu", false, "If set, also use the CPU for mining, only GPU's are used by default")
flag.IntVar(&intensity, "I", intensity, "Intensity")
host := flag.String("url", "localhost:9980", "daemon or server host and port, for stratum servers, use `stratum+tcp://<host>:<port>`")
pooluser := flag.String("user", "payoutaddress.rigname", "username, most stratum servers take this in the form [payoutaddress].[rigname]")
excludedGPUs := flag.String("E", "", "Exclude GPU's: comma separated list of devicenumbers")
flag.Parse()
if *printVersion {
fmt.Println("gominer version", Version)
os.Exit(0)
}
if *useCPU {
devicesTypesForMining = cl.DeviceTypeAll
}
globalItemSize := int(math.Exp2(float64(intensity)))
platforms, err := cl.GetPlatforms()
if err != nil {
log.Panic(err)
}
clDevices := make([]*cl.Device, 0, 4)
for _, platform := range platforms {
log.Println("Platform", platform.Name())
platormDevices, err := cl.GetDevices(platform, devicesTypesForMining)
if err != nil {
log.Println(err)
}
log.Println(len(platormDevices), "device(s) found:")
for i, device := range platormDevices {
log.Println(i, "-", device.Type(), "-", device.Name())
clDevices = append(clDevices, device)
}
}
if len(clDevices) == 0 {
log.Println("No suitable opencl devices found")
os.Exit(1)
}
//Filter the excluded devices
miningDevices := make(map[int]*cl.Device)
for i, device := range clDevices {
if deviceExcludedForMining(i, *excludedGPUs) {
continue
}
miningDevices[i] = device
}
nrOfMiningDevices := len(miningDevices)
var hashRateReportsChannel = make(chan *mining.HashRateReport, nrOfMiningDevices*10)
var miner mining.Miner
log.Println("Starting SIA mining")
c := sia.NewClient(*host, *pooluser)
miner = &sia.Miner{
ClDevices: miningDevices,
HashRateReports: hashRateReportsChannel,
Intensity: intensity,
GlobalItemSize: globalItemSize,
Client: c,
}
miner.Mine()
//Start printing out the hashrates of the different gpu's
hashRateReports := make([]float64, nrOfMiningDevices)
for {
//No need to print at every hashreport, we have time
for i := 0; i < nrOfMiningDevices; i++ {
report := <-hashRateReportsChannel
hashRateReports[report.MinerID] = report.HashRate
}
fmt.Print("\r")
var totalHashRate float64
for minerID, hashrate := range hashRateReports {
fmt.Printf("%d-%.1f ", minerID, hashrate)
totalHashRate += hashrate
}
fmt.Printf("Total: %.1f MH/s ", totalHashRate)
}
}
//deviceExcludedForMining checks if the device is in the exclusion list
func deviceExcludedForMining(deviceID int, excludedGPUs string) bool {
excludedGPUList := strings.Split(excludedGPUs, ",")
for _, excludedGPU := range excludedGPUList {
if strconv.Itoa(deviceID) == excludedGPU {
return true
}
}
return false
}