-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcpuminer.sh
executable file
·190 lines (172 loc) · 5.51 KB
/
cpuminer.sh
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
#!/bin/bash
YELLOW='\033[1;31m'
SEA='\033[38;5;49m'
NC='\033[0m'
location=$(dirname "$0")
# Run miner.
function start_mining {
INST="$1"
if [ ! -f "cpuminer-${INST}" ]; then
echo -en "Downloading ${SEA}${1}${NC} binary ... "
wget -q https://github.com/chron0/cpuminer-multi-static/raw/main/cpuminer-${INST}
echo -e "DONE"
chmod +x cpuminer-${INST}
fi
if [ ! -f "config.json" ]; then
echo -en "Downloading config.json template ... "
wget -q https://github.com/chron0/cpuminer-multi-static/raw/main/config.json
echo -e "DONE"
read -p $'Enter your \e[35mRTM Wallet Address\e[0m: ' RTM_Address
read -p $'Enter a \e[35mName for this Worker\e[0m: ' Worker_Name
USER="${RTM_Address}.${Worker_Name}"
sed -i "s|YOUR_RTM_ADDRESS|$USER|g" config.json
fi
echo -e "Starting Miner..."
./cpuminer-${INST} -c config.json
echo -e ""
echo -e "Miner has been stopped - to run it again use:"
echo -e "./cpuminer-${INST} -c config.json"
exit
}
# Detect all CPU parameters.
if [[ $USER != "root" ]]; then
echo -e "${YELLOW}Please consider runnig as 'root' to enable MSR and Huge Pages${NC}"
fi
LSCPU=$(lscpu)
MODEL_NAME=$(lscpu | egrep "Model name" | tr -s " " | cut -d":" -f 2-)
if lscpu | egrep -i "GenuineIntel" 1>/dev/null; then
CPU_VENDOR="Intel"
echo -n "Detected Intel CPU: "
elif lscpu | egrep -i "AuthenticAMD" 1>/dev/null; then
CPU_VENDOR="AMD"
CPU_FAMILY=$(lscpu | egrep -o -i "CPU family: +[0-9]+" | awk '{ print $3 }')
if [[ $CPU_FAMILY == 25 ]]; then
ZEN="zen3"
echo -n "Detected AMD zen3 CPU: "
elif [[ $CPU_FAMILY == 23 ]]; then
CPU_MODEL=$(lscpu | egrep -o -i "Model: +[0-9]+" | awk '{ print $2 }')
if [[ $CPU_MODEL == 1 || $CPU_MODEL == 17 || \
$CPU_MODEL == 24 || $CPU_MODEL == 32 ]]; then
ZEN="zen"
echo -n "Detected AMD zen CPU: "
elif [[ $CPU_MODEL == 8 || $CPU_MODEL == 24 ]]; then
ZEN="zen+"
echo -n "Detected AMD zen+ CPU: "
elif [[ $CPU_MODEL == 49 || $CPU_MODEL == 71 || $CPU_MODEL == 96 || \
$CPU_MODEL == 104 || $CPU_MODEL == 113 || $CPU_MODEL == 144 ]]; then
ZEN="zen2"
echo -n "Detected AMD zen2 CPU: "
else
echo -n "Detected AMD non-ZEN CPU: "
fi
fi
else
CPU_VENDOR="Unknown"
echo -n "Detected Unknown CPU: "
fi
echo -e "${SEA}${MODEL_NAME}${NC}"
if [[ $CPU_VENDOR == "AMD" ]]; then
if echo $MODEL_NAME | egrep -i " ([53][69]00(X|XT)?|[0-9]{4}(U|H|HX|HS)) " 1>/dev/null; then
if cat config.json | egrep -i "\"tune-full\" *: *false" 1>/dev/null 2>/dev/null; then
echo -e "${SEA}Detected CPU model is very likely to benefit from 'tune-full'${NC}"
echo -e "${YELLOW}Changing 'tune-full' to 'true' in config.json is recommended!${NC}"
fi
fi
fi
echo -ne "Available CPU Instructions: ${SEA}"
# Check AVX512 / AVX2 / AVX / SSE4.2
if lscpu | egrep -i " avx512f( |$)" 1>/dev/null && \
lscpu | egrep -i " avx512dq( |$)" 1>/dev/null && \
lscpu | egrep -i " avx512bw( |$)" 1>/dev/null && \
lscpu | egrep -i " avx512vl( |$)" 1>/dev/null; then
HAS_AVX512=1
echo -n "AVX512 "
fi
if lscpu | egrep -i " avx2( |$)" 1>/dev/null; then
HAS_AVX2=1
echo -n "AVX2 "
fi
if lscpu | egrep -i " avx( |$)" 1>/dev/null; then
HAS_AVX=1
echo -n "AVX "
fi
if lscpu | egrep -i " sse4_2( |$)" 1>/dev/null; then
HAS_SSE42=1
echo -n "SSE42 "
fi
# Check VAES / AES
if lscpu | egrep -i " vaes( |$)" 1>/dev/null; then
HAS_VAES=1
echo -n "VAES "
fi
if lscpu | egrep -i " aes(_ni|-ni)?( |$)" 1>/dev/null; then
HAS_AES=1
echo -n "AES "
fi
# Check SHA
if lscpu | egrep -i " sha(_ni)?( |$)" 1>/dev/null; then
HAS_SHA=1
echo -n "SHA "
fi
echo -e "${NC}"
if [[ $ZEN == "zen" || $ZEN == "zen+" ]]; then
# Sanity check
if [[ $HAS_SHA && $HAS_AVX2 && $HAS_AES ]]; then
start_mining "zen"
else
echo Problem detecting zen CPU? Instruction set does not match the model!
fi
elif [[ $ZEN == "zen2" ]]; then
# Sanity check
if [[ $HAS_SHA && $HAS_AVX2 && $HAS_AES ]]; then
start_mining "zen2"
else
echo Problem detecting zen2 CPU? Instruction set does not match the model!
fi
elif [[ $ZEN == "zen3" ]]; then
# Sanity check
if [[ $HAS_SHA && $HAS_AVX2 && $HAS_VAES ]]; then
start_mining "zen3"
else
echo Problem detecting zen3 CPU? Instruction set does not match the model!
fi
fi
# Fallback for Intels and incorrectly detected AMDs and non-Ryzens.
if [[ $HAS_AVX512 && $HAS_SHA && $HAS_VAES ]]; then
INST="avx512-sha-vaes"
elif [[ $HAS_AVX512 && $HAS_SHA ]]; then
INST="avx512-sha"
elif [[ $HAS_AVX512 ]]; then
INST="avx512"
elif [[ $HAS_AVX2 && $HAS_VAES && $HAS_SHA ]]; then
if [[ $CPU_VENDOR == "AMD" ]]; then
# zen3 fallback in case of non English locale.
INST="zen3"
else # Intel Alder Lake
INST="avx2-sha-vaes"
fi
elif [[ $HAS_AVX2 && $HAS_AES && $HAS_SHA ]]; then
# zen2 fallback in case of non English locale.
# In theory can also be zen/zen+
INST="zen2"
elif [[ $HAS_AVX2 && $HAS_AES ]]; then
INST="avx2"
elif [[ $HAS_AVX2 ]]; then
echo -e "${YELLOW}Detected AVX2 CPU but not AES support.${NC}"
echo -e "${YELLOW}Please check BIOS settings and enable it!${NC}"
echo -e "${YELLOW}Running without hardware AES leads major decrease in performance!${NC}"
INST="sse42"
elif [[ $HAS_AVX && $HAS_AES ]]; then
# It is possible to have AVX but not AES.
# Some OEM laptops have it disabled by default in the bios.
INST="avx"
elif [[ $HAS_AVX && $HAS_AES ]]; then
INST="sse42"
elif [[ $HAS_SSE42 && $HAS_AES ]]; then
INST="aes-sse42"
elif [[ $HAS_SSE42 ]]; then
INST="sse42"
else
INST="sse2"
fi
start_mining "$INST"