Author Topic: CGMINER CPU/GPU Miner  (Read 35263 times)

Offline maplesyrupghost

CGMINER CPU/GPU Miner
« on: November 05, 2011, 04:27:44 am »
CGMINER CPU/GPU miner overclock monitor fanspeed in C linux/windows/osx 2.0.7
bitcointalk.org thread

combined gpu and cpu miner written in c, cross platform for windows, linux and osx, based on the original code cpuminer.

This code is provided entirely free of charge by the programmer in his spare
time so donations would be greatly appreciated. Please consider using the
--donation feature or donate directly to the address below.

Help can also be obtained on IRC: irc.freenode.net #cgminer
READ THE README INCLUDED IN THE ARCHIVE.

Features:
- Very low overhead free c code for Linux and windows with very low non-mining CPU  and ram usage
- Custom modified phatk and poclbm kernels
- BFI_INT patching
- VECTOR support
- Binary loading of kernels (fast startup)
- long poll support - will use longpoll from any pool if primary pool does not support it
- Self detection of new blocks with a mini-database for slow/failing longpoll scenarios, maximum work efficiency and minimum rejects.
- Heavily threaded code hands out work retrieval and work submission to separate threads to not hinder GPUs working
- Caching of submissions during transient network outages
- Preemptive fetching of work prior to completion of current work
- Local generation of more valid work (ntime rollover) whenever possible, as supported on a per-work item basis
- Prevention of stale work submission on new block
- Multi GPU support (all or discrete selection)
- CPU mining support (disabled when GPU is detected unless explicitly re-enabled)
- Summarised and discrete device data statistics of requests, accepts, rejects, hw errors, efficiency and utility
- Watchdog thread to restart idle threads but not crash machine if they don't respond
- Dynamic intensity that keeps desktop interactive under load and maximises throughput when deskop idle
- Summary displayed when quitting
- Supports multiple pools with multiple intelligent failover mechanisms
- On the fly menu based management of most settings
- Trickling of extra work to backup pools if primary pool is responding but slow
- On the fly enabling/disable/restarting of GPUs
- INTEGRATED GPU MONITORING, OVERCLOCKING AND FANCONTROL
- Auto fan and GPU clocking
- Lots of other stuff I can't remember. See options.

Sample output:
Code: [Select]
cgminer version 2.0.0 - Started: [2011-09-09 12:11:32]
--------------------------------------------------------------------------------
 (5s):1713.6 (avg):1707.8 Mh/s | Q:301  A:729  R:8  HW:0  E:242%  U:22.53/m
 TQ: 7  ST: 8  SS: 0  DW: 15  NB: 3  LW: 984  GF: 1  RF: 4  I: 9
 Connected to http://ozco.in:8332 with LP as user ckolivas.0
 Block: 000008867dd9ba4044c87be3d1f2a0a9...  Started: [12:29:30]
--------------------------------------------------------------------------------
 [P]ool management [G]PU management [S]ettings [D]isplay options [Q]uit
 GPU 0: 73.0C 4491RPM | 432.7/427.4Mh/s | A:199 R:0 HW:0 U:6.15/m
 GPU 1: 72.0C 4017RPM | 428.9/427.4Mh/s | A:183 R:1 HW:0 U:5.66/m
 GPU 2: 73.5C 4248RPM | 418.8/427.5Mh/s | A:176 R:5 HW:0 U:5.44/m
 GPU 3: 74.0C 3409RPM | 426.7/427.4Mh/s | A:173 R:2 HW:0 U:5.35/m
--------------------------------------------------------------------------------

[2011-09-09 12:39:51] Accepted 6e92c4f1 GPU 1 thread 5 pool 0
[2011-09-09 12:39:53] Accepted 6d1b5803 GPU 2 thread 2 pool 0
[2011-09-09 12:39:54] Accepted 62a35d0a GPU 0 thread 0 pool 0

Pool menu:
Code: [Select]
0: Enabled Alive Priority 0: http://ozco.in:8332  User:ckolivas.2
1: Enabled Alive Priority 1: http://bitcoinpool.com:8334  User:ckolivas
2: Disabled Alive Priority 2: http://127.0.0.1:8332  User:con

Current pool management strategy: Load Balance
[A]dd pool [R]emove pool [D]isable pool [E]nable pool
[C]hange management strategy [S]witch pool [I]nformation
Or press any other key to continue

GPU menu:
Code: [Select]
GPU 0: 426.7 / 427.9 Mh/s | A:199  R:0  HW:0  U:6.09/m
72.5 C  F: 50% 4490 RPM)  E: 950 MHz  M: 825 Mhz  V: 1.175V  A: 99% P: 20%
Last initialised: [2011-09-09 12:11:33]
Thread 0: 227.4 Mh/s Enabled ALIVE
Thread 4: 226.1 Mh/s Enabled ALIVE

GPU 1: 426.2 / 427.9 Mh/s | A:186  R:1  HW:0  U:5.69/m
72.5 C  F: 67% 4011 RPM)  E: 950 MHz  M: 825 Mhz  V: 1.175V  A: 99% P: 20%
Last initialised: [2011-09-09 12:11:33]
Thread 1: 213.6 Mh/s Enabled ALIVE
Thread 5: 214.2 Mh/s Enabled ALIVE

GPU 2: 430.9 / 428.0 Mh/s | A:178  R:5  HW:0  U:5.44/m
73.5 C  F: 47% 4247 RPM)  E: 950 MHz  M: 825 Mhz  V: 1.175V  A: 99% P: 20%
Last initialised: [2011-09-09 12:11:33]
Thread 2: 212.8 Mh/s Enabled ALIVE
Thread 6: 188.3 Mh/s Enabled ALIVE

GPU 3: 430.7 / 427.9 Mh/s | A:175  R:2  HW:0  U:5.35/m
73.5 C  F: 56% 3414 RPM)  E: 950 MHz  M: 825 Mhz  V: 1.175V  A: 99% P: 20%
Last initialised: [2011-09-09 12:11:33]
Thread 3: 214.8 Mh/s Enabled ALIVE
Thread 7: 215.1 Mh/s Enabled ALIVE

Change settings menu:
Code: [Select]
Select GPU to change settings on: 0
Temp: 72.0 C
Fan Speed: 50% (4489 RPM)
Engine Clock: 950 MHz
Memory Clock: 825 Mhz
Vddc: 1.175 V
Activity: 99%
Powertune: 20%
Fan autotune is enabled (0-85)
GPU engine clock autotune is enabled (880-950)
Change [A]utomatic [E]ngine [F]an [M]emory [V]oltage [P]owertune
Or press any other key to continue

Settings menu:
Code: [Select]
[D]ynamic mode: Off
[L]ongpoll: On
[I]ntensity: 8
[Q]ueue: 0
[S]cantime: 60
[R]etries: -1
[P]ause: 5
Select an option or any other key to return

Display menu:
Code: [Select]
[D]ebug:off [S]ilent:off [V]erbose:off [R]PC debug:off [L]og interval:5
[N]ormal [C]lear
Select an option or any other key to return

On exiting:
Code: [Select]
Summary of runtime statistics:

Started at [2011-07-19 14:40:09]
Runtime: 2 hrs : 31 mins : 18 secs
Average hashrate: 1680.1 Megahash/s
Queued work requests: 3317
Share submissions: 3489
Accepted shares: 3489
Rejected shares: 0
Reject ratio: 0.0
Hardware errors: 0
Efficiency (accepted / queued): 105%
Utility (accepted shares / min): 23.06/min

Discarded work due to new blocks: 0
Stale submissions discarded due to new blocks: 9
Unable to get work from server occasions: 16
Work items generated locally: 330
Submitting work remotely delay occasions: 33
New blocks detected on network: 10

Pool: http://ozco.in:8332
 Queued work requests: 3253
 Share submissions: 3426
 Accepted shares: 3426
 Rejected shares: 0
 Reject ratio: 0.0
 Efficiency (accepted / queued): 105%
 Discarded work due to new blocks: 0
 Stale submissions discarded due to new blocks: 9
 Unable to get work from server occasions: 15
 Submitting work remotely delay occasions: 33

Pool: http://bitcoinpool.com:8334
 Queued work requests: 64
 Share submissions: 63
 Accepted shares: 63
 Rejected shares: 0
 Reject ratio: 0.0
 Efficiency (accepted / queued): 98%
 Discarded work due to new blocks: 0
 Stale submissions discarded due to new blocks: 0
 Unable to get work from server occasions: 1
 Submitting work remotely delay occasions: 0

Summary of per device statistics:

 GPU 0: [419.9 Mh/s] [Q:913  A:901  R:0  HW:0  E:99%  U:5.96/m]
 GPU 1: [420.1 Mh/s] [Q:912  A:865  R:0  HW:0  E:95%  U:5.72/m]
 GPU 2: [420.5 Mh/s] [Q:908  A:865  R:0  HW:0  E:95%  U:5.72/m]
 GPU 3: [419.6 Mh/s] [Q:910  A:858  R:0  HW:0  E:94%  U:5.68/m]

Command line options:

Usage: . [-atDdGCgIKklmpPQqrRsTouvwOchnV]
Options for both config file and command line:
--algo|-a <arg>     Specify sha256 implementation for CPU mining:
        auto            Benchmark at startup and pick fastest algorithm
        c               Linux kernel sha256, implemented in C
        4way            tcatm's 4-way SSE2 implementation
        via             VIA padlock implementation
        cryptopp        Crypto++ C/C++ implementation
        sse2_64         SSE2 64 bit implementation for x86_64 machines
        sse4_64         SSE4.1 64 bit implementation for x86_64 machines (default: sse2_64)
--auto-fan          Automatically adjust all GPU fan speeds to maintain a target temperature
--auto-gpu          Automatically adjust all GPU engine clock speeds to maintain a target temperature
--cpu-threads|-t <arg> Number of miner CPU threads (default: 4)
--debug|-D          Enable debug output
--device|-d <arg>   Select device to use, (Use repeat -d for multiple devices, default: all)
--disable-gpu|-G    Disable GPU mining even if suitable devices exist
--donation <arg>    Set donation percentage to cgminer author (0.0 - 99.9) (default: 0.0)
--enable-cpu|-C     Enable CPU mining with GPU mining (default: no CPU mining if suitable GPUs exist)
--expiry|-E <arg>   Upper bound on how many seconds after getting work we consider a share from it stale (default: 120)
--failover-only     Don't leak work to backup pools when primary pool is lagging
--gpu-threads|-g <arg> Number of threads per GPU (1 - 10) (default: 2)
--gpu-engine <arg>  GPU engine (over)clock range in Mhz - one value, range and/or comma separated list (e.g. 850-900,900,750-850)
--gpu-fan <arg>     GPU fan percentage range - one value, range and/or comma separated list (e.g. 0-85,85,65)
--gpu-memclock <arg> Set the GPU memory (over)clock in Mhz - one value for all or separate by commas for per card
--gpu-powertune <arg> Set the GPU powertune percentage - one value for all or separate by commas for per card
--gpu-vddc <arg>    Set the GPU voltage in Volts - one value for all or separate by commas for per card
--intensity|-I <arg> Intensity of GPU scanning (-10 -> 10, default: dynamic to maintain desktop interactivity)
--kernel-path|-K <arg> Specify a path to where the kernel .cl files are (default: "/usr/local/bin")
--kernel|-k <arg>   Select kernel to use (poclbm or phatk - default: auto)
--load-balance      Change multipool strategy from failover to even load balance
--log|-l <arg>      Interval in seconds between log output (default: 5)
--monitor|-m <arg>  Use custom pipe cmd for output messages
--no-adl            Disable the ATI display library used for monitoring and setting GPU parameters
--no-longpoll       Disable X-Long-Polling support
--no-restart        Do not attempt to restart GPUs that hang
--pass|-p <arg>     Password for bitcoin JSON-RPC server
--per-device-stats  Force verbose mode and output per-device statistics
--protocol-dump|-P  Verbose dump of protocol-level activities
--queue|-Q <arg>    Minimum number of work items to have queued (0 - 10) (default: 1)
--quiet|-q          Disable logging output, display status and errors
--real-quiet        Disable all output
--retries|-r <arg>  Number of times to retry before giving up, if JSON-RPC call fails (-1 means never) (default: -1)
--retry-pause|-R <arg> Number of seconds to pause, between retries (default: 5)
--rotate <arg>      Change multipool strategy from failover to regularly rotate at N minutes (default: 0)
--round-robin       Change multipool strategy from failover to round robin on failure
--scan-time|-s <arg> Upper bound on time spent scanning current work, in seconds (default: 60)
--sched-start <arg> Set a time of day in HH:MM to start mining (a once off without a stop time)
--sched-stop <arg>  Set a time of day in HH:MM to stop mining (will quit without a start time)
--shares <arg>      Quit after mining N shares (default: unlimited)
--submit-stale      Submit shares even if they would normally be considered stale
--syslog            Use system log for output messages (default: standard error)
--temp-cutoff <arg> Temperature where a GPU device will be automatically disabled, one value or comma separated list (default: 95)
--temp-hysteresis <arg> Set how much the temperature can fluctuate outside limits when automanaging speeds (default: 3)
--temp-overheat <arg> Overheat temperature when automatically managing fan and GPU speeds, one value or comma separated list (default: 85)
--temp-target <arg> Target temperature when automatically managing fan and GPU speeds, one value or comma separated list (default: 75)
--text-only|-T      Disable ncurses formatted screen output
--url|-o <arg>      URL for bitcoin JSON-RPC server
--user|-u <arg>     Username for bitcoin JSON-RPC server
--vectors|-v <arg>  Override detected optimal vector width (1, 2 or 4)
--verbose           Log verbose output to stderr as well as status output
--worksize|-w <arg> Override detected optimal worksize (default: 0)
--userpass|-O <arg> Username:Password pair for bitcoin JSON-RPC server
Options for command line only:
--config|-c <arg>   Load a JSON-format configuration file
See example-cfg.json for an example configuration.
--help|-h           Print this message
--ndevs|-n          Enumerate number of detected GPUs and exit
--version|-V        Display version and exit

---

Executive summary of how to use on dedicated miner on one pool:
cgminer -o http://poolurl:port -u username -p pass -I 9 --donation 0.5

First card regular desktop, 3 other dedicated cards:
cgminer -o http://pool:port -u username -p password -I d,9,9,9 --donation 0.5

Dedicated miner on two pools:
cgminer -o http://pool1url:port -u username1 -p pass1 -o http://pool2url:port -u username2 -p pass2 -I 9 --donation 0.5
(repeat entries for more, unlimited)

Desktop that also mines:
cgminer -o http://poolurl:port -u username -p pass --donation 0.5

Add overclocking settings, GPU and fan control for all cards:

cgminer -o http://pool:port -u username -p password -I 9 --auto-fan --auto-gpu --gpu-engine 850-950 --gpu-memclock 300 --donation 0.5

Add overclocking settings, GPU and fan control with different engine settings for 4 cards:

cgminer -o http://pool:port -u username -p password -I 9 --auto-fan --auto-gpu --gpu-engine 750-950,945,700-930,960 --gpu-memclock 300 --gpu-fan 25-85 --donation 0.5

READ WARNINGS AND DOCUMENTATION BELOW ABOUT OVERCLOCKING

---
Intensity of 9 is about the highest throughput for a 69xx, 8 for most other cards. Higher has no benefit on current cards (maybe more with next generation cards). Note that too high a setting can actually worsen throughput, so experiment, which you can do on the fly while it's running with the Settings menu. Specifying an intensity automatically disables the dynamic intensity feature.


FAILOVER STRATEGIES WITH MULTIPOOL:
A number of different strategies for dealing with multipool setups are
available. Each has their advantages and disadvantages so multiple strategies
are available by user choice, as per the following list:

FAILOVER:
The default strategy is failover. This means that if you input a number of
pools, it will try to use them as a priority list, moving away from the 1st
to the 2nd, 2nd to 3rd and so on. If any of the earlier pools recover, it will
move back to the higher priority ones.

ROUND ROBIN:
This strategy only moves from one pool to the next when the current one falls
idle and makes no attempt to move otherwise.

ROTATE:
This strategy moves at user-defined intervals from one active pool to the next,
skipping pools that are idle.

LOAD BALANCE:
This strategy sends work in equal amounts to all the pools specified. If any
pool falls idle, the rest will take up the slack keeping the miner busy.


---
FAQ:
What dependencies do I need on linux to build it?
libncurses, libncurses-dev, libcurl, libcurl-dev AMD ATI SDK.

Can I log the output to a file? Yes you can use the interfaced version and log at the same time, as the log goes to stderr. Start with your regular command line options and redirect stderr like this:
./cgminer -o xxx -u xxx -p xxx etc. 2>logfile.txt

It won't start, says something about no active pools: Check your login credentials are correct and that your URL includes both http:// and the port number.

It won't start, just seems to exit straight away: Make sure it has access to the kernel files.

CPU mining is slow: The windows build does not include the 64 bit assembly required to run fast.

CPU usage is high with GPU mining: On windows it might be due to the pthread implementation in use there. Setting affinity to one CPU will help. Linux is my primary platform, sorry.

CPU usage is high on linux: Problem with the the catalyst 11.7+ drivers. Stick to 11.6 for now till they sort it out.

---
OVERCLOCKING WARNING AND INFORMATION

AS WITH ALL OVERCLOCKING TOOLS YOU ARE ENTIRELY RESPONSIBLE FOR ANY HARM YOU
MAY CAUSE TO YOUR HARDWARE. OVERCLOCKING CAN INVALIDATE WARRANTIES, DAMAGE
HARDWARE AND EVEN CAUSE FIRES. THE AUTHOR ASSUMES NO RESPONSIBILITY FOR ANY
DAMAGE YOU MAY CAUSE OR UNPLANNED CHILDREN THAT MAY OCCUR AS A RESULT.

The GPU monitoring, clocking and fanspeed control incorporated into cgminer
comes through use of the ATI Display Library. As such, it only supports ATI
GPUs. Even if ADL support is successfully built into cgminer, unless the card
and driver supports it, no GPU monitoring/settings will be available.

Cgminer supports initial setting of GPU engine clock speed, memory clock
speed, voltage, fanspeed, and the undocumented powertune feature of 69x0+ GPUs.
The setting passed to cgminer is used by all GPUs unless separate values are
specified. All settings can all be changed within the menu on the fly on a
per-GPU basis.

For example:
--gpu-engine 950 --gpu-memclock 825

will try to set all GPU engine clocks to 950 and all memory clocks to 825,
while:
--gpu-engine 950,945,930,960 --gpu-memclock 300

will try to set the engine clock of card 0 to 950, 1 to 945, 2 to 930, 3 to
960 and all memory clocks to 825.

AUTO MODES:
There are two "auto" modes in cgminer, --auto-fan and --auto-gpu. These can
be used independently of each other and are complementary. Both auto modes
are designed to safely change settings while trying to maintain a target
temperature. By default this is set to 75 degrees C but can be changed with:

--temp-target
e.g.
--temp-target 80
Sets all cards' target temperature to 80 degrees.

--temp-target 75,85
Sets card 0 target temperature to 75, and card 1 to 85 degrees.

AUTO FAN:
e.g.
--auto-fan (implies 85% upper limit)
--gpu-fan 25-85,65 --auto-fan

Fan control in auto fan works off the theory that the minimum possible fan
required to maintain an optimal temperature will use less power, make less
noise, and prolong the life of the fan. In auto-fan mode, the fan speed is
limited to 85% if the temperature is below "overheat" intentionally, as
higher fanspeeds on GPUs do not produce signficantly more cooling, yet
significanly shorten the lifespan of the fans. If temperature reaches the
overheat value, fanspeed will still be increased to 100%. The overheat value
is set to 85 degrees by default and can be changed with:

--temp-overheat
e.g.
--temp-overheat 75,85
Sets card 0 overheat threshold to 75 degrees and card 1 to 85.

AUTO GPU:
e.g.
--auto-gpu --gpu-engine 750-950
--auto-gpu --gpu-engine 750-950,945,700-930,960

GPU control in auto gpu tries to maintain as high a clock speed as possible
while not reaching overheat temperatures. As a lower clock speed limit,
the auto-gpu mode checks the GPU card's "normal" clock speed and will not go
below this unless you have manually set a lower speed in the range. Also,
unless a higher clock speed was specified at startup, it will not raise the
clockspeed. If the temperature climbs, fanspeed is adjusted and optimised
before GPU engine clockspeed is adjusted. If fan speed control is not available
or already optimal, then GPU clock speed is only decreased if it goes over
the target temperature by the hysteresis amount, which is set to 3 by default
and can be changed with:
--temp-hysteresis
If the temperature drops below the target temperature, and engine clock speed
is not at the highest level set at startup, cgminer will raise the clock speed.
If at any time you manually set an even higher clock speed successfully in
cgminer, it will record this value and use it as its new upper limit (and the
same for low clock speeds and lower limits). If the temperature goes over the
cutoff limit (95 degrees by default), cgminer will completely disable the GPU
from mining and it will not be re-enabled unless manually done so. The cutoff
temperature can be changed with:

--temp-cutoff
e.g.
--temp-cutoff 95,105
Sets card 0 cutoff temperature to 95 and card 1 to 105.


CHANGING SETTINGS:
When setting values, it is important to realise that even though the driver
may report the value was changed successfully, and the new card power profile
information contains the values you set it to, that the card itself may
refuse to use those settings. As the performance profile changes dynamically,
querying the "current" value on the card can be wrong as well. So when changing
values in cgminer, after a pause of 1 second, it will report to you the current
values where you should check that your change has taken. An example is that
6970 reference cards will accept low memory values but refuse to actually run
those lower memory values unless they're within 125 of the engine clock speed.
In that scenario, they usually set their real speed back to their default.

Cgminer reports the so-called "safe" range of whatever it is you are modifying
when you ask to modify it on the fly. However, you can change settings to values
outside this range. Despite this, the card can easily refuse to accept your
changes, or worse, to accept your changes and then silently ignore them. So
there is absolutely to know how far to/from where/to it can set things safely or
otherwise, and there is nothing stopping you from at least trying to set them
outside this range. Being very conscious of these possible failures is why
cgminer will report back the current values for you to examine how exactly the
card has responded. Even within the reported range of accepted values by the
card, it is very easy to crash just about any card, so it cannot use those
values to determine what range to set. You have to provide something meaningful
manually for cgminer to work with through experimentation.

STARTUP / SHUTDOWN:
When cgminer starts up, it tries to read off the current profile information
for clock and fan speeds and stores these values. When quitting cgminer, it
will then try to restore the original values. Changing settings outside of
cgminer while it's running may be reset to the startup cgminer values when
cgminer shuts down because of this.

---
This code is provided entirely free of charge by the programmer in his spare
time so donations would be greatly appreciated, either with the --donation feature or directly to the address below.

---
LATEST NEWS EXCERPT

Version 2.0.7 - October 17, 2011

- Support work without midstate or hash1, which are deprecated in bitcoind 0.5+
- Go to kernel build should we fail to clCreateProgramWithBinary instead of
failing on that device. This should fix the windows problems with devices not
initialising.
- Support new configuration file format courtesy of Chris Savery which can write
the config file from the menu and will load it on startup.
- Write unix configuration to .cgminer/cgminer.conf by default and prompt to
overwrite if given a filename from the menu that exists.

Donations: 148KkS2vgVi4VzUi4JcKzM2PMaMVPi3nnq
BitcoinTrading.com founder