Cgminer Source

Discussion in 'cgminer' started by SG-O, Jan 26, 2016.

  1. 2017/12/15 - Decred v1.1.2 released! → Release Notes  → Downloads
  1. SG-O

    SG-O Member
    Developer

    Jan 13, 2016
    104
    86
    Male
    Software Dev
    Milky Way
    #1 SG-O, Jan 26, 2016
    Last edited: Jan 27, 2016
    The CGMiner for Decred has just arrived on GitHub!
    My question is, if its ready to build and run or if it's still missing several major components?
    If I'm not mistaken we are still missing the Decred Core Client to start mining. Any information about that available yet?

    Anything about the new Miner can be posted below!

    #Edit1: Changed title to differentiate from compiled miner thread.
     
    Freemind, Skralg and tacotime like this.
  2. tacotime

    tacotime Hero Member

    Dec 7, 2015
    410
    1,133
    You can build and benchmark it. It's ready.
     
    Rune S and SG-O like this.
  3. davecgh

    davecgh Hero Member
    Developer Organizer

    Dec 31, 2015
    642
    788
    Male
    United States
    The testnet binaries should be out tomorrow as well.
     
    anondran, tacotime and SG-O like this.
  4. SG-O

    SG-O Member
    Developer

    Jan 13, 2016
    104
    86
    Male
    Software Dev
    Milky Way
    Will there be any pre-compiled binaries during the testnet phase or will we all have to build it ourselves?
    If there won't be any official, are we allowed to share our builds?
     
  5. traspy

    traspy New Member

    Jan 4, 2016
    8
    2
    Male
    For a newbie like me: How to benchmark on windows? Can't find any executable file....
     
  6. SG-O

    SG-O Member
    Developer

    Jan 13, 2016
    104
    86
    Male
    Software Dev
    Milky Way
    It's not compiled yet! You have to build it for yourself first, then there will be executables!
     
    traspy likes this.
  7. jolan

    jolan Sr. Member
    Developer

    Dec 7, 2015
    197
    226
    Male
    Decred Team Member
    We will be releasing pre-built downloads tomorrow. It would be great if you didn't share binaries but I guess everyone is excited to benchmark their cards so I'll stay out of it. Please use multiple anti-virus programs before running anything from random people or in a VM with GPU passthrough.

    You'll want to run cgminer(.exe) --blake256 --benchmark.
     
    Rune S and traspy like this.
  8. SG-O

    SG-O Member
    Developer

    Jan 13, 2016
    104
    86
    Male
    Software Dev
    Milky Way
    I've been trying to build it for the last hour and I had no success: After running the build configuration I get the following:

    Code:
    ------------------------------------------------------------------------
    cgminer 3.7.2
    ------------------------------------------------------------------------
    
    
    Configuration Options Summary:
    
      libcurl(GBT+getwork).: Enabled: -LD:/MinGW/lib -lcurl -lcurldll
      curses.TUI...........: FOUND: -lpdcurses
      OpenCL...............: Detection overrided. GPU mining support DISABLED
    configure: error: No mining configured in
    

    When I then try to run make I get the following error:

    Code:
    In file included from ./miner.h:9:0,
                     from ./sha2.h:36,
                     from cgminer.c:52:
    d:\mingw\include\pthread.h:320:8: error: redefinition of 'struct timespec'
    struct timespec {
            ^
    In file included from d:\mingw\include\unistd.h:96:0,
                     from cgminer.c:23:
    d:\mingw\include\parts\time.h:105:8: note: originally defined here
    struct timespec
            ^
    In file included from cgminer.c:54:0:
    compat.h:17:19: error: conflicting types for 'nanosleep'
    static inline int nanosleep(const struct timespec *req, struct timespec *rem)
                       ^
    In file included from cgminer.c:23:0:
    d:\mingw\include\unistd.h:110:5: note: previous definition of 'nanosleep' was he
    re
    int nanosleep( const struct timespec *period, struct timespec *residual )
         ^
    In file included from cgminer.c:54:0:
    compat.h:50:19: error: conflicting types for 'sleep'
    static inline int sleep(unsigned int secs)
                       ^
    In file included from cgminer.c:23:0:
    d:\mingw\include\unistd.h:143:10: note: previous definition of 'sleep' was here
    unsigned sleep( unsigned period ){ return __mingw_sleep( period, 0 ); }
              ^
    make[2]: *** [cgminer-cgminer.o] Error 1
    make[2]: Leaving directory `/home/Joerg/cgminer-3.7'
    make[1]: *** [all-recursive] Error 1
    make[1]: Leaving directory `/home/Joerg/cgminer-3.7'
    make: *** [all] Error 2
    
     
  9. jolan

    jolan Sr. Member
    Developer

    Dec 7, 2015
    197
    226
    Male
    Decred Team Member
    You need to specify --enable-opencl, not sure about the other part since I haven't built it on Windows yet.
     
  10. SG-O

    SG-O Member
    Developer

    Jan 13, 2016
    104
    86
    Male
    Software Dev
    Milky Way
    I already had specified --enable-opencl and had almost the same result:
    Code:
    ------------------------------------------------------------------------
    cgminer 3.7.2
    ------------------------------------------------------------------------
    
    
    Configuration Options Summary:
    
      libcurl(GBT+getwork).: Enabled: -LD:/MinGW/lib -lcurl -lcurldll
      curses.TUI...........: FOUND: -lpdcurses
      OpenCL...............: NOT FOUND. GPU mining support DISABLED
    configure: error: No mining configured in
     
  11. jolan

    jolan Sr. Member
    Developer

    Dec 7, 2015
    197
    226
    Male
    Decred Team Member
    Which brand of graphics cards do you have, AMD/Intel/Nvidia? Usually the drivers or SDK install the OpenCL library to C:\Windows\system32\OpenCL.dll. Sounds like that it might not be installed or detected properly. The log is in config.log, that may tell you more.

    I'll have to try compiling on Windows to see if I can re-produce the build errors. Looks like mingw now includes some functions that weren't there previously so some updates might need to be made for newer versions of mingw.
     
  12. Skralg

    Skralg New Member

    Dec 30, 2015
    3
    3
    Male
    Software Developer
    Las Vegas
    I built mine on cygwin, and it benchmarks pretty well.
    Card 1: Radeon R9 200 Series, Pitcairn, 1280 shaders, 2048MB memory, GPU Clock 955, Memory Clock 1400
    Card 2: Radeon R7 Graphics, Spectre, 512 shaders, 1024MB memory, GPU Clock 867, Memory Clock 1066

    [2016-01-26 17:01:17] GPU0 | (5s):737.8M (avg):739.9Mh/s | A:0 R:0 HW:0 WU:0.0/m
    [2016-01-26 17:01:17] GPU1 | (5s):258.2M (avg):257.1Mh/s | A:0 R:0 HW:0 WU:0.0/m
     
    thepotterone likes this.
  13. davecgh

    davecgh Hero Member
    Developer Organizer

    Dec 31, 2015
    642
    788
    Male
    United States
    Built under MinGW.
    AMD Radeon HD 7770, 640 shaders, 1024MB memory, GPU Clock 1100, Memory Clock 1300

    [2016-01-26 19:39:33] GPU0 | (5s):422.6M (avg):461.2Mh/s | A:0 R:0 HW:0 WU:0.0/m
     
  14. lulworm

    lulworm New Member

    Jan 14, 2016
    13
    11
    Male
    Web developer
    Ghana
    #14 lulworm, Jan 26, 2016
    Last edited: Jan 26, 2016

    MinGW64 defines nanosleep() and sleep(), MinGW32 doesn't usually.

    Download this version of adl https://drive.google.com/folderview?id=0ByitvRo_awTXb0VzR0hFb1FIRUE&usp=sharing

    Copy them into ADL_SDK directory inside the cgminer-3.7 directory


    Open compat.h in cgminer folder and find this section of the code, starting from line number 16

    Code:
    #ifndef HAVE_LIBWINPTHREAD
    static inline int nanosleep(const struct timespec *req, struct timespec *rem)
    {
        struct timeval tstart;
        DWORD msecs;
    
        cgtime(&tstart);
        msecs = (req->tv_sec * 1000) + ((999999 + req->tv_nsec) / 1000000);
    
        if (SleepEx(msecs, true) == WAIT_IO_COMPLETION) {
            if (rem) {
                struct timeval tdone, tnow, tleft;
                tdone.tv_sec = tstart.tv_sec + req->tv_sec;
                tdone.tv_usec = tstart.tv_usec + ((999 + req->tv_nsec) / 1000);
                if (tdone.tv_usec > 1000000) {
                    tdone.tv_usec -= 1000000;
                    ++tdone.tv_sec;
                }
    
                cgtime(&tnow);
                if (timercmp(&tnow, &tdone, >))
                    return 0;
                timersub(&tdone, &tnow, &tleft);
    
                rem->tv_sec = tleft.tv_sec;
                rem->tv_nsec = tleft.tv_usec * 1000;
            }
            errno = EINTR;
            return -1;
        }
        return 0;
    }
    #endif
    
    static inline int sleep(unsigned int secs)
    {
        struct timespec req, rem;
        req.tv_sec = secs;
        req.tv_nsec = 0;
        if (!nanosleep(&req, &rem))
            return 0;
        return rem.tv_sec + (rem.tv_nsec ? 1 : 0);
    }

    Replace with this code

    Code:
    #if !(__MINGW32__)
    
    #ifndef HAVE_LIBWINPTHREAD
    static inline int nanosleep(const struct timespec *req, struct timespec *rem)
    {
        struct timeval tstart;
        DWORD msecs;
    
        cgtime(&tstart);
        msecs = (req->tv_sec * 1000) + ((999999 + req->tv_nsec) / 1000000);
    
        if (SleepEx(msecs, true) == WAIT_IO_COMPLETION) {
            if (rem) {
                struct timeval tdone, tnow, tleft;
                tdone.tv_sec = tstart.tv_sec + req->tv_sec;
                tdone.tv_usec = tstart.tv_usec + ((999 + req->tv_nsec) / 1000);
                if (tdone.tv_usec > 1000000) {
                    tdone.tv_usec -= 1000000;
                    ++tdone.tv_sec;
                }
    
                cgtime(&tnow);
                if (timercmp(&tnow, &tdone, >))
                    return 0;
                timersub(&tdone, &tnow, &tleft);
    
                rem->tv_sec = tleft.tv_sec;
                rem->tv_nsec = tleft.tv_usec * 1000;
            }
            errno = EINTR;
            return -1;
        }
        return 0;
    }
    #endif
    
    static inline int sleep(unsigned int secs)
    {
        struct timespec req, rem;
        req.tv_sec = secs;
        req.tv_nsec = 0;
        if (!nanosleep(&req, &rem))
            return 0;
        return rem.tv_sec + (rem.tv_nsec ? 1 : 0);
    }
    
    #endif

    Haven't tried compiling it myself as i've been a little busy on some job assignment.
    Please try this solution and let me know if it works.
    Otherwise i'll provide you with another solution which involves editing unistd.h

    Cheers
     
    SG-O likes this.
  15. lulworm

    lulworm New Member

    Jan 14, 2016
    13
    11
    Male
    Web developer
    Ghana
    I have Compiled successfully with MingW32 on windows without any problems

    AMD 6900 = 1.5Gh/s
     

    Attached Files:

  16. SG-O

    SG-O Member
    Developer

    Jan 13, 2016
    104
    86
    Male
    Software Dev
    Milky Way
    Thank you lulworm for your sugestion, it helped a little, but i still have some problems compiling it.
    Now I still have the following problems:

    Code:
      CC     cgminer-cgminer.o
    In file included from ./miner.h:9:0,
                     from ./sha2.h:36,
                     from cgminer.c:52:
    d:\mingw\include\pthread.h:320:8: error: redefinition of 'struct timespec'
    struct timespec {
            ^
    In file included from d:\mingw\include\unistd.h:96:0,
                     from cgminer.c:23:
    d:\mingw\include\parts\time.h:105:8: note: originally defined here
    struct timespec
            ^
    cgminer.c: In function 'hash_sole_work':
    cgminer.c:6504:6: warning: passing argument 1 of 'nanosleep' from incompatible p
    ointer type [enabled by default]
          nanosleep(&rgtp, NULL);
          ^
    In file included from cgminer.c:23:0:
    d:\mingw\include\unistd.h:110:5: note: expected 'const struct timespec *' but ar
    gument is of type 'struct timespec *'
    int nanosleep( const struct timespec *period, struct timespec *residual )
         ^
    make[2]: *** [cgminer-cgminer.o] Error 1
    make[2]: Leaving directory `/home/Joerg/cgminer-3.7'
    make[1]: *** [all-recursive] Error 1
    make[1]: Leaving directory `/home/Joerg/cgminer-3.7'
    make: *** [all] Error 2
    

    If I have the time, I may try to rewrite CGminer in a language that I'm more familiar with on windows like Mono or Java
     
  17. lulworm

    lulworm New Member

    Jan 14, 2016
    13
    11
    Male
    Web developer
    Ghana

    Don't worry i've slightly modified unistd.h in "MinGW\include" and the link is provided below.
    Rename "MinGW\include\unistd.h" to unistd.h.old
    Download unistd.h below into your MinGW\include folder and try again.

    https://drive.google.com/file/d/0ByitvRo_awTXQXJ6WFNZcWJTTGM/view?usp=sharing

    Let me know if u encounter any other errors.
     
  18. Wolf

    Wolf Jr. Member

    Jan 25, 2016
    107
    45
    #18 Wolf, Jan 27, 2016
    Last edited: Jan 27, 2016
    Points docked for having configure called in autogen.sh, and EVEN THEN it doesn't work right, because there's no --enable-opencl used when configure is called from autogen.sh - most people like to call configure themselves. The autogen.sh script isn't executable when cloned, either.

    My real reason to bitch, however, is that the README doesn't say you must use -k blake256 to get it to mine Decred at all - those trying --benchmark are likely getting totally bogus values. It uses the poclbm SHA256d kernel by default.

    Nitpicks: Could have cleaned out SHA256d code and kernels, plus did a few other cleanups since it doesn't seem to care much about putting it into a multi-algo miner - for a Decred-only miner, it could be WAY easier to use and lighter, but again, that's just a nitpick.

    EDIT:

    Just looked at the OpenCL - DEAR LORD, who wrote that? I mean, it's probably efficient, yes, but reading it makes you want to tear your eyes out. You do know macros exist for a reason, and so do loops... if you're worried about the branching with looping, just use "#pragma unroll" and use it so the code is readable. Also, the AMD compiler is probably too stupid to turn some of your rotates into vector swizzles... just saying.

    EDIT2:

    Looked at the END of the OpenCL - loose ends here. If - and yes, this is hella unlikely (depending on share difficulty) - two work items find a share at the same time, then it is very possible they both write to the same index in the same output array and/or increment the counter at the end of it at the same time, making the result undefined. For those that don't code, this means "probably total garbage." The OpenCL builtin function atomic_inc() is your friend.

    EDIT3: I just found out you don't need -k blake256, you need --blake256. Documentation on this, again, would be REALLY helpful.
     
    ZeroASIC and ClokworkGremlin like this.
  19. jcv

    jcv Full Member
    Developer

    Wolf, if there are specific things you don't like we'd be happy for PR's on the github page. Or issues.
     
  20. jcv

    jcv Full Member
    Developer

    As for the ugly code comment, as someone who wrote a lot of very optimized FORTRAN in another life, sometimes optimization leads to ugly things. Compilers are usually smarter than coders, but in the cases that they aren't, sometimes pretty code is what has to lose. Not something that should be done often, but sometimes, you need it.
     

Share This Page