Skip to content

Commit

Permalink
Interface nicehash djeZo equihash solver (squashed)
Browse files Browse the repository at this point in the history
Todo:
    - send block height via stratum protocol (encoded in jobid?)
    - remove equi/blake2 cpu algorithm to use common one

the extranonce imcompatibility is related to the solver nonce data,
offsets may be reversed in nheqminer, to check...

The solver was adapted for SM 3.0+ support (no perf changes)

Note: The solver was not improved on purpose, to be able compare
the two miners performances (nheqminer 0.5c the last open sourced, and ccminer)

Signed-off-by: Tanguy Pruvot <[email protected]>

stratum: code cleanup, move equi fns in equi folder
  • Loading branch information
tpruvot committed May 23, 2017
1 parent c44be3f commit 8cf2159
Show file tree
Hide file tree
Showing 24 changed files with 4,422 additions and 24 deletions.
6 changes: 6 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ ccminer_SOURCES = elist.h miner.h compat.h \
crc32.c hefty1.c \
ccminer.cpp pools.cpp util.cpp bench.cpp bignum.cpp \
api.cpp hashlog.cpp nvml.cpp stats.cpp sysinfos.cpp cuda.cpp \
equi/equi-stratum.cpp equi/equi.cpp equi/blake2/blake2bx.cpp \
equi/equihash.cpp equi/cuda_equi.cu \
heavy/heavy.cu \
heavy/cuda_blake512.cu heavy/cuda_blake512.h \
heavy/cuda_combine.cu heavy/cuda_combine.h \
Expand Down Expand Up @@ -97,6 +99,10 @@ ccminer_LDFLAGS += -L/usr/local/llvm/lib
ccminer_LDADD += -lomp
endif

#ccminer_CPPFLAGS += -DUSE_LIBSODIUM
#ccminer_LDFLAGS += -Lequi/lib
#ccminer_LDADD += -lsodium
ccminer_LDADD += -lcuda

nvcc_ARCH = -gencode=arch=compute_50,code=\"sm_50,compute_50\"

Expand Down
4 changes: 4 additions & 0 deletions algos.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ enum sha_algos {
ALGO_DEEP,
ALGO_DECRED,
ALGO_DMD_GR,
ALGO_EQUIHASH,
ALGO_FRESH,
ALGO_FUGUE256, /* Fugue256 */
ALGO_GROESTL,
Expand Down Expand Up @@ -78,6 +79,7 @@ static const char *algo_names[] = {
"deep",
"decred",
"dmd-gr",
"equihash",
"fresh",
"fugue256",
"groestl",
Expand Down Expand Up @@ -149,6 +151,8 @@ static inline int algo_to_int(char* arg)
i = ALGO_C11;
else if (!strcasecmp("diamond", arg))
i = ALGO_DMD_GR;
else if (!strcasecmp("equi", arg))
i = ALGO_EQUIHASH;
else if (!strcasecmp("doom", arg))
i = ALGO_LUFFA;
else if (!strcasecmp("hmq17", arg))
Expand Down
1 change: 1 addition & 0 deletions api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1341,6 +1341,7 @@ void api_set_throughput(int thr_id, uint32_t throughput)
if (thr_id < MAX_GPUS && thr_info) {
struct cgpu_info *cgpu = &thr_info[thr_id].gpu;
cgpu->intensity = throughput2intensity(throughput);
if (cgpu->throughput != throughput) cgpu->throughput = throughput;
}
// to display in bench results
if (opt_benchmark)
Expand Down
56 changes: 53 additions & 3 deletions ccminer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include "algos.h"
#include "sia/sia-rpc.h"
#include "crypto/xmr-rpc.h"
#include "equi/equihash.h"

#include <cuda_runtime.h>

Expand Down Expand Up @@ -243,6 +244,7 @@ Options:\n\
c11/flax X11 variant\n\
decred Decred Blake256\n\
deep Deepcoin\n\
equihash Zcash Equihash\n\
dmd-gr Diamond-Groestl\n\
fresh Freshcoin (shavite 80)\n\
fugue256 Fuguecoin\n\
Expand Down Expand Up @@ -558,6 +560,14 @@ void get_currentalgo(char* buf, int sz)
snprintf(buf, sz, "%s", algo_names[opt_algo]);
}

void format_hashrate(double hashrate, char *output)
{
if (opt_algo == ALGO_EQUIHASH)
format_hashrate_unit(hashrate, output, "Sol/s");
else
format_hashrate_unit(hashrate, output, "H/s");
}

/**
* Exit app
*/
Expand Down Expand Up @@ -634,6 +644,10 @@ static void calc_network_diff(struct work *work)
if (opt_algo == ALGO_LBRY) nbits = swab32(work->data[26]);
if (opt_algo == ALGO_DECRED) nbits = work->data[29];
if (opt_algo == ALGO_SIA) nbits = work->data[11]; // unsure if correct
if (opt_algo == ALGO_EQUIHASH) {
net_diff = equi_network_diff(work);
return;
}

uint32_t bits = (nbits & 0xffffff);
int16_t shift = (swab32(nbits) & 0xff); // 0x1c = 28
Expand Down Expand Up @@ -856,6 +870,17 @@ static bool submit_upstream_work(CURL *curl, struct work *work)
return true;
}

if (pool->type & POOL_STRATUM && stratum.is_equihash) {
struct work submit_work;
memcpy(&submit_work, work, sizeof(struct work));
//if (!hashlog_already_submittted(submit_work.job_id, submit_work.nonces[idnonce])) {
if (equi_stratum_submit(pool, &submit_work))
hashlog_remember_submit(&submit_work, submit_work.nonces[idnonce]);
stratum.job.shares_count++;
//}
return true;
}

/* discard if a newer block was received */
stale_work = work->height && work->height < g_work.height;
if (have_stratum && !stale_work && opt_algo != ALGO_ZR5 && opt_algo != ALGO_SCRYPT_JANE) {
Expand Down Expand Up @@ -1508,6 +1533,7 @@ static bool stratum_gen_work(struct stratum_ctx *sctx, struct work *work)
/* Generate merkle root */
switch (opt_algo) {
case ALGO_DECRED:
case ALGO_EQUIHASH:
case ALGO_SIA:
// getwork over stratum, no merkle to generate
break;
Expand Down Expand Up @@ -1566,6 +1592,13 @@ static bool stratum_gen_work(struct stratum_ctx *sctx, struct work *work)
memcpy(&work->data[44], &sctx->job.coinbase[sctx->job.coinbase_size-4], 4);
sctx->job.height = work->data[32];
//applog_hex(work->data, 180);
} else if (opt_algo == ALGO_EQUIHASH) {
memcpy(&work->data[9], sctx->job.coinbase, 32+32); // merkle [9..16] + reserved
work->data[25] = le32dec(sctx->job.ntime);
work->data[26] = le32dec(sctx->job.nbits);
memcpy(&work->data[27], sctx->xnonce1, sctx->xnonce1_size & 0x1F); // pool extranonce
work->data[35] = 0x80;
//applog_hex(work->data, 140);
} else if (opt_algo == ALGO_LBRY) {
for (i = 0; i < 8; i++)
work->data[9 + i] = be32dec((uint32_t *)merkle_root + i);
Expand Down Expand Up @@ -1618,7 +1651,7 @@ static bool stratum_gen_work(struct stratum_ctx *sctx, struct work *work)

pthread_mutex_unlock(&stratum_work_lock);

if (opt_debug && opt_algo != ALGO_DECRED && opt_algo != ALGO_SIA) {
if (opt_debug && opt_algo != ALGO_DECRED && opt_algo != ALGO_EQUIHASH && opt_algo != ALGO_SIA) {
uint32_t utm = work->data[17];
if (opt_algo != ALGO_ZR5) utm = swab32(utm);
char *tm = atime2str(utm - sctx->srvtime_diff);
Expand Down Expand Up @@ -1656,6 +1689,9 @@ static bool stratum_gen_work(struct stratum_ctx *sctx, struct work *work)
case ALGO_LYRA2:
work_set_target(work, sctx->job.diff / (128.0 * opt_difficulty));
break;
case ALGO_EQUIHASH:
equi_work_set_target(work, sctx->job.diff / opt_difficulty);
break;
default:
work_set_target(work, sctx->job.diff / opt_difficulty);
}
Expand Down Expand Up @@ -1830,6 +1866,9 @@ static void *miner_thread(void *userdata)
} else if (opt_algo == ALGO_CRYPTOLIGHT || opt_algo == ALGO_CRYPTONIGHT) {
nonceptr = (uint32_t*) (((char*)work.data) + 39);
wcmplen = 39;
} else if (opt_algo == ALGO_EQUIHASH) {
nonceptr = &work.data[EQNONCE_OFFSET]; // 27 is pool extranonce (256bits nonce space)
wcmplen = 4+32+32;
}

if (have_stratum) {
Expand Down Expand Up @@ -1962,6 +2001,10 @@ static void *miner_thread(void *userdata)
nonceptr[1] += 1;
nonceptr[2] |= thr_id;

} else if (opt_algo == ALGO_EQUIHASH) {
nonceptr[1]++;
nonceptr[1] |= thr_id << 24;
//applog_hex(&work.data[27], 32);
} else if (opt_algo == ALGO_WILDKECCAK) {
//nonceptr[1] += 1;
} else if (opt_algo == ALGO_SIA) {
Expand Down Expand Up @@ -2264,6 +2307,9 @@ static void *miner_thread(void *userdata)
case ALGO_DEEP:
rc = scanhash_deep(thr_id, &work, max_nonce, &hashes_done);
break;
case ALGO_EQUIHASH:
rc = scanhash_equihash(thr_id, &work, max_nonce, &hashes_done);
break;
case ALGO_FRESH:
rc = scanhash_fresh(thr_id, &work, max_nonce, &hashes_done);
break;
Expand Down Expand Up @@ -2431,7 +2477,7 @@ static void *miner_thread(void *userdata)
work.nonces[1] = nonceptr[2];
}

if (stratum.rpc2 && rc == -EBUSY || work_restart[thr_id].restart) {
if (stratum.rpc2 && (rc == -EBUSY || work_restart[thr_id].restart)) {
// bbr scratchpad download or stale result
sleep(1);
if (!thr_id) pools[cur_pooln].wait_time += 1;
Expand Down Expand Up @@ -2489,7 +2535,7 @@ static void *miner_thread(void *userdata)
}

// only required to debug purpose
if (opt_debug && check_dups && opt_algo != ALGO_DECRED && opt_algo != ALGO_SIA)
if (opt_debug && check_dups && opt_algo != ALGO_DECRED && opt_algo != ALGO_EQUIHASH && opt_algo != ALGO_SIA)
hashlog_remember_scan_range(&work);

/* output */
Expand Down Expand Up @@ -3854,6 +3900,10 @@ int main(int argc, char *argv[])
allow_mininginfo = false;
}

if (opt_algo == ALGO_EQUIHASH) {
opt_extranonce = false; // disable subscribe
}

if (opt_algo == ALGO_CRYPTONIGHT || opt_algo == ALGO_CRYPTOLIGHT) {
rpc2_init();
if (!opt_quiet) applog(LOG_INFO, "Using JSON-RPC 2.0");
Expand Down
20 changes: 17 additions & 3 deletions ccminer.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
<PtxAsOptionV>true</PtxAsOptionV>
<Keep>true</Keep>
<CodeGeneration>compute_50,sm_50;compute_52,sm_52;compute_30,sm_30;compute_20,sm_21</CodeGeneration>
<AdditionalOptions>--ptxas-options="-O2" %(AdditionalOptions)</AdditionalOptions>
<AdditionalOptions>--ptxas-options="-O2" --Wno-deprecated-gpu-targets %(AdditionalOptions)</AdditionalOptions>
<Optimization>O2</Optimization>
</CudaCompile>
<CudaLink>
Expand Down Expand Up @@ -199,9 +199,10 @@
<PtxAsOptionV>true</PtxAsOptionV>
<Keep>true</Keep>
<CodeGeneration>compute_52,sm_52;compute_50,sm_50;compute_35,sm_35;compute_30,sm_30;compute_20,sm_21</CodeGeneration>
<Include>$(NVTOOLSEXT_PATH)\include;..\..\..\Common\C99</Include>
<Include>$(NVTOOLSEXT_PATH)\include</Include>
<Optimization>O3</Optimization>
<TargetMachinePlatform>64</TargetMachinePlatform>
<AdditionalOptions>--Wno-deprecated-gpu-targets %(AdditionalOptions)</AdditionalOptions>
</CudaCompile>
<CudaLink>
<Optimization>O3</Optimization>
Expand Down Expand Up @@ -235,6 +236,12 @@
<ClCompile Include="crypto\cryptolight-cpu.cpp" />
<ClCompile Include="crypto\cryptonight-cpu.cpp" />
<ClCompile Include="crypto\cpu\c_keccak.c" />
<ClCompile Include="equi\blake2\blake2bx.cpp">
<EnableEnhancedInstructionSet Condition="'$(Platform)'=='Win32'">StreamingSIMDExtensions</EnableEnhancedInstructionSet>
</ClCompile>
<ClCompile Include="equi\equi-stratum.cpp" />
<ClCompile Include="equi\equi.cpp" />
<ClCompile Include="equi\equihash.cpp" />
<ClCompile Include="nvapi.cpp" />
<ClCompile Include="pools.cpp" />
<ClCompile Include="util.cpp" />
Expand All @@ -254,6 +261,8 @@
<ClCompile Include="lyra2\Lyra2.c" />
<ClCompile Include="lyra2\Sponge.c" />
<ClCompile Include="lyra2\Lyra2Z.c" />
<ClInclude Include="equi\eqcuda.hpp" />
<ClInclude Include="equi\equihash.h" />
<ClInclude Include="neoscrypt\neoscrypt.h" />
<ClCompile Include="neoscrypt\neoscrypt.cpp" />
<ClCompile Include="neoscrypt\neoscrypt-cpu.c" />
Expand Down Expand Up @@ -283,6 +292,11 @@
<CudaCompile Include="crypto\wildkeccak.cu">
<MaxRegCount>128</MaxRegCount>
</CudaCompile>
<CudaCompile Include="equi\cuda_equi.cu">
<CodeGeneration>compute_52,sm_52;compute_50,sm_50;compute_30,sm_30</CodeGeneration>
<AdditionalOptions> -Xptxas -dlcm=ca -Xptxas -dscm=cs %(AdditionalOptions)</AdditionalOptions>
<MaxRegCount>0</MaxRegCount>
</CudaCompile>
<CudaCompile Include="neoscrypt\cuda_neoscrypt.cu">
<MaxRegCount>160</MaxRegCount>
</CudaCompile>
Expand Down Expand Up @@ -552,7 +566,7 @@
</CudaCompile>
<CudaCompile Include="x15\cuda_x14_shabal512.cu" />
<CudaCompile Include="x15\cuda_x15_whirlpool.cu" />
<CudaCompile Include="x17\hmq17.cu"/>
<CudaCompile Include="x17\hmq17.cu" />
<CudaCompile Include="x15\x15.cu" />
<CudaCompile Include="x15\whirlpool.cu" />
<CudaCompile Include="x17\x17.cu">
Expand Down
26 changes: 25 additions & 1 deletion ccminer.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@
<Filter Include="Source Files\CUDA\xmr">
<UniqueIdentifier>{0f9aec5e-5409-488f-992a-2c108590d1ac}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\equi">
<UniqueIdentifier>{031afae7-2a78-4e32-9738-4b589b6f7ff3}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="compat\jansson\dump.c">
Expand Down Expand Up @@ -321,6 +324,18 @@
<ClCompile Include="crypto\wildkeccak-cpu.cpp">
<Filter>Source Files\crypto\bbr</Filter>
</ClCompile>
<ClCompile Include="equi\equi.cpp">
<Filter>Source Files\equi</Filter>
</ClCompile>
<ClCompile Include="equi\equihash.cpp">
<Filter>Source Files\equi</Filter>
</ClCompile>
<ClCompile Include="equi\equi-stratum.cpp">
<Filter>Source Files\equi</Filter>
</ClCompile>
<ClCompile Include="equi\blake2\blake2bx.cpp">
<Filter>Source Files\equi</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="algos.h">
Expand Down Expand Up @@ -563,6 +578,12 @@
<ClInclude Include="crypto\cryptonight.h">
<Filter>Source Files\CUDA\xmr</Filter>
</ClInclude>
<ClInclude Include="equi\eqcuda.hpp">
<Filter>Source Files\equi</Filter>
</ClInclude>
<ClInclude Include="equi\equihash.h">
<Filter>Source Files\equi</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<CudaCompile Include="cuda.cpp">
Expand Down Expand Up @@ -895,6 +916,9 @@
<CudaCompile Include="crypto\wildkeccak.cu">
<Filter>Source Files\CUDA</Filter>
</CudaCompile>
<CudaCompile Include="equi\cuda_equi.cu">
<Filter>Source Files\equi</Filter>
</CudaCompile>
</ItemGroup>
<ItemGroup>
<Image Include="res\ccminer.ico">
Expand All @@ -911,4 +935,4 @@
<Filter>Ressources</Filter>
</Text>
</ItemGroup>
</Project>
</Project>
2 changes: 1 addition & 1 deletion compat/ccminer-config.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@
#define PACKAGE_URL "http://github.com/tpruvot/ccminer"

/* Define to the version of this package. */
#define PACKAGE_VERSION "2.0"
#define PACKAGE_VERSION "2.1"

/* If using the C implementation of alloca, define if you know the
direction of stack growth for your system; otherwise it will be
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
AC_INIT([ccminer], [2.0], [], [ccminer], [http://github.com/tpruvot/ccminer])
AC_INIT([ccminer], [2.1], [], [ccminer], [http://github.com/tpruvot/ccminer])

AC_PREREQ([2.59c])
AC_CANONICAL_SYSTEM
Expand Down
Loading

0 comments on commit 8cf2159

Please sign in to comment.