As an Amazon Associate I earn money from qualifying purchases.
Showing posts with label batch files. Show all posts
Showing posts with label batch files. Show all posts

Tuesday, December 10, 2013

Finding Optimal Clock Speed for CGMiner and R9 290/R9 290X

Update, 12/12/2013: There were some bugs in the batch files (an errant "--" in one, for example), so I've updated them with new versions that should run properly now.

Going along with the previous post on finding the best Thread Concurrency setting for your hardware, you'll probably first want to find some good clock speeds. Unlike searching for a good TC value, tuning your clock speeds could very well lead to a system crash/hang and/or BSOD. Ideally, your system will automatically reboot, but in some cases it will get stuck and you'll have to manually intervene. Once again, I've created a couple batch files (that build off the previous batch files) for helping you find optimal values for your hardware, which you can download here. The contents of the two batch files are included below for reference:

engine-clock-test-r9version.bat:
@echo off
set threadconcurrency=24000
set gpuclock=800
set memclock=1300
set gpufan=50-75
set gpuvolt=1.100
set gpupowertune=50
set gpustopclock=1100

if exist currentgpuclock.txt (
  for /F %%x in (currentgpuclock.txt) do set gpuclock=%%x
)

setlocal EnableExtensions

:startloop
echo Current GPU Clock is %gpuclock%
echo %gpuclock%> currentgpuclock.txt
start "MinerThread" miner-tc-r9version.bat %threadconcurrency% %gpuclock% %memclock% %gpufan% %gpuvolt% %gpupowertune%
sleep 300
taskkill /im cgminer.exe /f
<nul set /p =GPU Clock %gpuclock%: >> AvgHashrateGPU.txt
grep -i "(avg)" %threadconcurrency%.txt | tail -1 >> AvgHashrateGPU.txt
set /a gpuclock=gpuclock+5
if "%gpuclock%" GTR "%gpustopclock%" goto :EOF

goto :startloop
memory-clock-test-r9version.bat:
@echo off
set threadconcurrency=24000
set gpuclock=800
set memclock=1200
set gpufan=50-75
set gpuvolt=1.100
set gpupowertune=50
set memstopclock=1700

if exist currentmemclock.txt (
  for /F %%x in (currentmemclock.txt) do set memclock=%%x
)

setlocal EnableExtensions

:startloop
echo Current RAM Clock is %memclock%
echo %memclock%> currentmemclock.txt
start "MinerThread" miner-tc-r9version.bat %threadconcurrency% %gpuclock% %memclock% %gpufan% %gpuvolt% %gpupowertune%
sleep 300
taskkill /im cgminer.exe /f
<nul set /p =RAM Clock %memclock%: >> AvgHashrateRAM.txt
grep -i "(avg)" %threadconcurrency%.txt | tail -1 >> AvgHashrateRAM.txt
set /a memclock=memclock+10
if "%memclock%" GTR "%memstopclock%" goto :EOF

goto :startloop
Other than modifying the GPU Engine or GPU Memory clock each iteration, the two files are the same. They also use the same miner-tc-r9version.bat file as before (which I didn't rename because why bother). If you create a link to the batch file you're testing and put that in your Startup folder, the batch files will also continue from where they left off in the case of a system reboot...which means if your system is unstable before the stopping clock you specify, it will be stuck in a reboot loop, so keep an eye on things or don't put the files in the Startup folder and instead save that for a stable cgminer configuration -- and be sure to set the gpustopclock and memstopclock to appropriate values.

My recommendation would be to choose a reasonable starting memory clock (around 1300 is usually safe on all R9 290/290X GPUs) and run the engine-clock-test-r9version batch file. When that finishes (or reaches a point where it cannot continue), look at the AvgHashrateGPU.txt file and you should end up with one of to things. Eiher you find out how far you can push clocks before becoming unstable and crashing (with each increase in clock speed bringing improved performance), and in that case I'd probably back off 10-25MHz from the point where the GPU crashed, but you can do as you please. The other possibility is that you'll find hash rates peak at a lower clock speed (say, 825-850MHz), and as you try going higher the AMD GPU will begin to throttle automatically. If this is happening, use the clock speed that gives you the highest hash rate.

Once you've found a good GPU clock, set the gpuclock=800 line in the second batch file, memory-clock-test-r9version, to that clock speed and then run the second script. It will do the same thing as before, except now RAM clocks go up 10MHz every five minutes until you reach the stopping clock speed (1700MHz is what I put in) or you crash -- and a crash is far more likely if you try for 1700MHz GDDR5! Check your AvgHashrateRAM.txt file for the best result and use that for your GPU, and then go run the Thread Concurrency optimization batch file and find the best TC for your system.

Here's the tricky part: you need to do the above for each and every GPU in your system(s) if you want to get optimal performance, while means you also need to tweak the miner-tc-r9version.bat file and add "--device [Number]" to the cgminer.exe command for each GPU. You might not need to do this for Thread Concurrency, but for the Engine and RAM GPU clocks it will definitely help out! Also, once you find values for each GPU that work well, you may find that running all your GPUs at once will require slightly lower clocks in order to be stable (which potentially could mean you need to check TC again, though that's probably overkill).

Now all we need is for more R9 GPUs to be available at reasonable prices -- I'm seeing prices of $700 for R9 290 and $830 for R9 290X right now! And Newegg isn't really any better last I checked (well, maybe a bit better, but still price gouging). If you've already got yourself some shiny R9 290 GPUs, happy mining while everyone else is stuck waiting!

Donations and referrals gladly accepted if this helps you out:
LTC: LXpEZcNJtikd263z7Ha3vrdYDcLU7hiKWv

CGMiner Optimal Thread Concurrency for R9 290/290X

Continuing from my previous post, I've now created a batch file to help find the optimal Thread Concurrency setting for R9 290/290X systems. The difficulty with doing this stems from the fact that normally exiting CGMiner on Windows with the new GPUs will cause a BSOD on most (all?) systems, so you can't use my other batch files. They work great on HD 7970/R9 280X and earlier systems, though, and last night I managed to increase my HD 7950 test system by 20KHash/sec per GPU. So how do we deal with R9 290/290X? We tweak things a bit and end up with some new batch files, which you can download via my Dropbox.

Instructions:

Extract the contents of that Zip file to your CGMiner folder (Windows only right now). There are five files inside, including three EXE files, but nothing dangerous; here's the quick summary of the EXE files.

Sleep.exe is a program that can be used in batch files to pause for a set amount of time (e.g. 300 seconds = "sleep 300").

Grep.exe is a common Unix program that allows you to search through files for matching strings; you can use "find" on Windows, but the output of CGMiner messes find up because it includes special characters.

Tail.exe is the last executable and it's also a port from Unix; it allows you to output the last few lines from a file (or a command); so "tail -1" gives the last line from a file or command.

I use the above three files in the batch files to help with creating a useful summary of the mining results for each thread concurrency. The two batch files are similar to before, but with some tweaks. Here's what they contain if you don't want to download:

thread-concurrency-test-r9version.bat
@echo off
set threadconcurrency=18000
set gpuclock=900
set memclock=1400
set gpufan=50-75
set gpuvolt=1.100
set gpupowertune=50

if exist currenttc.txt (
  for /F %%x in (currenttc.txt) do set threadconcurrency=%%x
)

:startloop
echo Current TC is %threadconcurrency%
echo %threadconcurrency%> currenttc.txt
start "MinerThread" miner-tc-r9version.bat %threadconcurrency% %gpuclock% %memclock% %gpufan% %gpuvolt% %gpupowertune%
sleep 300
taskkill /im cgminer.exe /f
<nul set /p =%threadconcurrency%: >> AvgHashrateTC.txt
grep -i "(avg)" %threadconcurrency%.txt | tail -1 >> AvgHashrateTC.txt
set /a threadconcurrency=threadconcurrency+64

goto :startloop
miner-tc-r9version.bat
@echo off
set threadconcurrency=%1
set gpuclock=%2
set memclock=%3
set gpufan=%4
set gpuvolt=%5
set gpupowertune=%6
cgminer --scrypt -o stratum+tcp://coinotron.com:3334 -u trogdorjw73.tester -p tester -w 256 -v 1 -I 20 -g 1 -T --gpu-engine %gpuclock% --gpu-memclock %memclock% --gpu-fan %gpufan% --gpu-vddc %gpuvolt% -- --temp-target 80 --temp-overheat 95 --temp-cutoff 99 --thread-concurrency %threadconcurrency% > %threadconcurrency%.txt
exit
The first files starts with some variables you can modify for clock speeds, starting thread concurrency, voltage, fan speed, and powertune. It the calls the second file (passing the variables along), which actually starts CGMiner running. Because we can't let CGMiner exit gracefully without a BSOD, the first file waits 300 seconds after starting the second file and then kills the CGMiner.exe process, at which point it uses the output from the mining results and grabs the last average hash rate, which ends up in a text file called AvgHashrateTC.txt.

So to use this, you first need to delete (or at least rename) your cgminer.conf file in your CGMiner folder, then extract the Zip file to the directory and just run thread-concurrency-test-r9version.bat and walk away (though you might want to tweak the clocks or other settings first). Come back in a day or so and look at your averages and you'll see something like the following:
18000: (29s):1.398M (avg):1.569Mh/s | A:640   R:0    HW:627  WU:616.8/m
18064: (29s):1.368M (avg):1.565Mh/s | A:1600  R:0    HW:710  WU:610.6/m
18128: (29s):1.264M (avg):1.585Mh/s | A:1600  R:0    HW:537  WU:608.4/m
18192: (29s):1.330M (avg):1.536Mh/s | A:1600  R:0    HW:600  WU:685.5/m
18256: (29s):1.409M (avg):1.575Mh/s | A:1920  R:320  HW:347  WU:707.8/m
18320: (29s):1.339M (avg):1.544Mh/s | A:2240  R:0    HW:467  WU:626.2/m
18384: (29s):537.3K (avg):1.357Mh/s | A:640   R:0    HW:384  WU:681.4/m
....
If all goes well, you will have a lot more lines than the above, but it's possible your system will crash during the testing. To get around that, the currently tested TC is spit out to a file which gets read when the first batch file starts. If you create a shortcut to thread-concurrency-test-r9version.bat and put that in your Startup folder, even after a crash/reboot the testing will pick up where it left off.

In the meantime, based on more experience with the GPUs, I'm recommending the Radeon R9 290 over the R9 290X for Windows users -- you can probably get closer to 1000KHash/sec on the 290X with Linux, but on Windows it can be rather difficult. Also, the default voltage used on your GPU will affect your ability to hit higher clocks and hash rates -- lower voltages being better.

Donations gladly accepted if this helps you out:
LTC: LXpEZcNJtikd263z7Ha3vrdYDcLU7hiKWv
Go win some LTC!

Finding Optimal Litecoin Mining Settings

Tuning your Litecoin mining system to get ideal performance can be a royal pain in the rear -- this I know from personal experience. Settings that work great for one person can end up being terrible for another individual. So if you've just bought a shiny new Radeon R9 290 or R9 290X (or any other GPU for that matter) and you're trying to get better hash rates, here's the general plan of attack for getting optimal mining performance from your system:
  1. Ideally you want to mine at intensity 20, as that will result in the fastest performance, but the system will not really be usable for other work.
  2. Start at reasonable settings and then start increasing GPU clocks and memory clocks until your system becomes unstable.
  3. You'll probably need to play with fan speeds and/or voltages in the process of tuning.
  4. Once you've found the clocks that your GPU will handle, start looking for the optimal thread concurrency setting.
Needless to say, dialing things in can take days if not weeks, and every crash and restart can be maddening. I'm trying to build a set of batch files to automate things under Windows. Here's what I have so far, for finding an optimal thread concurrency setting. You need to put the two batch files in your CGminer folder, without any active cgminer.conf file.

ThreadConcurrency.bat:
@echo off
set threadconcurrency=18000
:startloop
echo Current TC is %threadconcurrency%
start /wait "MinerThread" miner-tc.bat %threadconcurrency%
<nul set /p =%threadconcurrency%:  >> AvgHashrateTC.txt
type %threadconcurrency%.txt  | find /i "average hashrate" >> AvgHashrateTC.txt
set /a threadconcurrency=threadconcurrency+64
goto :startloop
miner-tc.bat:
@echo off
set threadconcurrency=%1
cgminer --scrypt -o stratum+tcp://coinotron.com:3334 --shares 5  -u trogdorjw73.tester -p tester -w 256 -v 1 -I 20 -g 1 -T --gpu-engine 965 --gpu-fan 70 --gpu-memclock 1550 --gpu-vddc 1.075 --temp-target 85 --temp-overheat 95 --temp-cutoff 99 --thread-concurrency %threadconcurrency% > %threadconcurrency%.txt
exit
Place those two files into your cgminer folder and then run ThreadConcurrency.bat (tweaking as needed for your mining pool, temps, etc.) and walk away. Your PC will run through five shares at each thread concurrency setting and spit out the result to a file called "AvgHashrateTC.txt", and you can look at that in the morning after running the batch file all night (or in the evening after running it all day if you prefer).

There's a catch, of course: I set the above to do five shares, and sometimes you'll get lucky or unlucky so hash rates can be higher/lower. Setting the shares value higher (like 20 or 30) would take longer to get through a sequence but it would be more accurate. When you're fine tuning that's worth a look, and maybe you could even change the increment from "+64" to "+32" or "+16" -- or even "+1" if you think that might help.

You can use the same approach for clock speeds as well, but you'll probably want a maximum clock (or just let it go until your PC reboots). I'll post some batch files for that tomorrow. Also note that on the R9 290/290X cards under Windows, when cgminer exits it often causes a BSOD -- no fun! I'm not sure if that's drivers or cgminer 3.7.2; I need to try poking around a bit, but it's a real irritant. Closing the window with the X in the corner avoids the problem, but that doesn't work with CGWatcher or my batch files above.

If you find this useful, go ahead and run the files as above and I'll get a few mining shares during your testing. Optionally, feel free to donate to my blogging efforts by shopping online or via LTC donations. Or win some for free and give me a commission.

LTC: LXpEZcNJtikd263z7Ha3vrdYDcLU7hiKWv

Sunday, May 5, 2013

Detailed Settings for ~600kHash/sec Litecoin with Radeon 7950

So I have a few Litecoin mining rigs running, and the latest has three Radeon HD 7950 cards in it. I detailed most of the hardware in my previous post, but this time I wanted to provide some clear steps and settings for mining that get close to 600kHash/sec on a single 7950. If you look at a list of scores, for example this list, you might think hitting 600kHash is trivial. Well, I suppose it can be, but don't expect it to happen by just running with the default settings. Here's what I ended up doing to get there.

First, my latest HD 7950 cards are from Sapphire, this time the dual-fan model with a stock clock of 925MHz on the cores. (As far as I can tell, that's the stock clock and not the Boost Clock.) They're available for $300 each, and they come with the Never Settle Reloaded bundle of Bioshock Infinite, Crysis 3, and Far Cry: Blood Dragon -- you can typically get close to $50 for the bundle via eBay. As I already have three other Radeon 7950 cards, you'd think I have a decent handle on settings by now, but I'm still tweaking and learning.

My main PC has a single 7950 in it, and I game occasionally on this system. I also use it to surf the web, email, write, etc. If you're not using a PC that's mining Litecoin, you can go for Intensity 20, but for a PC that you're actually trying to use for other things you'll never be able to use it properly with Intensity more than 13. So, I have two folders, with two different CGminer configuration files: one for when I'm not using the PC, and the other for when I'm working. The Intensity 13 version gets about 10-15% less hashing performance, but there's a catch: I'm using practically all of the GPU's 3GB of RAM! With a single thread, I get around 330kHash, but with two threads I'm at 510kHash. Here are the two cgminer.conf files I'm running on my "daily use" PC:

cgminer.conf Usable:
{
"pools" : [
{
"url" : "coinotron.com:3334",
"user" : "[USER].[WORKER]",
"pass" : "[PASS]"
},
{
"url" : "newlc.ozco.in:9332",
"user" : "[USER].[WORKER]",
"pass" : "[PASS]"
}
],

"intensity" : "13",
"vectors" : "1",
"worksize" : "256",
"lookup-gap" : "2",
"thread-concurrency" : "17920",
"shaders" : "1792",

"gpu-engine" : "900-1025",
"gpu-fan" : "40-100",
"gpu-memclock" : "1550",
"gpu-powertune" : "20",
"gpu-vddc" : "1.100",
"temp-cutoff" : "99",
"temp-overheat" : "95",
"temp-target" : "80",

"api-port" : "4028",
"expiry" : "120",
"failover-only" : true,
"gpu-threads" : "2",

"log" : "5",
"queue" : "1",
"scan-time" : "60",
"temp-hysteresis" : "3",

"scrypt" : true,
"kernel" : "scrypt",
"kernel-path" : "/usr/local/bin"
}

cgminer.conf High Hashing:
{
"pools" : [
{
"url" : "coinotron.com:3334",
"user" : "[USER].[WORKER]",
"pass" : "[PASS]"
},
{
"url" : "newlc.ozco.in:9332",
"user" : "[USER].[WORKER]",
"pass" : "[PASS]"
}
],

"intensity" : "20",
"vectors" : "1",
"worksize" : "256",
"lookup-gap" : "2",
"thread-concurrency" : "21712",
"shaders" : "1792",

"gpu-engine" : "900-1025",
"gpu-fan" : "40-100",
"gpu-memclock" : "1550",
"gpu-powertune" : "20",
"gpu-vddc" : "1.100",
"temp-cutoff" : "99",
"temp-overheat" : "95",
"temp-target" : "80",

"api-port" : "4028",
"expiry" : "120",
"failover-only" : true,
"gpu-threads" : "1",

"log" : "5",
"queue" : "1",
"scan-time" : "60",
"temp-hysteresis" : "3",

"scrypt" : true,
"kernel" : "scrypt",
"kernel-path" : "/usr/local/bin"
}
That might seem like a pretty simple configuration for some, but let me run through some of the specifics. First, the "Usable" configuration has thread-concurrency at 17920. I arrived at that number by trying different values until I could get cgminer to start; I think I'm hitting maximum RAM use perhaps, though maybe I could increase it slightly. Either way, it's not running much faster I don't think so I leave it alone. The second configuration file is basically what you often see recommended for Radeon 7950, but I usually see talk of 650+ kHash, which is only going to happen with some serious overclocking and tuning!

There's more to starting CGminer going than the above, however. First, nearly all of my 7950 cards have default voltages that are far too high to run reliably without water cooling, at least in my ~75F environment. The dual-fan Sapphire cards for instance all come set to 1.250V, but under mining load even at lower intensities I can hit 95C and higher on some of the cards. What's more, three of the cards at 1.250V running slightly overclocked settings consume 1000W and more from the outlet, with an 80 Plus Platinum PSU even. Wow! The trick for me has been undervolting and overclocking, which isn't what you'd immediately expect.

MSI Afterburner is a great little utility for overclocking and undervolting, but it doesn't work with all cards -- the dual-fan Sapphire cards for instance don't allow voltage adjustments with it. Sapphire has their own TRIXX utility that works with their cards, however, so that's what I used. Here are my standard settings for reasonably reliable operation:
Vcore: 1.100V
GPU Clock: 1025MHz
RAM Clock: 1550MHz (6200MHz effective)
PowerTune: +10 (or +20 -- this doesn't seem to matter much)
I've managed to use those settings successfully on six different Radeon HD 7950 cards now, so I'm pretty confident they'll work for most users (at least if you're in a decent climate -- if the room is above 85F, you'll probably have issues). Okay, that gives us the overclock/undervolt settings as well as CGminer settings, so we're done, right? Not quite!

The final step is launching CGminer properly. For that, I created a batch file (a sequence of commands for Windows to run). Since I have CGminer starting up with Windows, I had to play around a bit. MSI Afterburner (or Sapphire TRIXX) is set to load automatically and restore my clocks, but depending on the PC this can take 10-30 seconds before it's complete (more on a slower CPU/HDD). If CGminer launches before the clocks and voltage are set properly, there's a very good chance your PC will crash and require a hard reboot! The other lines are to ensure the thread-concurrency options work properly, and then to tell CGminer to automatically tune fan speed. Here's the batch file (paste this into "LaunchCGminer.bat"):
@echo off
set GPU_MAX_ALLOC_PERCENT=100
setx GPU_MAX_ALLOC_PERCENT 100
@ping 1.1.1.1 -n 1 -w 30000>nul
cgminer.exe --auto-fan --failover-only
Create a shortcut to that batch file and place it in C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup and you should be set. But there are a few final items to mention! I have two different CGminer (currently 3.1.0) folders, one for high intensity and one for low intensity. There appears to be a bug with AMD's drivers or CGminer or something, with the result being that if I run CGminer, quit, run it again, quit, etc. then maybe on the third or fourth cycle I usually get a system crash. Ugh. So rebooting between runs is often required. Also, you'll want to close out of most other programs (especially your web browser!) before starting CGminer, as if it can't get enough VRAM it won't run properly. Oddly, after it's started and working well, you can start Firefox, Chrome, etc. without issue. Also also, if you run Photoshop, I suggest just exiting CGminer until you're done -- it's not worth the potential hassle, trust me!

I think that's it for now. Happy Litecoin mining! My latest build is named "Frankenmine" because it's sort of in a disassembled mess right now while I wait for a few more pieces to arrive (specifically the PCIe slot extenders). It's definitely not safe for kids to be around at this point in time! If there's interest, I can provide the cgminer.conf files for this as well, and I have some other stories to relate involving the joys of Linux. But for now, this is what I'm using to get ~1800kHash/sec:
As always, if you find this stuff useful, please feel free to kick a few digital pennies my way!

BTC: 1JSrAuxPUhD2rS6yYLiPPT6X8fvz7c7k1W
LTC: LXpEZcNJtikd263z7Ha3vrdYDcLU7hiKWv

Or if donating directly is too much, go play at the LTC4You faucet and typically win 0.04 LTC every hour. That's a free $1.20 for clicking a button and typing a captcha. :-)

Update: Need help? See my Toubeshooting Guide.