Skip to content

Instantly share code, notes, and snippets.

@gboddin
Last active January 27, 2024 11:58
Show Gist options
  • Star 22 You must be signed in to star a gist
  • Fork 9 You must be signed in to fork a gist
  • Save gboddin/bbf10dc51cd468fba93e8f4e17c51859 to your computer and use it in GitHub Desktop.
Save gboddin/bbf10dc51cd468fba93e8f4e17c51859 to your computer and use it in GitHub Desktop.
Mining optimisation under Linux

Mining under linux

Disclaimer

I'm in no case responsible for fried hardware, erased software or burning down houses. Make sure your miners are always well cooled.

General recommendation

Though you can easily mix nVidia and AMD in the same rig with Linux, it's recommended to use a different thread for each platform so a Driver crash doesn't bring the whole rig down. It should be noted however, that some mining software have trouble when both architecture are found on the same rig.

nVidia

OS

I recommend using Ubuntu. The advantage is this little PPA over there : https://launchpad.net/~graphics-drivers/+archive/ubuntu/ppa that will allow easy installation of latest nVidia drivers.

Driver installation

add-apt-repository ppa:graphics-drivers/ppa
apt-get update
apt-get install -y linux-headers-generic nvidia-387 libcuda1-387 xorg --no-install-recommend

Enabling XORG on all GPU

If you don't enable XORG, you won't be able to use nvidia-settings to overclock your card(s), so yes, and X server is needed.

nvidia-xconfig --enable-all-gpus --coolbits=28 --allow-empty-initial-configuration

Create a systemd service file ( see nvidia-mining.service )

vim /nvidia-mining.service
<read and paste content from mining.service below>

Create your mining start-up script (see start-nvidia-mining.sh)

vim /start-nvidia-mining.sh
<read and paste content from start-nvidia-mining.sh below>
chmod +x /start-nvidia-mining.sh

In the script a value of 100 is used for GPUMemoryTransferRateOffset. The max memory overclock you can achieve depends on your card. Start from 100 and increase slowly to find a safe spot ( running stable for more than 30 minutes ).

Enable the service at start-up

systemctl enable /nvidia-mining.service
systemctl start nvidia-mining

AMD ( Polaris tested, possibly all other cards supported by amdgpu )

Flashing new memory stripes

Not covered, you need a Windows computer with ATI flash. The current linux version doesn't support Polaris cards. I recommend checking https://anorak.tech/ for an up-to-date BIOS and how-to.

OS

I recommend using Ubuntu >= 16.04. To get optimal support for latest AMDs you should download and install a kernel newer than 4.11 : http://kernel.ubuntu.com/~kernel-ppa/mainline/drm-next/current/ .

Drivers

I recommend using the opensource driver included with the kernel. (The PRO driver only supports ubuntu 16.04).

However, you're gonnna need to download the full driver archive from AMD ( http://support.amd.com/en-us/kb-articles/Pages/AMDGPU-PRO-Driver-for-Linux-Release-Notes.aspx , 17.40 when writting this) to install opencl libraries.

Once downloaded, extract the file and ONLY install the following packages (and depedencies):

  • libopencl1-amdgpu-pro-xxx-amd64.deb
  • opencl-amdgpu-pro-icd-xxx-amd64.deb
  • clinfo-amdgpu-pro-xxx-amd64.deb

Overclocking and undervolting support

https://github.com/OhGodACompany/OhGodATool is a tool that allows both of this. It has been tested with Polaris on 4.15 kernels and does allow undervolting/overclocking via the power-play tables.

Undervolting example

  1. Display the voltage and core clock table :
root@host# ./ohgodatool -i 0 --show-core --show-voltage
DPM state 0:
	VDDC: 750 (voltage table entry 0)
	VDDC offset: 0
	Core clock: 300
DPM state 1:
	VDDC: 65282 (voltage table entry 1)
	VDDC offset: -26
	Core clock: 600
DPM state 2:
	VDDC: 65283 (voltage table entry 2)
	VDDC offset: -26
	Core clock: 900
DPM state 3:
	VDDC: 65284 (voltage table entry 3)
	VDDC offset: -26
	Core clock: 1145
DPM state 4:
	VDDC: 65284 (voltage table entry 4)
	VDDC offset: -26
	Core clock: 1215
DPM state 5:
	VDDC: 65284 (voltage table entry 5)
	VDDC offset: -26
	Core clock: 1250
DPM state 6:
	VDDC: 65284 (voltage table entry 6)
	VDDC offset: -26
	Core clock: 1275
DPM state 7:
	VDDC: 950 (voltage table entry 7)
	VDDC offset: 0
	Core clock: 1300

Voltage state 0: 
	VDD = 750
	CACLow = 0
	CACMid = 0
	CACHigh = 0
Voltage state 1: 
	VDD = 65282
	CACLow = 0
	CACMid = 0
	CACHigh = 0
Voltage state 2: 
	VDD = 65283
	CACLow = 0
	CACMid = 0
	CACHigh = 0
Voltage state 3: 
	VDD = 65284
	CACLow = 0
	CACMid = 0
	CACHigh = 0
Voltage state 4: 
	VDD = 65284
	CACLow = 0
	CACMid = 0
	CACHigh = 0
Voltage state 5: 
	VDD = 65284
	CACLow = 0
	CACMid = 0
	CACHigh = 0
Voltage state 6: 
	VDD = 65284
	CACLow = 0
	CACMid = 0
	CACHigh = 0
Voltage state 7: 
	VDD = 65284
	CACLow = 0
	CACMid = 0
	CACHigh = 0
Voltage state 8: 
	VDD = 800
	CACLow = 0
	CACMid = 0
	CACHigh = 0
Voltage state 9: 
	VDD = 850
	CACLow = 0
	CACMid = 0
	CACHigh = 0
Voltage state 10: 
	VDD = 900
	CACLow = 0
	CACMid = 0
	CACHigh = 0
Voltage state 11: 
	VDD = 950
	CACLow = 0
	CACMid = 0
	CACHigh = 0
Voltage state 12: 
	VDD = 1000
	CACLow = 0
	CACMid = 0
	CACHigh = 0
Voltage state 13: 
	VDD = 1050
	CACLow = 0
	CACMid = 0
	CACHigh = 0
Voltage state 14: 
	VDD = 1100
	CACLow = 0
	CACMid = 0
	CACHigh = 0
Voltage state 15: 
	VDD = 1150
	CACLow = 0
	CACMid = 0
	CACHigh = 0
  1. Assign the choosen voltage (here 950mV, so position 11) to the latest core clock (here 7)
./ohgodatool -i 2 --core-state 7 --core-vddc-idx 11
Core state 7 VDDC: 7 -> 11

Overclocking example

  1. List the current memory clock
 ./ohgodatool -i 2 --show-mem
Memory state 0:
	VDDC: 750
	VDDCI: 800
	VDDC GFX offset: 0
	MVDD: 900
	Memory clock: 300
Memory state 1:
	VDDC: 65282
	VDDCI: 850
	VDDC GFX offset: 0
	MVDD: 900
	Memory clock: 1000
Memory state 2:
	VDDC: 65283
	VDDCI: 950
	VDDC GFX offset: 0
	MVDD: 900
	Memory clock: 1800
  1. Change the last clock in the table
root@localhost# ./ohgodatool -i 0 --mem-state 2  --mem-clock 2100
Memory state 2 clock: 1800 -> 2100.

Create a systemd service file ( see amd-mining.service )

vim /amd-mining.service
<read and paste content from amd-mining.service below>

Create your mining start-up script (see start-amd-mining.sh)

vim /start-amd-mining.sh
<read and paste content from start-amd-mining.sh below>
chmod +x /start-amd-mining.sh

Enable the service at start-up

systemctl enable /amd-mining.service
systemctl start amd-mining
[Unit]
Description=AMD Mining service
[Service]
User=root
Group=root
GuessMainPID=no
ExecStart=/start-amd-mining.sh
Restart=always
RestartSec=30
StartLimitInterval=200
StartLimitBurst=5
[Install]
WantedBy=multi-user.target
[Unit]
Description=nVidia Mining service
[Service]
User=root
Group=root
GuessMainPID=no
ExecStart=/usr/bin/xinit /start-nvidia-mining.sh
Restart=always
RestartSec=30
StartLimitInterval=200
StartLimitBurst=5
[Install]
WantedBy=multi-user.target
#!/bin/bash
export GPU_FORCE_64BIT_PTR=1
export GPU_MAX_HEAP_SIZE=100
export GPU_MAX_ALLOC_PERCENT=100
export GPU_SINGLE_ALLOC_PERCENT=100
# Configure card 0
/srv/ohgodatool/ohgodatool -i 0 --core-state 7 --core-vddc-idx 11 --mem-state 2 --mem-clock 2100 --set-fanspeed 60
# Configure card 1
/srv/ohgodatool/ohgodatool -i 1 --core-state 7 --core-vddc-idx 11 --mem-state 2 --mem-clock 2100 --set-fanspeed 60
# and so on ...
cd /xmrstak-amd
./bin/xmr-stak
#!/bin/bash
export GPU_FORCE_64BIT_PTR=1
export GPU_MAX_HEAP_SIZE=100
export GPU_MAX_ALLOC_PERCENT=100
export GPU_SINGLE_ALLOC_PERCENT=100
# Configure your card fan and memory OC :
# Here a value of 1400 is choosen.
# Start from lower and increase by step of 100
# Let it run for 10 minutes, if no crash -> increment again
/usr/bin/nvidia-settings -c :0 -a "[gpu:0]/GPUFanControlState=1" -a "[gpu:0]/GPUTargetFanSpeed=100" -a "[gpu:0]/GPUMemoryTransferRateOffset[3]=100"
# Repeat for the next GPU :
#/usr/bin/nvidia-settings -c :0 -a "[gpu:1]/GPUFanControlState=1" -a "[gpu:1]/GPUTargetFanSpeed=100" -a "[gpu:1]/GPUMemoryTransferRateOffset[3]=100"
# Launch your miner, here xmr-stak
cd /xmrstak-nvidia
./bin/xmr-stak
@reqshark
Copy link

well done, sir

:)

@PNixx
Copy link

PNixx commented Jun 2, 2018

Has anyone worked with vega 56?

@reqshark
Copy link

Has anyone worked with vega 56?

@PNixx, yes. Not as cool as rx570 IMO

@vanities
Copy link

vanities commented Aug 3, 2018

Thanks!!

@Arman92
Copy link

Arman92 commented Sep 6, 2018

GREAT! Thank you <3

@mortsavi
Copy link

mortsavi commented Sep 29, 2018

It makes the claymore to crash... as soon as I set the mem and core. (AMDgpu-pro)

@cultd3ad
Copy link

@gboddin
Do you have any ideas how I can solve the problem? I am using old AMD cards R9 280 series.

root@demo:/demo/sbin# ./ohgodatool -i 0 --show-core --show-voltage --show-mem
Unable to read header from file.

thanks in advance

@gardotd426
Copy link

@cultd3ad your GPU isn't supported by the amdgpu kernel driver. It's too old, so it uses the radeon kernel driver by default.

As the gist mentions above, it says "probably any GPU supported by amdgpu.

Good news is, your GPU has experimental support for amdgpu. You just have to enable it and disable radeon.

Assuming you're using GRUB as your bootloader (if you're on Ubuntu and haven't changed it, then you are indeed using GRUB), you simply edit /etc/default/grub (obviously you'll have to use sudo , so sudo nano /etc/default/grub).

There will be a line near the top that says GRUB_CMDLINE_LINUX_DEFAULT= with some stuff inside some quotation marks. Like:

GRUB_CMDLINE_LINUX_DEFAULT="loglevel=3 quiet splash"

Or something similar. In between those quotes, you need to add:

radeon.si_support=0 radeon.cik_support=0 amdgpu.si_support=1 amdgpu.cik_support=1

Add it INSIDE the quotes, with the other stuff, just make sure there is a space between every entry. So in the above example, it would look like this:

GRUB_CMDLINE_LINUX_DEFAULT="loglevel=3 quiet splash radeon.si_support=0 radeon.cik_support=0 amdgpu.si_support=1 amdgpu.cik_support=1"

Then run sudo update-grub, and reboot.

You can confirm the driver you're using through various methods, but I would just use inxi. You can run inxi -Gxz, and you'll see in the output driver: loaded: amdgpu unloaded: radeon or something like that. As long as you see amdgpu in the loaded section, then you're good.

Make sure you have xf86-video-amdgpu installed, I'm not sure what the name of that package is in Ubuntu. Oh I just checked, in Ubuntu it's xserver-xorg-video-amdgpu.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment