As an Amazon Associate I earn money from qualifying purchases.

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

13 comments:

  1. cgminer chrashes at once when I start the bat file.
    works perfectly with this settings: -g 1 -w 512 --lookup-gap 2 --thread-concurrency 24500 -I 19 --auto-fan --gpu-fan 30-80 --temp-cutoff 99 --temp-overheat 90 --temp-target 95 --gpu-engine 1000 --gpu-memclock 1500 --gpu-powertune 20

    ReplyDelete
    Replies
    1. So you probably need to adjust the starting clocks and the miner-tc file for some of your settings. (Incidentally, -w 512 means nothing -- it's the same as -w 256. Look at the Scrypt BIN files and you can see w256 still.)

      set threadconcurrency=20000
      set gpuclock=1000
      set memclock=1500
      set gpufan=30-80
      set gpuvolt=1.150
      set gpupowertune=20
      set gpustopclock=1100

      Which batch file are you running right now?

      Delete
    2. I found The problem The same night. It was The specified voltage

      Delete
  2. Have you tried running these configs using GUIminer-scrypt ?

    ReplyDelete
  3. Great article!!

    I'm now running 908KH/s on my stock Sapphire R9 290!! :D It's been running for over 12 hours at that speed. cgminer says it's doing avg 908KH/s, but my pool is stating I'm over 924KH/s and still climbing after averaging out over the past 24 hours, 3 of which I was not mining when I was changing settings/etc

    I used the scripts, took me about 36 hours to get the settings fully "tuned-in" how I wanted...LOL! I did however change out the miner user settings because I knew it would take a long time to test it out (sorry). But I do plan on directly donating for your efforts at this!

    I'm a programmer myself but have never really delved into batch script programming, so it was cool to learn a little bit there. I updated the script files for my purpose & added a countdown timer window for each iteration (and reduced from 5 min to 3.5 min), as well as a watch window (tail log file) to see what the miner was doing during each iteration. I was shocked to find out that the engine core didn't need to be "maxed out" to get the best results. Mine ran fine up to about 1080MHz before crashing the GPU. Similar results with the memclock

    Anyway, my optimal settings ended up being:
    "auto-fan" : true,
    "gpu-vddc" : "1.100",
    "thread-concurrency" : "22400",
    "gpu-engine" : "1040",
    "gpu-memclock" : "1488",
    "lookup-gap" : "2",
    "gpu-powertune" : "50",
    "gpu-threads" : "1",
    "shaders" : "2560",
    "intensity" : "20",
    "gpu-fan" : "67-85",
    "temp-cutoff" : "96",
    "temp-overheat" : "91",
    "temp-target" : "85",
    "temp-hysteresis" : "3",
    "log" : "5",
    "queue" : "1",
    "scan-time" : "5",
    "scrypt" : true

    I've found that setting my minimum fan speed at 67% keeps it cool enough that it rarely has to throttle up above 70% and keeps it a "cool" 85*C without having to spin up/down much at all. Mine is just sitting on a cardboard box right now, but went to Lowes last night to get some aluminum angle to build a frame.

    Files after my modifications: https://drive.google.com/file/d/0B9E7RM4DXnozODNwZDNNYnZiU00/edit?usp=sharing

    I only updated the logic in the files after doing the concurrency test because it was taking so long and I like having feedback on the process... But went back and changed the others. If you (or anyone) else has any issues with them they should be easy to fix :)

    If anyone would like to donate for my setting contributions please feel free! :D
    LTC: LWHgLSxi3iLHGQ4ESME6Tj4STcpX5p3yTD

    ReplyDelete
    Replies
    1. there is some countseconds.bat which is called but missing in your files

      Delete
  4. hey there,

    I ran the tool for GPU setting. works good. one thing though, in the txt output file, I don't get one result line per speed setting, but a whole bunch of them?

    ReplyDelete
    Replies
    1. Yeah, it's basically due to the way cgminer spits out results -- there's a missing NEWLINE character after each current average, even with -T specified. Most of the averages should be pretty similar though.

      Delete
  5. This comment has been removed by a blog administrator.

    ReplyDelete
    Replies
    1. The worksize can be set to 64, 128, or 256 -- anything other than that and it goes to the default (256). That's my understanding at least; I haven't looked at the source code to verify what the setting does.

      Delete
  6. (Shaders * Core in Ghz) * 0.34 = Expected Kh/s

    R9 280x = 2048 Shaders

    2048 * 1.02 * 0.34 = 710kh/s

    This should help you fine tune more - if your clock speed doesnt match this formula it means your not fine tuned.

    HTH

    ReplyDelete
  7. Hi Unknown... I haven't done anything with these files in about four years, and the various hashing algorithms and such have changed quite a bit since then. Sorry. Hope you can figure out what needs to be tweaked!

    ReplyDelete
  8. So the way this worked back in the day is that it would set some mining parameters in environment variables, which would get passed to cgminer, and then the mining would start and run for 300 seconds. Then the process would get killed off and the last line of the file would show the average hashrate.

    Then the clocks for the VRAM or GPU would increment and the test would run again -- or the threadcount parameter would increment and the test would run again.

    The theory was you would let it run overnight to find optimal values. Each line would show the hashrate for the various settings that were used.

    Switching to sgminer, some of the parameters I passed to cgminer may no longer work properly, and I don't know if the sgminer output would work either. I'd have to look at the current mining programs and probably rework some of the 'logic' to make things run properly.

    What exactly are you trying to determine -- clockspeeds, or some other setting? And the coin/hashing algorithm you're using would matter as well.

    ReplyDelete