Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a6822e6d0d | ||
|
|
3788fef9fd | ||
|
|
21630d5fbc | ||
|
|
e2f73614c0 | ||
|
|
40fc2bdcbc | ||
|
|
d923f0c1b2 | ||
|
|
6b69246c33 | ||
|
|
c5df142124 | ||
|
|
15293d063f | ||
|
|
aa271104c1 | ||
|
|
25a78c96b5 | ||
|
|
5abfac72d6 | ||
|
|
7c5087d01c | ||
|
|
b5b9b1f2db | ||
|
|
b9cfee0bb3 | ||
|
|
f73f5f6a2e | ||
|
|
cad3772122 | ||
|
|
7981e83db7 | ||
|
|
e21c75793a | ||
|
|
7661f73317 | ||
|
|
cb9d51c026 | ||
|
|
a12dfa5370 | ||
|
|
6b41234ff1 | ||
|
|
1187a6e7e3 | ||
|
|
9aac7ca713 |
No files matched your search
@@ -13,7 +13,7 @@ but some distros may have a different default location)
|
||||
|
||||
# Step 1: gcc and dependencies
|
||||
dnf install gcc gcc-c++ automake
|
||||
dnf install jansson-devel openssl-devel libcurl-devel
|
||||
dnf install jansson-devel openssl-devel libcurl-devel zlib-devel pciutils-devel
|
||||
|
||||
# Step 2: nvidia drivers (Download common linux drivers from nvidia site)
|
||||
dnf install kernel-devel
|
||||
|
||||
+7
-8
@@ -21,6 +21,7 @@ ccminer_SOURCES = elist.h miner.h compat.h \
|
||||
crc32.c hefty1.c \
|
||||
ccminer.cpp pools.cpp util.cpp bignum.cpp \
|
||||
api.cpp hashlog.cpp nvml.cpp stats.cpp sysinfos.cpp cuda.cpp \
|
||||
ethash/etherpc.cpp ethash/ethash.cu \
|
||||
heavy/heavy.cu \
|
||||
heavy/cuda_blake512.cu heavy/cuda_blake512.h \
|
||||
heavy/cuda_combine.cu heavy/cuda_combine.h \
|
||||
@@ -44,20 +45,18 @@ ccminer_SOURCES = elist.h miner.h compat.h \
|
||||
neoscrypt/neoscrypt.cpp neoscrypt/neoscrypt-cpu.c neoscrypt/cuda_neoscrypt.cu \
|
||||
cuda_nist5.cu pentablake.cu skein.cu cuda_skeincoin.cu skein2.cpp zr5.cu \
|
||||
sph/bmw.c sph/blake.c sph/groestl.c sph/jh.c sph/keccak.c sph/skein.c \
|
||||
sph/cubehash.c sph/echo.c sph/luffa.c sph/sha2.c sph/sha256d.c sph/shavite.c sph/simd.c \
|
||||
sph/cubehash.c sph/echo.c sph/luffa.c sph/sha2.c sph/shavite.c sph/simd.c \
|
||||
sph/hamsi.c sph/hamsi_helper.c sph/sph_hamsi.h \
|
||||
sph/shabal.c sph/whirlpool.c sph/sha2big.c sph/haval.c \
|
||||
sha256/bitcoin.cu sha256/cuda_bitcoin.cu \
|
||||
sha256/credits.cu sha256/cuda_credits.cu \
|
||||
pluck/pluck.cu pluck/cuda_pluck.cu \
|
||||
qubit/qubit.cu qubit/qubit_luffa512.cu qubit/deep.cu qubit/luffa.cu \
|
||||
x11/x11.cu x11/fresh.cu x11/cuda_x11_luffa512.cu x11/cuda_x11_cubehash512.cu \
|
||||
x11/cuda_x11_shavite512.cu x11/cuda_x11_simd512.cu x11/cuda_x11_echo.cu \
|
||||
x11/cuda_x11_luffa512_Cubehash.cu \
|
||||
x13/x13.cu x13/cuda_x13_hamsi512.cu x13/cuda_x13_fugue512.cu \
|
||||
x15/x14.cu x15/x15.cu x15/cuda_x14_shabal512.cu x15/cuda_x15_whirlpool.cu \
|
||||
x15/whirlpoolx.cu x15/cuda_whirlpoolx.cu \
|
||||
x17/x17.cu x17/cuda_x17_haval512.cu x17/cuda_x17_sha512.cu \
|
||||
x11/s3.cu
|
||||
x11/c11.cu x11/s3.cu
|
||||
|
||||
# scrypt
|
||||
ccminer_SOURCES += scrypt.cpp scrypt-jane.cpp \
|
||||
@@ -76,12 +75,12 @@ ccminer_SOURCES += compat/winansi.c
|
||||
endif
|
||||
|
||||
ccminer_LDFLAGS = $(PTHREAD_FLAGS) @CUDA_LDFLAGS@
|
||||
ccminer_LDADD = @LIBCURL@ @JANSSON_LIBS@ @PTHREAD_LIBS@ @WS2_LIBS@ @CUDA_LIBS@ @OPENMP_CFLAGS@ @LIBS@ $(nvml_libs)
|
||||
ccminer_CPPFLAGS = @LIBCURL_CPPFLAGS@ @OPENMP_CFLAGS@ $(CPPFLAGS) $(PTHREAD_FLAGS) -fno-strict-aliasing $(JANSSON_INCLUDES) $(DEF_INCLUDES) $(nvml_defs) -DSCRYPT_KECCAK512 -DSCRYPT_CHACHA -DSCRYPT_CHOOSE_COMPILETIME
|
||||
ccminer_LDADD = @LIBCURL@ @JANSSON_LIBS@ @PTHREAD_LIBS@ @WS2_LIBS@ @CUDA_LIBS@ @PCILIB@ @OPENMP_CFLAGS@ @LIBS@ $(nvml_libs)
|
||||
ccminer_CPPFLAGS = @LIBCURL_CPPFLAGS@ @PCIFLAGS@ @OPENMP_CFLAGS@ $(CPPFLAGS) $(PTHREAD_FLAGS) -fno-strict-aliasing $(JANSSON_INCLUDES) $(DEF_INCLUDES) $(nvml_defs)
|
||||
|
||||
nvcc_ARCH = -gencode=arch=compute_50,code=\"sm_50,compute_50\"
|
||||
|
||||
nvcc_ARCH += -gencode=arch=compute_52,code=\"sm_52,compute_52\"
|
||||
#nvcc_ARCH += -gencode=arch=compute_52,code=\"sm_52,compute_52\"
|
||||
#nvcc_ARCH += -gencode=arch=compute_35,code=\"sm_35,compute_35\"
|
||||
#nvcc_ARCH += -gencode=arch=compute_30,code=\"sm_30,compute_30\"
|
||||
#nvcc_ARCH += -gencode=arch=compute_20,code=\"sm_21,compute_20\"
|
||||
|
||||
+20
-9
@@ -1,5 +1,5 @@
|
||||
|
||||
ccMiner release 1.6.x-tpruvot (Jun 2015) - "SHA and ..."
|
||||
ccMiner release 1.6.5-C11 (Jul 2015) "Special for Chaincoin C11"
|
||||
---------------------------------------------------------------
|
||||
|
||||
***************************************************************
|
||||
@@ -24,7 +24,6 @@ cbuchner v1.2:
|
||||
|
||||
This is a CUDA accelerated mining application which handle :
|
||||
|
||||
Credits
|
||||
HeavyCoin & MjollnirCoin
|
||||
FugueCoin
|
||||
GroestlCoin & Myriad-Groestl
|
||||
@@ -32,6 +31,7 @@ JackpotCoin
|
||||
QuarkCoin family & AnimeCoin
|
||||
TalkCoin
|
||||
DarkCoin and other X11 coins
|
||||
Chaincoin and Flaxscript (C11)
|
||||
Saffroncoin blake (256 14-rounds)
|
||||
BlakeCoin (256 8-rounds)
|
||||
Qubit (Digibyte, ...)
|
||||
@@ -65,10 +65,9 @@ its command line interface and options.
|
||||
|
||||
-a, --algo=ALGO specify the algorithm to use
|
||||
anime use to mine Animecoin
|
||||
bitcoin use to mine SHA-256d coins
|
||||
blake use to mine Saffroncoin (Blake 256)
|
||||
blakecoin use to mine Old Blake 256
|
||||
credits use to mine Credits [CRE]
|
||||
c11/flax use to mine Chaincoin and Flax
|
||||
deep use to mine Deepcoin
|
||||
dmd-gr use to mine Diamond-Groestl
|
||||
fresh use to mine Freshcoin
|
||||
@@ -84,7 +83,6 @@ its command line interface and options.
|
||||
neoscrypt use to mine FeatherCoin
|
||||
nist5 use to mine TalkCoin
|
||||
penta use to mine Joincoin / Pentablake
|
||||
pluck use to mine Supcoin
|
||||
quark use to mine Quarkcoin
|
||||
qubit use to mine Qubit
|
||||
scrypt use to mine Scrypt coins
|
||||
@@ -97,6 +95,7 @@ its command line interface and options.
|
||||
x14 use to mine X14Coin
|
||||
x15 use to mine Halcyon
|
||||
x17 use to mine X17
|
||||
whirlpoolx use to mine Vanilla
|
||||
zr5 use to mine ZiftrCoin
|
||||
|
||||
-d, --devices gives a comma separated list of CUDA device IDs
|
||||
@@ -138,6 +137,9 @@ its command line interface and options.
|
||||
--max-temp=N Only mine if gpu temp is less than specified value
|
||||
--max-rate=N[KMG] Only mine if net hashrate is less than specified value
|
||||
--max-diff=N Only mine if net difficulty is less than specified value
|
||||
--pstate=0 will force the Geforce 9xx to run in P0 P-State
|
||||
--plimit=150W set the gpu power limit, allow multiple values for N cards
|
||||
--keep-clocks prevent reset clocks and/or power limit on exit
|
||||
-B, --background run the miner in the background
|
||||
--benchmark run in offline benchmark mode
|
||||
--cputest debug hashes from cpu algorithms
|
||||
@@ -221,14 +223,23 @@ features.
|
||||
|
||||
>>> RELEASE HISTORY <<<
|
||||
|
||||
June 2015 v1.6.5
|
||||
August 2015...
|
||||
Restore WhirlpoolX algo
|
||||
|
||||
July 06th 2015 v1.6.5-C11
|
||||
Nvml api power limits
|
||||
Add chaincoin c11 algo (used by Flaxscript too)
|
||||
Remove pluck algo
|
||||
|
||||
June 23th 2015 v1.6.5
|
||||
Handle Ziftrcoin PoK solo mining
|
||||
Basic compatibility with CUDA 7.0 (generally slower hashrate)
|
||||
Show gpus vendor names on linux (windows test branch is pciutils)
|
||||
Remove -v and -m short params specific to heavycoin
|
||||
Add --diff-multiplier (-m) and rename --diff to --diff-factor (-f)
|
||||
First steps to handle nvml application clocks and P0 on the GTX9xx
|
||||
Optimize qubit, deep and luffa algos
|
||||
Compatibility with CUDA 7.0 (but slower hashrate)
|
||||
Various improvements on multipool and cmdline parameters
|
||||
Import Credits (djm34) and Bitcoin (klaus) "SHA256" algos
|
||||
Optimize a bit qubit, deep, luffa, x11 and quark algos
|
||||
|
||||
May 26th 2015 v1.6.4
|
||||
Implement multi-pool support (failover and time rotate)
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
* Software Foundation; either version 2 of the License, or (at your option)
|
||||
* any later version. See COPYING for more details.
|
||||
*/
|
||||
#define APIVERSION "1.5"
|
||||
#define APIVERSION "1.6"
|
||||
|
||||
#ifdef WIN32
|
||||
# define _WINSOCK_DEPRECATED_NO_WARNINGS
|
||||
@@ -124,6 +124,7 @@ static void gpustatus(int thr_id)
|
||||
cgpu->gpu_temp = gpu_temp(cgpu);
|
||||
cgpu->gpu_fan = (uint16_t) gpu_fanpercent(cgpu);
|
||||
cgpu->gpu_fan_rpm = (uint16_t) gpu_fanrpm(cgpu);
|
||||
cgpu->gpu_power = gpu_power(cgpu);
|
||||
#endif
|
||||
cuda_gpu_clocks(cgpu);
|
||||
|
||||
@@ -135,10 +136,11 @@ static void gpustatus(int thr_id)
|
||||
|
||||
card = device_name[gpuid];
|
||||
|
||||
snprintf(buf, sizeof(buf), "GPU=%d;BUS=%hd;CARD=%s;"
|
||||
"TEMP=%.1f;FAN=%hu;RPM=%hu;FREQ=%d;KHS=%.2f;HWF=%d;I=%.1f;THR=%u|",
|
||||
gpuid, cgpu->gpu_bus, card, cgpu->gpu_temp, cgpu->gpu_fan,
|
||||
cgpu->gpu_fan_rpm, cgpu->gpu_clock, cgpu->khashes,
|
||||
snprintf(buf, sizeof(buf), "GPU=%d;BUS=%hd;CARD=%s;TEMP=%.1f;"
|
||||
"POWER=%u;FAN=%hu;RPM=%hu;FREQ=%d;KHS=%.2f;HWF=%d;I=%.1f;THR=%u|",
|
||||
gpuid, cgpu->gpu_bus, card, cgpu->gpu_temp,
|
||||
cgpu->gpu_power, cgpu->gpu_fan, cgpu->gpu_fan_rpm,
|
||||
cgpu->gpu_clock, cgpu->khashes,
|
||||
cgpu->hw_errors, cgpu->intensity, cgpu->throughput);
|
||||
|
||||
// append to buffer for multi gpus
|
||||
@@ -248,6 +250,7 @@ static void gpuhwinfos(int gpu_id)
|
||||
cgpu->gpu_fan = (uint16_t) gpu_fanpercent(cgpu);
|
||||
cgpu->gpu_fan_rpm = (uint16_t) gpu_fanrpm(cgpu);
|
||||
cgpu->gpu_pstate = (int16_t) gpu_pstate(cgpu);
|
||||
cgpu->gpu_power = gpu_power(cgpu);
|
||||
gpu_info(cgpu);
|
||||
#endif
|
||||
|
||||
@@ -260,12 +263,13 @@ static void gpuhwinfos(int gpu_id)
|
||||
card = device_name[gpu_id];
|
||||
|
||||
snprintf(buf, sizeof(buf), "GPU=%d;BUS=%hd;CARD=%s;SM=%u;MEM=%lu;"
|
||||
"TEMP=%.1f;FAN=%hu;RPM=%hu;FREQ=%d;MEMFREQ=%d;PST=%s;"
|
||||
"TEMP=%.1f;FAN=%hu;RPM=%hu;FREQ=%d;MEMFREQ=%d;PST=%s;POWER=%u;"
|
||||
"VID=%hx;PID=%hx;NVML=%d;NVAPI=%d;SN=%s;BIOS=%s|",
|
||||
gpu_id, cgpu->gpu_bus, card, cgpu->gpu_arch, cgpu->gpu_mem,
|
||||
cgpu->gpu_temp, cgpu->gpu_fan, cgpu->gpu_fan_rpm,
|
||||
cgpu->gpu_clock, cgpu->gpu_memclock,
|
||||
pstate, cgpu->gpu_vid, cgpu->gpu_pid, cgpu->nvml_id, cgpu->nvapi_id,
|
||||
pstate, cgpu->gpu_power,
|
||||
cgpu->gpu_vid, cgpu->gpu_pid, cgpu->nvml_id, cgpu->nvapi_id,
|
||||
cgpu->gpu_sn, cgpu->gpu_desc);
|
||||
|
||||
strcat(buffer, buf);
|
||||
|
||||
@@ -62,6 +62,7 @@ function translateField($key)
|
||||
$intl['TEMP'] = 'T°c';
|
||||
$intl['FAN'] = 'Fan %';
|
||||
$intl['FREQ'] = 'Freq.';
|
||||
$intl['POWER'] = 'Power';
|
||||
$intl['PST'] = 'P-State';
|
||||
|
||||
// pool infos
|
||||
@@ -96,6 +97,9 @@ function translateValue($key,$val,$data=array())
|
||||
case 'FREQ':
|
||||
$val = sprintf("%d MHz", round(floatval($val)/1000.0));
|
||||
break;
|
||||
case 'POWER':
|
||||
$val = sprintf("%d W", round(floatval($val)/1000.0));
|
||||
break;
|
||||
case 'TS':
|
||||
$val = strftime("%H:%M:%S", (int) $val);
|
||||
break;
|
||||
|
||||
+144
-118
@@ -85,12 +85,12 @@ struct workio_cmd {
|
||||
|
||||
enum sha_algos {
|
||||
ALGO_ANIME,
|
||||
ALGO_BITCOIN,
|
||||
ALGO_BLAKE,
|
||||
ALGO_BLAKECOIN,
|
||||
ALGO_CREDITS,
|
||||
ALGO_C11,
|
||||
ALGO_DEEP,
|
||||
ALGO_DMD_GR,
|
||||
ALGO_ETHER,
|
||||
ALGO_FRESH,
|
||||
ALGO_FUGUE256, /* Fugue256 */
|
||||
ALGO_GROESTL,
|
||||
@@ -104,7 +104,6 @@ enum sha_algos {
|
||||
ALGO_NEOSCRYPT,
|
||||
ALGO_NIST5,
|
||||
ALGO_PENTABLAKE,
|
||||
ALGO_PLUCK,
|
||||
ALGO_QUARK,
|
||||
ALGO_QUBIT,
|
||||
ALGO_SCRYPT,
|
||||
@@ -117,17 +116,19 @@ enum sha_algos {
|
||||
ALGO_X14,
|
||||
ALGO_X15,
|
||||
ALGO_X17,
|
||||
ALGO_WHIRLPOOLX,
|
||||
ALGO_ZR5,
|
||||
ALGO_COUNT
|
||||
};
|
||||
|
||||
static const char *algo_names[] = {
|
||||
"anime",
|
||||
"bitcoin",
|
||||
"blake",
|
||||
"blakecoin",
|
||||
"credits",
|
||||
"c11",
|
||||
"deep",
|
||||
"dmd-gr",
|
||||
"ethash",
|
||||
"fresh",
|
||||
"fugue256",
|
||||
"groestl",
|
||||
@@ -141,7 +142,6 @@ static const char *algo_names[] = {
|
||||
"neoscrypt",
|
||||
"nist5",
|
||||
"penta",
|
||||
"pluck",
|
||||
"quark",
|
||||
"qubit",
|
||||
"scrypt",
|
||||
@@ -154,7 +154,9 @@ static const char *algo_names[] = {
|
||||
"x14",
|
||||
"x15",
|
||||
"x17",
|
||||
"whirlpoolx",
|
||||
"zr5",
|
||||
""
|
||||
};
|
||||
|
||||
bool opt_debug = false;
|
||||
@@ -190,8 +192,7 @@ static enum sha_algos opt_algo = ALGO_X11;
|
||||
int opt_n_threads = 0;
|
||||
int opt_affinity = -1;
|
||||
int opt_priority = 0;
|
||||
static double opt_diff_factor = 1.;
|
||||
static double opt_diff_multiplier = 1.;
|
||||
static double opt_difficulty = 1.;
|
||||
bool opt_extranonce = true;
|
||||
bool opt_trust_pool = false;
|
||||
uint16_t opt_vote = 9999;
|
||||
@@ -203,6 +204,9 @@ long device_sm[MAX_GPUS] = { 0 };
|
||||
uint32_t gpus_intensity[MAX_GPUS] = { 0 };
|
||||
uint32_t device_gpu_clocks[MAX_GPUS] = { 0 };
|
||||
uint32_t device_mem_clocks[MAX_GPUS] = { 0 };
|
||||
uint32_t device_plimit[MAX_GPUS] = { 0 };
|
||||
int8_t device_pstate[MAX_GPUS] = { -1 };
|
||||
static bool opt_keep_clocks = false;
|
||||
|
||||
// un-linked to cmdline scrypt options (useless)
|
||||
int device_batchsize[MAX_GPUS] = { 0 };
|
||||
@@ -277,10 +281,9 @@ Usage: " PROGRAM_NAME " [OPTIONS]\n\
|
||||
Options:\n\
|
||||
-a, --algo=ALGO specify the hash algorithm to use\n\
|
||||
anime Animecoin\n\
|
||||
bitcoin SHA256d\n\
|
||||
blake Blake 256 (SFR)\n\
|
||||
blakecoin Fast Blake 256 (8 rounds)\n\
|
||||
credits Credits (CRE) SHA256-168\n\
|
||||
c11/flax X11 variant\n\
|
||||
deep Deepcoin\n\
|
||||
dmd-gr Diamond-Groestl\n\
|
||||
fresh Freshcoin (shavite 80)\n\
|
||||
@@ -296,7 +299,6 @@ Options:\n\
|
||||
neoscrypt FeatherCoin, Phoenix, UFO...\n\
|
||||
nist5 NIST5 (TalkCoin)\n\
|
||||
penta Pentablake hash (5x Blake 512)\n\
|
||||
pluck SupCoin\n\
|
||||
quark Quark\n\
|
||||
qubit Qubit\n\
|
||||
scrypt Scrypt\n\
|
||||
@@ -309,6 +311,7 @@ Options:\n\
|
||||
x14 X14\n\
|
||||
x15 X15\n\
|
||||
x17 X17\n\
|
||||
whirlpoolx WhirlpoolX (VNL)\n\
|
||||
zr5 ZR5 (ZiftrCoin)\n\
|
||||
-d, --devices Comma separated list of CUDA devices to use.\n\
|
||||
Device IDs start counting from 0! Alternatively takes\n\
|
||||
@@ -339,6 +342,7 @@ Options:\n\
|
||||
--no-gbt disable getblocktemplate support (height check in solo)\n\
|
||||
--no-longpoll disable X-Long-Polling support\n\
|
||||
--no-stratum disable X-Stratum support\n\
|
||||
--no-extranonce disable extranonce subscribe on stratum\n\
|
||||
-q, --quiet disable per-thread hashmeter output\n\
|
||||
--no-color disable colored output\n\
|
||||
-D, --debug enable debug output\n\
|
||||
@@ -350,10 +354,12 @@ Options:\n\
|
||||
--max-temp=N Only mine if gpu temp is less than specified value\n\
|
||||
--max-rate=N[KMG] Only mine if net hashrate is less than specified value\n\
|
||||
--max-diff=N Only mine if net difficulty is less than specified value\n"
|
||||
#if defined(USE_WRAPNVML) && defined(__linux)
|
||||
#if defined(USE_WRAPNVML) && (defined(__linux) || defined(_WIN64)) /* via nvml */
|
||||
"\
|
||||
--gpu-clock=1150 Set device application clock\n\
|
||||
--mem-clock=3505 Set the gpu memory clock (require 346.72 linux driver)\n"
|
||||
--mem-clock=3505 Set the gpu memory max clock (346.72+ driver)\n\
|
||||
--gpu-clock=1150 Set the gpu engine max clock (346.72+ driver)\n\
|
||||
--pstate=0[,2] Set the gpu power state (352.21+ driver)\n\
|
||||
--plimit=100W Set the gpu power limit (352.21+ driver)\n"
|
||||
#endif
|
||||
#ifdef HAVE_SYSLOG_H
|
||||
"\
|
||||
@@ -391,6 +397,7 @@ struct option options[] = {
|
||||
{ "intensity", 1, NULL, 'i' },
|
||||
{ "ndevs", 0, NULL, 'n' },
|
||||
{ "no-color", 0, NULL, 1002 },
|
||||
{ "no-extranonce", 0, NULL, 1012 },
|
||||
{ "no-gbt", 0, NULL, 1011 },
|
||||
{ "no-longpoll", 0, NULL, 1003 },
|
||||
{ "no-stratum", 0, NULL, 1007 },
|
||||
@@ -417,6 +424,9 @@ struct option options[] = {
|
||||
{ "statsavg", 1, NULL, 'N' },
|
||||
{ "gpu-clock", 1, NULL, 1070 },
|
||||
{ "mem-clock", 1, NULL, 1071 },
|
||||
{ "pstate", 1, NULL, 1072 },
|
||||
{ "plimit", 1, NULL, 1073 },
|
||||
{ "keep-clocks", 0, NULL, 1074 },
|
||||
#ifdef HAVE_SYSLOG_H
|
||||
{ "syslog", 0, NULL, 'S' },
|
||||
{ "syslog-prefix", 1, NULL, 1018 },
|
||||
@@ -502,7 +512,7 @@ static void affine_to_cpu_mask(int id, uint8_t mask) {
|
||||
}
|
||||
cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID, -1, sizeof(cpuset_t), &set);
|
||||
}
|
||||
#else /* Windows */
|
||||
#elif defined(WIN32) /* Windows */
|
||||
static inline void drop_policy(void) { }
|
||||
static void affine_to_cpu_mask(int id, uint8_t mask) {
|
||||
if (id == -1)
|
||||
@@ -510,6 +520,9 @@ static void affine_to_cpu_mask(int id, uint8_t mask) {
|
||||
else
|
||||
SetThreadAffinityMask(GetCurrentThread(), mask);
|
||||
}
|
||||
#else /* Martians */
|
||||
static inline void drop_policy(void) { }
|
||||
static void affine_to_cpu_mask(int id, uint8_t mask) { }
|
||||
#endif
|
||||
|
||||
static bool get_blocktemplate(CURL *curl, struct work *work);
|
||||
@@ -540,7 +553,7 @@ void proper_exit(int reason)
|
||||
timeEndPeriod(1); // else never executed
|
||||
#endif
|
||||
#ifdef USE_WRAPNVML
|
||||
if (hnvml) {
|
||||
if (hnvml && !opt_keep_clocks) {
|
||||
for (int n=0; n < opt_n_threads; n++) {
|
||||
nvml_reset_clocks(hnvml, device_map[n]);
|
||||
}
|
||||
@@ -594,7 +607,6 @@ static void calc_network_diff(struct work *work)
|
||||
case ALGO_QUARK:
|
||||
diffone = 0xFFFFFF0000000000ull;
|
||||
break;
|
||||
case ALGO_PLUCK:
|
||||
case ALGO_SCRYPT:
|
||||
case ALGO_SCRYPT_JANE:
|
||||
// cant get the right value on these 3 algos...
|
||||
@@ -634,28 +646,13 @@ static void calc_network_diff(struct work *work)
|
||||
|
||||
static bool work_decode(const json_t *val, struct work *work)
|
||||
{
|
||||
int data_size = 128, target_size = sizeof(work->target);
|
||||
int adata_sz, atarget_sz = ARRAY_SIZE(work->target);
|
||||
int midstate_sz = 0;
|
||||
int data_size = sizeof(work->data), target_size = sizeof(work->target);
|
||||
int adata_sz = ARRAY_SIZE(work->data), atarget_sz = ARRAY_SIZE(work->target);
|
||||
int i;
|
||||
|
||||
switch (opt_algo) {
|
||||
case ALGO_NEOSCRYPT:
|
||||
data_size = 84;
|
||||
break;
|
||||
case ALGO_ZR5:
|
||||
data_size = 80;
|
||||
break;
|
||||
case ALGO_BITCOIN:
|
||||
/* note: getwork is no more supported in BTC wallet */
|
||||
midstate_sz = 32;
|
||||
break;
|
||||
case ALGO_CREDITS:
|
||||
data_size = 168;
|
||||
midstate_sz = 32;
|
||||
break;
|
||||
if (opt_algo == ALGO_NEOSCRYPT || opt_algo == ALGO_ZR5) {
|
||||
data_size = 80; adata_sz = 20;
|
||||
}
|
||||
adata_sz = data_size / sizeof(uint32_t);
|
||||
|
||||
if (unlikely(!jobj_binary(val, "data", work->data, data_size))) {
|
||||
applog(LOG_ERR, "JSON inval data");
|
||||
@@ -665,14 +662,6 @@ static bool work_decode(const json_t *val, struct work *work)
|
||||
applog(LOG_ERR, "JSON inval target");
|
||||
return false;
|
||||
}
|
||||
if (midstate_sz) {
|
||||
if (unlikely(!jobj_binary(val, "midstate", work->midstate, midstate_sz))) {
|
||||
applog(LOG_ERR, "JSON inval midstate");
|
||||
return false;
|
||||
}
|
||||
for (i = 0; i < midstate_sz/4 /*sizeof(uint32_t)*/; i++)
|
||||
work->midstate[i] = le32dec(work->midstate + i);
|
||||
}
|
||||
|
||||
if (opt_algo == ALGO_HEAVY) {
|
||||
if (unlikely(!jobj_binary(val, "maxvote", &work->maxvote, sizeof(work->maxvote)))) {
|
||||
@@ -766,9 +755,8 @@ static void calc_target_diff(struct work *work)
|
||||
if (unlikely(!d64))
|
||||
d64 = 1;
|
||||
work->difficulty = (double)diffone / d64;
|
||||
if (opt_diff_factor > 0.)
|
||||
work->difficulty /= opt_diff_factor;
|
||||
work->difficulty *= opt_diff_multiplier;
|
||||
if (opt_difficulty > 0.)
|
||||
work->difficulty /= opt_difficulty;
|
||||
}
|
||||
|
||||
static int share_result(int result, int pooln, const char *reason)
|
||||
@@ -801,8 +789,8 @@ static int share_result(int result, int pooln, const char *reason)
|
||||
if (reason) {
|
||||
applog(LOG_WARNING, "reject reason: %s", reason);
|
||||
/* if (strncasecmp(reason, "low difficulty", 14) == 0) {
|
||||
opt_diff_factor = (opt_diff_factor * 2.0) / 3.0;
|
||||
applog(LOG_WARNING, "factor reduced to : %0.2f", opt_diff_factor);
|
||||
opt_difficulty = (opt_difficulty * 2.0) / 3.0;
|
||||
applog(LOG_WARNING, "difficulty factor reduced to : %0.2f", opt_difficulty);
|
||||
return 0;
|
||||
} */
|
||||
if (!check_dups && strncasecmp(reason, "duplicate", 9) == 0) {
|
||||
@@ -821,6 +809,9 @@ static bool submit_upstream_work(CURL *curl, struct work *work)
|
||||
bool stale_work = false;
|
||||
char s[384];
|
||||
|
||||
if (pool->type & POOL_ETHER)
|
||||
return ether_submitwork(curl, pool, work);
|
||||
|
||||
/* discard if a newer bloc 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) {
|
||||
@@ -915,22 +906,16 @@ static bool submit_upstream_work(CURL *curl, struct work *work)
|
||||
|
||||
} else {
|
||||
|
||||
int data_size = 128, adata_sz;
|
||||
|
||||
switch (opt_algo) {
|
||||
case ALGO_NEOSCRYPT:
|
||||
case ALGO_ZR5:
|
||||
data_size = 80;
|
||||
break;
|
||||
case ALGO_CREDITS:
|
||||
data_size = 168;
|
||||
break;
|
||||
}
|
||||
adata_sz = data_size / sizeof(uint32_t);
|
||||
int data_size = sizeof(work->data);
|
||||
int adata_sz = ARRAY_SIZE(work->data);
|
||||
|
||||
/* build hex string */
|
||||
char *str = NULL;
|
||||
|
||||
if (opt_algo == ALGO_ZR5) {
|
||||
data_size = 80; adata_sz = 20;
|
||||
}
|
||||
|
||||
if (opt_algo != ALGO_HEAVY && opt_algo != ALGO_MJOLLNIR) {
|
||||
for (int i = 0; i < adata_sz; i++)
|
||||
le32enc(work->data + i, work->data[i]);
|
||||
@@ -1066,15 +1051,23 @@ static bool get_mininginfo(CURL *curl, struct work *work)
|
||||
// "blocks": 491493 (= current work height - 1)
|
||||
// "difficulty": 0.99607860999999998
|
||||
// "networkhashps": 56475980
|
||||
// "netmhashps": 351.74414726
|
||||
if (res) {
|
||||
json_t *key = json_object_get(res, "difficulty");
|
||||
if (key && json_is_real(key)) {
|
||||
net_diff = json_real_value(key);
|
||||
if (key) {
|
||||
if (!json_is_real(key))
|
||||
key = json_object_get(key, "proof-of-work");
|
||||
if (json_is_real(key))
|
||||
net_diff = json_real_value(key);
|
||||
}
|
||||
key = json_object_get(res, "networkhashps");
|
||||
if (key && json_is_integer(key)) {
|
||||
net_hashrate = json_integer_value(key);
|
||||
}
|
||||
key = json_object_get(res, "netmhashps");
|
||||
if (key && json_is_real(key)) {
|
||||
net_hashrate = (json_real_value(key) * 1e6);
|
||||
}
|
||||
key = json_object_get(res, "blocks");
|
||||
if (key && json_is_integer(key)) {
|
||||
net_blocks = json_integer_value(key);
|
||||
@@ -1095,6 +1088,10 @@ static bool get_upstream_work(CURL *curl, struct work *work)
|
||||
struct pool_infos *pool = &pools[work->pooln];
|
||||
json_t *val;
|
||||
|
||||
if (pool->type & POOL_ETHER) {
|
||||
return ether_getwork(curl, pool, work);
|
||||
}
|
||||
|
||||
if (opt_debug_threads)
|
||||
applog(LOG_DEBUG, "%s: want_longpoll=%d have_longpoll=%d",
|
||||
__func__, want_longpoll, have_longpoll);
|
||||
@@ -1358,7 +1355,6 @@ err_out:
|
||||
static bool stratum_gen_work(struct stratum_ctx *sctx, struct work *work)
|
||||
{
|
||||
uchar merkle_root[64];
|
||||
double diff_factor = opt_diff_factor;
|
||||
int i;
|
||||
|
||||
if (!sctx->job.job_id) {
|
||||
@@ -1428,7 +1424,6 @@ static bool stratum_gen_work(struct stratum_ctx *sctx, struct work *work)
|
||||
break;
|
||||
}
|
||||
|
||||
// to check...
|
||||
work->data[20] = 0x80000000;
|
||||
work->data[31] = (opt_algo == ALGO_MJOLLNIR) ? 0x000002A0 : 0x00000280;
|
||||
|
||||
@@ -1454,32 +1449,28 @@ static bool stratum_gen_work(struct stratum_ctx *sctx, struct work *work)
|
||||
free(xnonce2str);
|
||||
}
|
||||
|
||||
if (opt_diff_multiplier > 0.)
|
||||
diff_factor /= opt_diff_multiplier;
|
||||
if (diff_factor == 0.)
|
||||
diff_factor = 1.;
|
||||
if (opt_difficulty == 0.)
|
||||
opt_difficulty = 1.;
|
||||
|
||||
switch (opt_algo) {
|
||||
case ALGO_CREDITS:
|
||||
case ALGO_JACKPOT:
|
||||
case ALGO_NEOSCRYPT:
|
||||
case ALGO_PLUCK:
|
||||
case ALGO_SCRYPT:
|
||||
case ALGO_SCRYPT_JANE:
|
||||
diff_to_target(work->target, sctx->job.diff / (65536.0 * diff_factor));
|
||||
diff_to_target(work->target, sctx->job.diff / (65536.0 * opt_difficulty));
|
||||
break;
|
||||
case ALGO_DMD_GR:
|
||||
case ALGO_FRESH:
|
||||
case ALGO_FUGUE256:
|
||||
case ALGO_GROESTL:
|
||||
diff_to_target(work->target, sctx->job.diff / (256.0 * diff_factor));
|
||||
diff_to_target(work->target, sctx->job.diff / (256.0 * opt_difficulty));
|
||||
break;
|
||||
case ALGO_KECCAK:
|
||||
case ALGO_LYRA2:
|
||||
diff_to_target(work->target, sctx->job.diff / (128.0 * diff_factor));
|
||||
diff_to_target(work->target, sctx->job.diff / (128.0 * opt_difficulty));
|
||||
break;
|
||||
default:
|
||||
diff_to_target(work->target, sctx->job.diff / diff_factor);
|
||||
diff_to_target(work->target, sctx->job.diff / opt_difficulty);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -1541,7 +1532,6 @@ static void *miner_thread(void *userdata)
|
||||
struct work work;
|
||||
uint32_t max_nonce;
|
||||
uint32_t end_nonce = UINT32_MAX / opt_n_threads * (thr_id + 1) - (thr_id + 1);
|
||||
uint64_t loopcnt = 0;
|
||||
bool work_done = false;
|
||||
bool extrajob = false;
|
||||
char s[16];
|
||||
@@ -1604,7 +1594,7 @@ static void *miner_thread(void *userdata)
|
||||
uint64_t max64, minmax = 0x100000;
|
||||
|
||||
// &work.data[19]
|
||||
int wcmplen = opt_algo == ALGO_CREDITS ? 140 : 76;
|
||||
int wcmplen = 76;
|
||||
int wcmpoft = 0;
|
||||
uint32_t *nonceptr = (uint32_t*) (((char*)work.data) + wcmplen);
|
||||
|
||||
@@ -1775,18 +1765,17 @@ static void *miner_thread(void *userdata)
|
||||
switch (opt_algo) {
|
||||
case ALGO_BLAKECOIN:
|
||||
case ALGO_BLAKE:
|
||||
case ALGO_WHIRLPOOLX:
|
||||
minmax = 0x80000000U;
|
||||
break;
|
||||
case ALGO_BITCOIN:
|
||||
case ALGO_KECCAK:
|
||||
case ALGO_SKEIN:
|
||||
case ALGO_SKEIN2:
|
||||
minmax = 0x40000000U;
|
||||
break;
|
||||
case ALGO_JACKPOT:
|
||||
case ALGO_LUFFA:
|
||||
minmax = 0x2000000;
|
||||
break;
|
||||
case ALGO_C11:
|
||||
case ALGO_S3:
|
||||
case ALGO_X11:
|
||||
case ALGO_X13:
|
||||
@@ -1798,9 +1787,6 @@ static void *miner_thread(void *userdata)
|
||||
case ALGO_SCRYPT_JANE:
|
||||
minmax = 0x100000;
|
||||
break;
|
||||
case ALGO_PLUCK:
|
||||
minmax = 0x2000;
|
||||
break;
|
||||
}
|
||||
max64 = max(minmax-1, max64);
|
||||
}
|
||||
@@ -1864,6 +1850,11 @@ static void *miner_thread(void *userdata)
|
||||
max_nonce, &hashes_done);
|
||||
break;
|
||||
|
||||
case ALGO_C11:
|
||||
rc = scanhash_c11(thr_id, work.data, work.target,
|
||||
max_nonce, &hashes_done);
|
||||
break;
|
||||
|
||||
case ALGO_FUGUE256:
|
||||
rc = scanhash_fugue256(thr_id, work.data, work.target,
|
||||
max_nonce, &hashes_done);
|
||||
@@ -1900,11 +1891,6 @@ static void *miner_thread(void *userdata)
|
||||
max_nonce, &hashes_done);
|
||||
break;
|
||||
|
||||
case ALGO_BITCOIN:
|
||||
rc = scanhash_bitcoin(thr_id, work.data, work.target,
|
||||
max_nonce, &hashes_done);
|
||||
break;
|
||||
|
||||
case ALGO_BLAKECOIN:
|
||||
rc = scanhash_blake256(thr_id, work.data, work.target,
|
||||
max_nonce, &hashes_done, 8);
|
||||
@@ -1915,11 +1901,6 @@ static void *miner_thread(void *userdata)
|
||||
max_nonce, &hashes_done, 14);
|
||||
break;
|
||||
|
||||
case ALGO_CREDITS:
|
||||
rc = scanhash_credits(thr_id, work.data, work.target,
|
||||
work.midstate, max_nonce, &hashes_done);
|
||||
break;
|
||||
|
||||
case ALGO_FRESH:
|
||||
rc = scanhash_fresh(thr_id, work.data, work.target,
|
||||
max_nonce, &hashes_done);
|
||||
@@ -1945,11 +1926,6 @@ static void *miner_thread(void *userdata)
|
||||
max_nonce, &hashes_done);
|
||||
break;
|
||||
|
||||
case ALGO_PLUCK:
|
||||
rc = scanhash_pluck(thr_id, work.data, work.target,
|
||||
max_nonce, &hashes_done);
|
||||
break;
|
||||
|
||||
case ALGO_SCRYPT:
|
||||
rc = scanhash_scrypt(thr_id, work.data, work.target, NULL,
|
||||
max_nonce, &hashes_done, &tv_start, &tv_end);
|
||||
@@ -1975,6 +1951,11 @@ static void *miner_thread(void *userdata)
|
||||
max_nonce, &hashes_done);
|
||||
break;
|
||||
|
||||
case ALGO_WHIRLPOOLX:
|
||||
rc = scanhash_whirlpoolx(thr_id, work.data, work.target,
|
||||
max_nonce, &hashes_done);
|
||||
break;
|
||||
|
||||
case ALGO_X11:
|
||||
rc = scanhash_x11(thr_id, work.data, work.target,
|
||||
max_nonce, &hashes_done);
|
||||
@@ -2004,6 +1985,10 @@ static void *miner_thread(void *userdata)
|
||||
rc = scanhash_zr5(thr_id, &work, max_nonce, &hashes_done);
|
||||
break;
|
||||
|
||||
case ALGO_ETHER:
|
||||
rc = scanhash_ether(thr_id, &work, max_nonce, &hashes_done);
|
||||
break;
|
||||
|
||||
default:
|
||||
/* should never happen */
|
||||
goto out;
|
||||
@@ -2065,13 +2050,7 @@ static void *miner_thread(void *userdata)
|
||||
hashlog_remember_scan_range(&work);
|
||||
|
||||
/* output */
|
||||
bool display_hashrate = (loopcnt > 0);
|
||||
if (opt_algo == ALGO_CREDITS) {
|
||||
display_hashrate = loopcnt > 800 && !(loopcnt % 400);
|
||||
}
|
||||
loopcnt++;
|
||||
|
||||
if (!opt_quiet && display_hashrate) {
|
||||
if (!opt_quiet && firstwork_time) {
|
||||
format_hashrate(thr_hashrates[thr_id], s);
|
||||
applog(LOG_INFO, "GPU #%d: %s, %s",
|
||||
device_map[thr_id], device_name[device_map[thr_id]], s);
|
||||
@@ -2471,28 +2450,26 @@ void parse_arg(int key, char *arg)
|
||||
case 'a': /* --algo */
|
||||
p = strstr(arg, ":"); // optional factor
|
||||
if (p) *p = '\0';
|
||||
for (i = 0; i < ARRAY_SIZE(algo_names); i++) {
|
||||
for (i = 0; i < ALGO_COUNT; i++) {
|
||||
if (algo_names[i] && !strcasecmp(arg, algo_names[i])) {
|
||||
opt_algo = (enum sha_algos)i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i == ARRAY_SIZE(algo_names)) {
|
||||
if (i == ALGO_COUNT) {
|
||||
// some aliases...
|
||||
if (!strcasecmp("credit", arg))
|
||||
i = opt_algo = ALGO_CREDITS;
|
||||
if (!strcasecmp("flax", arg))
|
||||
i = opt_algo = ALGO_C11;
|
||||
else if (!strcasecmp("diamond", arg))
|
||||
i = opt_algo = ALGO_DMD_GR;
|
||||
else if (!strcasecmp("doom", arg))
|
||||
i = opt_algo = ALGO_LUFFA;
|
||||
else if (!strcasecmp("sha256d", arg))
|
||||
i = opt_algo = ALGO_BITCOIN;
|
||||
else if (!strcasecmp("ziftr", arg))
|
||||
i = opt_algo = ALGO_ZR5;
|
||||
else
|
||||
applog(LOG_ERR, "Unknown algo parameter '%s'", arg);
|
||||
}
|
||||
if (i == ARRAY_SIZE(algo_names))
|
||||
if (i == ALGO_COUNT)
|
||||
show_usage_and_exit(1);
|
||||
if (p) {
|
||||
opt_nfactor = atoi(p + 1);
|
||||
@@ -2797,6 +2774,31 @@ void parse_arg(int key, char *arg)
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 1072: /* --pstate */
|
||||
{
|
||||
char *pch = strtok(arg,",");
|
||||
int n = 0;
|
||||
while (pch != NULL && n < MAX_GPUS) {
|
||||
int dev_id = device_map[n++];
|
||||
device_pstate[dev_id] = (int8_t) atoi(pch);
|
||||
pch = strtok(NULL, ",");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 1073: /* --plimit */
|
||||
{
|
||||
char *pch = strtok(arg,",");
|
||||
int n = 0;
|
||||
while (pch != NULL && n < MAX_GPUS) {
|
||||
int dev_id = device_map[n++];
|
||||
device_plimit[dev_id] = atoi(pch);
|
||||
pch = strtok(NULL, ",");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 1074: /* --keep-clocks */
|
||||
opt_keep_clocks = true;
|
||||
break;
|
||||
case 1005:
|
||||
opt_benchmark = true;
|
||||
want_longpoll = false;
|
||||
@@ -2812,6 +2814,7 @@ void parse_arg(int key, char *arg)
|
||||
break;
|
||||
case 1007:
|
||||
want_stratum = false;
|
||||
opt_extranonce = false;
|
||||
break;
|
||||
case 1008:
|
||||
opt_time_limit = atoi(arg);
|
||||
@@ -2819,6 +2822,9 @@ void parse_arg(int key, char *arg)
|
||||
case 1011:
|
||||
allow_gbt = false;
|
||||
break;
|
||||
case 1012:
|
||||
opt_extranonce = false;
|
||||
break;
|
||||
case 'S':
|
||||
case 1018:
|
||||
applog(LOG_INFO, "Now logging to syslog...");
|
||||
@@ -2894,13 +2900,13 @@ void parse_arg(int key, char *arg)
|
||||
d = atof(arg);
|
||||
if (d <= 0.)
|
||||
show_usage_and_exit(1);
|
||||
opt_diff_factor = d;
|
||||
opt_difficulty = d;
|
||||
break;
|
||||
case 'm': // --diff-multiplier
|
||||
d = atof(arg);
|
||||
if (d <= 0.)
|
||||
show_usage_and_exit(1);
|
||||
opt_diff_multiplier = d;
|
||||
opt_difficulty = 1.0/d;
|
||||
break;
|
||||
|
||||
/* PER POOL CONFIG OPTIONS */
|
||||
@@ -3115,6 +3121,7 @@ int main(int argc, char *argv[])
|
||||
device_interactive[i] = -1;
|
||||
device_texturecache[i] = -1;
|
||||
device_singlememory[i] = -1;
|
||||
device_pstate[i] = -1;
|
||||
}
|
||||
|
||||
// number of gpus
|
||||
@@ -3124,6 +3131,12 @@ int main(int argc, char *argv[])
|
||||
/* parse command line */
|
||||
parse_cmdline(argc, argv);
|
||||
|
||||
// extra credits..
|
||||
if (opt_algo == ALGO_WHIRLPOOLX) {
|
||||
printf(" Whirlpoolx support by Alexis Provos.\n");
|
||||
printf("VNL donation address: Vr5oCen8NrY6ekBWFaaWjCUFBH4dyiS57W\n\n");
|
||||
}
|
||||
|
||||
if (!opt_benchmark && !strlen(rpc_url)) {
|
||||
// try default config file (user then binary folder)
|
||||
char defconfig[MAX_PATH] = { 0 };
|
||||
@@ -3161,6 +3174,10 @@ int main(int argc, char *argv[])
|
||||
cur_pooln = pool_get_first_valid(0);
|
||||
pool_switch(cur_pooln);
|
||||
|
||||
if (opt_algo == ALGO_ETHER) {
|
||||
pools[cur_pooln].type |= POOL_ETHER;
|
||||
}
|
||||
|
||||
flags = !opt_benchmark && strncmp(rpc_url, "https:", 6)
|
||||
? (CURL_GLOBAL_ALL & ~CURL_GLOBAL_SSL)
|
||||
: CURL_GLOBAL_ALL;
|
||||
@@ -3293,21 +3310,30 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
#ifdef USE_WRAPNVML
|
||||
#ifndef WIN32
|
||||
#if defined(__linux__) || defined(_WIN64)
|
||||
/* nvml is currently not the best choice on Windows (only in x64) */
|
||||
hnvml = nvml_create();
|
||||
if (hnvml) {
|
||||
bool gpu_reinit = false;
|
||||
cuda_devicenames(); // refresh gpu vendor name
|
||||
applog(LOG_INFO, "NVML GPU monitoring enabled.");
|
||||
for (int n=0; n < opt_n_threads; n++) {
|
||||
if (nvml_set_pstate(hnvml, device_map[n]) == 1)
|
||||
gpu_reinit = true;
|
||||
if (nvml_set_plimit(hnvml, device_map[n]) == 1)
|
||||
gpu_reinit = true;
|
||||
if (nvml_set_clocks(hnvml, device_map[n]) == 1)
|
||||
gpu_reinit = true;
|
||||
if (gpu_reinit)
|
||||
cuda_reset_device(n, NULL);
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (nvapi_init() == 0)
|
||||
#endif
|
||||
#ifdef WIN32
|
||||
if (!hnvml && nvapi_init() == 0)
|
||||
applog(LOG_INFO, "NVAPI GPU monitoring enabled.");
|
||||
#endif
|
||||
else
|
||||
else if (!hnvml)
|
||||
applog(LOG_INFO, "GPU monitoring is not available.");
|
||||
#endif
|
||||
|
||||
|
||||
+13
-13
@@ -157,7 +157,7 @@
|
||||
<MaxRegCount>80</MaxRegCount>
|
||||
<PtxAsOptionV>true</PtxAsOptionV>
|
||||
<Keep>true</Keep>
|
||||
<CodeGeneration>compute_35,sm_35;compute_50,sm_50;compute_52,sm_52</CodeGeneration>
|
||||
<CodeGeneration>compute_50,sm_50;compute_52,sm_52;compute_30,sm_30;compute_35,sm_35</CodeGeneration>
|
||||
<AdditionalOptions>--ptxas-options="-O2" %(AdditionalOptions)</AdditionalOptions>
|
||||
<Optimization>O2</Optimization>
|
||||
</CudaCompile>
|
||||
@@ -269,7 +269,6 @@
|
||||
<ExcludedFromBuild>true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="sph\sha2.c" />
|
||||
<ClCompile Include="sph\sha256d.c" />
|
||||
<ClCompile Include="sph\sha2big.c" />
|
||||
<ClCompile Include="sph\shabal.c" />
|
||||
<ClCompile Include="sph\shavite.c" />
|
||||
@@ -336,11 +335,8 @@
|
||||
<CudaCompile Include="cuda.cpp" />
|
||||
<CudaCompile Include="cuda_groestlcoin.cu" />
|
||||
<CudaCompile Include="cuda_myriadgroestl.cu" />
|
||||
<CudaCompile Include="cuda_nist5.cu" />
|
||||
<CudaCompile Include="sha256\bitcoin.cu" />
|
||||
<CudaCompile Include="sha256\cuda_bitcoin.cu" />
|
||||
<CudaCompile Include="sha256\credits.cu" />
|
||||
<CudaCompile Include="sha256\cuda_credits.cu" />
|
||||
<CudaCompile Include="cuda_nist5.cu">
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="scrypt\blake.cu" />
|
||||
<CudaCompile Include="scrypt\keccak.cu" />
|
||||
<CudaCompile Include="scrypt\sha256.cu" />
|
||||
@@ -425,8 +421,6 @@
|
||||
<AdditionalOptions Condition="'$(Configuration)'=='Release'">-Xptxas "-abi=yes" %(AdditionalOptions)</AdditionalOptions>
|
||||
<AdditionalOptions Condition="'$(Configuration)'=='Debug'">-Xptxas "-abi=yes" %(AdditionalOptions)</AdditionalOptions>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="pluck\pluck.cu" />
|
||||
<CudaCompile Include="pluck\cuda_pluck.cu" />
|
||||
<CudaCompile Include="quark\cuda_quark_groestl512.cu">
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="quark\cuda_quark_keccak512.cu">
|
||||
@@ -468,8 +462,8 @@
|
||||
<CudaCompile Include="x11\cuda_x11_simd512.cu">
|
||||
<MaxRegCount>64</MaxRegCount>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="x11\fresh.cu">
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="x11\c11.cu" />
|
||||
<CudaCompile Include="x11\fresh.cu" />
|
||||
<CudaCompile Include="x11\s3.cu" />
|
||||
<CudaCompile Include="x11\simd_functions.cu">
|
||||
<ExcludedFromBuild>true</ExcludedFromBuild>
|
||||
@@ -489,8 +483,8 @@
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="x15\x15.cu">
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="x15\cuda_x15_whirlpool.cu">
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="x15\cuda_whirlpoolx.cu" />
|
||||
<CudaCompile Include="x15\whirlpoolx.cu" />
|
||||
<CudaCompile Include="x17\x17.cu">
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="x17\cuda_x17_haval512.cu">
|
||||
@@ -498,6 +492,12 @@
|
||||
<CudaCompile Include="x17\cuda_x17_sha512.cu">
|
||||
<MaxRegCount>80</MaxRegCount>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="x15\x14.cu">
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="x15\x15.cu">
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="x17\x17.cu">
|
||||
</CudaCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Image Include="res\ccminer.ico" />
|
||||
|
||||
+9
-24
@@ -79,9 +79,6 @@
|
||||
<Filter Include="Source Files\neoscrypt">
|
||||
<UniqueIdentifier>{2037fd0d-e7a2-4da8-956c-150aec726a99}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Source Files\CUDA\sha256">
|
||||
<UniqueIdentifier>{6def248f-bf21-43b0-8fd7-f2c749b73e9e}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="compat\jansson\dump.c">
|
||||
@@ -183,9 +180,6 @@
|
||||
<ClCompile Include="sph\haval_helper.c">
|
||||
<Filter>Source Files\sph</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="sph\sha256d.c">
|
||||
<Filter>Source Files\sph</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="sph\sha2big.c">
|
||||
<Filter>Source Files\sph</Filter>
|
||||
</ClCompile>
|
||||
@@ -439,12 +433,6 @@
|
||||
<CudaCompile Include="JHA\cuda_jha_compactionTest.cu">
|
||||
<Filter>Source Files\CUDA\JHA</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="pluck\pluck.cu">
|
||||
<Filter>Source Files\CUDA</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="pluck\cuda_pluck.cu">
|
||||
<Filter>Source Files\CUDA</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="quark\cuda_jh512.cu">
|
||||
<Filter>Source Files\CUDA\quark</Filter>
|
||||
</CudaCompile>
|
||||
@@ -529,6 +517,9 @@
|
||||
<CudaCompile Include="x11\cuda_x11_simd512.cu">
|
||||
<Filter>Source Files\CUDA\x11</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="x11\c11.cu">
|
||||
<Filter>Source Files\CUDA\x11</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="x11\fresh.cu">
|
||||
<Filter>Source Files\CUDA\x11</Filter>
|
||||
</CudaCompile>
|
||||
@@ -562,6 +553,12 @@
|
||||
<CudaCompile Include="x15\cuda_x15_whirlpool.cu">
|
||||
<Filter>Source Files\CUDA\x15</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="x15\cuda_whirlpoolx.cu">
|
||||
<Filter>Source Files\CUDA\x15</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="x15\whirlpoolx.cu">
|
||||
<Filter>Source Files\CUDA\x15</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="x17\cuda_x17_haval512.cu">
|
||||
<Filter>Source Files\CUDA\x17</Filter>
|
||||
</CudaCompile>
|
||||
@@ -646,18 +643,6 @@
|
||||
<CudaCompile Include="neoscrypt\cuda_neoscrypt.cu">
|
||||
<Filter>Source Files\neoscrypt</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="sha256\bitcoin.cu">
|
||||
<Filter>Source Files\CUDA\sha256</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="sha256\cuda_bitcoin.cu">
|
||||
<Filter>Source Files\CUDA\sha256</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="sha256\credits.cu">
|
||||
<Filter>Source Files\CUDA\sha256</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="sha256\cuda_credits.cu">
|
||||
<Filter>Source Files\CUDA\sha256</Filter>
|
||||
</CudaCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Image Include="res\ccminer.ico">
|
||||
|
||||
+28
-31
@@ -54,42 +54,39 @@ static const char rcsid[]="$Id: getopt_long.c,v 1.1 2009/10/16 19:50:28 rodney E
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if 0
|
||||
#include <err.h>
|
||||
#endif
|
||||
#include <errno.h>
|
||||
#include <getopt.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
/* Windows needs warnx(). We change the definition though:
|
||||
* 1. (another) global is defined, opterrmsg, which holds the error message
|
||||
* 2. errors are always printed out on stderr w/o the program name
|
||||
* Note that opterrmsg always gets set no matter what opterr is set to. The
|
||||
* error message will not be printed if opterr is 0 as usual.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
char opterrmsg[128]; /* last error message is stored here */
|
||||
|
||||
static void warnx(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
if (fmt != NULL)
|
||||
_vsnprintf(opterrmsg, 128, fmt, ap);
|
||||
else
|
||||
opterrmsg[0]='\0';
|
||||
va_end(ap);
|
||||
fprintf(stderr, opterrmsg);
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
/* Windows needs warnx(). We change the definition though:
|
||||
* 1. (another) global is defined, opterrmsg, which holds the error message
|
||||
* 2. errors are always printed out on stderr w/o the program name
|
||||
* Note that opterrmsg always gets set no matter what opterr is set to. The
|
||||
* error message will not be printed if opterr is 0 as usual.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
char opterrmsg[128]; /* last error message is stored here */
|
||||
|
||||
static void warnx(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
if (fmt != NULL)
|
||||
_vsnprintf(opterrmsg, 128, fmt, ap);
|
||||
else
|
||||
opterrmsg[0]='\0';
|
||||
va_end(ap);
|
||||
fprintf(stderr, opterrmsg);
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
#endif /*_WIN32*/
|
||||
|
||||
#define REPLACE_GETOPT /* use this getopt as the system getopt(3) */
|
||||
|
||||
+8
-1
@@ -1,4 +1,4 @@
|
||||
AC_INIT([ccminer], [1.6.5-git])
|
||||
AC_INIT([ccminer], [1.6.6-dev])
|
||||
|
||||
AC_PREREQ([2.59c])
|
||||
AC_CANONICAL_SYSTEM
|
||||
@@ -72,9 +72,16 @@ AC_CHECK_LIB([pthread], [pthread_create], PTHREAD_LIBS="-lpthread",
|
||||
AC_CHECK_LIB([pthreadGC], [pthread_create], PTHREAD_LIBS="-lpthreadGC"
|
||||
))))
|
||||
|
||||
AC_CHECK_LIB([z],[gzopen], [], [])
|
||||
AC_CHECK_LIB([ssl],[SSL_library_init], [], [AC_MSG_ERROR([OpenSSL library required])])
|
||||
AC_CHECK_LIB([crypto],[EVP_DigestFinal_ex], [], [AC_MSG_ERROR([OpenSSL library required])])
|
||||
|
||||
# libpci-dev (to get vendor name)
|
||||
PCILIB=""; PCIFLAGS=""
|
||||
AC_CHECK_LIB([pci],[pci_alloc], PCILIB="-lpci"; PCIFLAGS="-DHAVE_PCIDEV", [])
|
||||
AC_SUBST(PCILIB)
|
||||
AC_SUBST(PCIFLAGS)
|
||||
|
||||
AM_CONDITIONAL([WANT_JANSSON], [test x$request_jansson = xtrue])
|
||||
AM_CONDITIONAL([HAVE_WINDOWS], [test x$have_win32 = xtrue])
|
||||
AM_CONDITIONAL([ARCH_x86], [test x$have_x86 = xtrue])
|
||||
|
||||
+6
-3
@@ -47,6 +47,9 @@
|
||||
/* Define to 1 if you have the `ssl' library (-lssl). */
|
||||
#define HAVE_LIBSSL 1
|
||||
|
||||
/* Define to 1 if you have the `z' library (-lz). */
|
||||
#define HAVE_LIBZ 1
|
||||
|
||||
/* Define to 1 if you have the <memory.h> header file. */
|
||||
#define HAVE_MEMORY_H 1
|
||||
|
||||
@@ -159,7 +162,7 @@
|
||||
#define PACKAGE_NAME "ccminer"
|
||||
|
||||
/* Define to the full name and version of this package. */
|
||||
#define PACKAGE_STRING "ccminer 1.6.5-git"
|
||||
#define PACKAGE_STRING "ccminer 1.6.6-dev"
|
||||
|
||||
/* Define to the one symbol short name of this package. */
|
||||
#define PACKAGE_TARNAME "ccminer"
|
||||
@@ -168,7 +171,7 @@
|
||||
#define PACKAGE_URL "http://github.com/tpruvot/ccminer"
|
||||
|
||||
/* Define to the version of this package. */
|
||||
#define PACKAGE_VERSION "1.6.5-git"
|
||||
#define PACKAGE_VERSION "1.6.6-dev"
|
||||
|
||||
/* If using the C implementation of alloca, define if you know the
|
||||
direction of stack growth for your system; otherwise it will be
|
||||
@@ -182,7 +185,7 @@
|
||||
#define STDC_HEADERS 1
|
||||
|
||||
/* Version number of package */
|
||||
#define VERSION "1.6.5-git"
|
||||
#define VERSION "1.6.6-dev"
|
||||
|
||||
/* Define curl_free() as free() if our version of curl lacks curl_free. */
|
||||
/* #undef curl_free */
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#endif
|
||||
|
||||
#include "miner.h"
|
||||
#include "nvml.h"
|
||||
|
||||
#include "cuda_runtime.h"
|
||||
|
||||
@@ -64,23 +65,40 @@ void cuda_devicenames()
|
||||
GPU_N = min(MAX_GPUS, GPU_N);
|
||||
for (int i=0; i < GPU_N; i++)
|
||||
{
|
||||
char vendorname[32] = { 0 };
|
||||
cudaDeviceProp props;
|
||||
cudaGetDeviceProperties(&props, device_map[i]);
|
||||
|
||||
device_name[i] = strdup(props.name);
|
||||
device_sm[i] = (props.major * 100 + props.minor * 10);
|
||||
|
||||
if (device_name[i]) {
|
||||
free(device_name[i]);
|
||||
device_name[i] = NULL;
|
||||
}
|
||||
#ifdef USE_WRAPNVML
|
||||
if (gpu_vendor((uint8_t)props.pciBusID, vendorname) > 0 && strlen(vendorname)) {
|
||||
device_name[i] = (char*) calloc(1, strlen(vendorname) + strlen(props.name) + 2);
|
||||
if (!strncmp(props.name, "GeForce ", 8))
|
||||
sprintf(device_name[i], "%s %s", vendorname, &props.name[8]);
|
||||
else
|
||||
sprintf(device_name[i], "%s %s", vendorname, props.name);
|
||||
} else
|
||||
#endif
|
||||
device_name[i] = strdup(props.name);
|
||||
}
|
||||
}
|
||||
|
||||
void cuda_print_devices()
|
||||
{
|
||||
int ngpus = cuda_num_devices();
|
||||
cuda_devicenames();
|
||||
for (int n=0; n < ngpus; n++) {
|
||||
int m = device_map[n];
|
||||
cudaDeviceProp props;
|
||||
cudaGetDeviceProperties(&props, m);
|
||||
if (!opt_n_threads || n < opt_n_threads)
|
||||
fprintf(stderr, "GPU #%d: SM %d.%d %s\n", m, props.major, props.minor, props.name);
|
||||
if (!opt_n_threads || n < opt_n_threads) {
|
||||
fprintf(stderr, "GPU #%d: SM %d.%d %s\n", m, props.major, props.minor, device_name[n]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -309,7 +309,6 @@ uint64_t shr_t64(uint64_t x, uint32_t n)
|
||||
#endif
|
||||
}
|
||||
|
||||
// device asm for ?
|
||||
__device__ __forceinline__
|
||||
uint64_t shl_t64(uint64_t x, uint32_t n)
|
||||
{
|
||||
@@ -324,40 +323,6 @@ uint64_t shl_t64(uint64_t x, uint32_t n)
|
||||
#endif
|
||||
}
|
||||
|
||||
// device asm 32 for pluck
|
||||
__device__ __forceinline__
|
||||
uint32_t andor32(uint32_t a, uint32_t b, uint32_t c) {
|
||||
#ifdef __CUDA_ARCH__
|
||||
uint32_t result;
|
||||
asm("{ .reg .u32 m,n,o;\n\t"
|
||||
"and.b32 m, %1, %2;\n\t"
|
||||
" or.b32 n, %1, %2;\n\t"
|
||||
"and.b32 o, n, %3;\n\t"
|
||||
" or.b32 %0, m, o ;\n\t"
|
||||
"}\n\t"
|
||||
: "=r"(result) : "r"(a), "r"(b), "r"(c));
|
||||
return result;
|
||||
#else
|
||||
// unused on host...
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
__device__ __forceinline__
|
||||
uint32_t xor3b(uint32_t a, uint32_t b, uint32_t c) {
|
||||
#ifdef __CUDA_ARCH__
|
||||
uint32_t result;
|
||||
asm("{ .reg .u32 t1;\n\t"
|
||||
"xor.b32 t1, %2, %3;\n\t"
|
||||
"xor.b32 %0, %1, t1;\n\t"
|
||||
"}"
|
||||
: "=r"(result) : "r"(a) ,"r"(b),"r"(c));
|
||||
return result;
|
||||
#else
|
||||
return a^b^c;
|
||||
#endif
|
||||
}
|
||||
|
||||
__device__ __forceinline__
|
||||
uint32_t shr_t32(uint32_t x,uint32_t n) {
|
||||
#ifdef __CUDA_ARCH__
|
||||
|
||||
@@ -0,0 +1,531 @@
|
||||
/*
|
||||
* Genoil's CUDA mining kernel for Ethereum
|
||||
* based on Tim Hughes' opencl kernel.
|
||||
* thanks to tpruvot,djm34,sp,cbuchner for things i took from ccminer.
|
||||
*/
|
||||
|
||||
#define SHUFFLE_MIN_VER 9350
|
||||
|
||||
|
||||
#include "miner.h"
|
||||
#include "cuda_helper.h"
|
||||
#include "ethash_cu_miner_kernel.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <memory.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
#include "vector_types.h"
|
||||
|
||||
#include "rotl64.cuh"
|
||||
#include "keccak.cuh"
|
||||
|
||||
//#include "ethash_cu_miner_kernel_globals.h"
|
||||
__constant__ uint32_t d_dag_size;
|
||||
__constant__ uint32_t d_max_outputs;
|
||||
|
||||
#define ACCESSES 64
|
||||
#define THREADS_PER_HASH (128 / 16) /* 8 */
|
||||
|
||||
#define FNV_PRIME 0x01000193
|
||||
|
||||
#define SWAP64(v) \
|
||||
((ROTL64L(v, 8) & 0x000000FF000000FF) | \
|
||||
(ROTL64L(v, 24) & 0x0000FF000000FF00) | \
|
||||
(ROTL64H(v, 40) & 0x00FF000000FF0000) | \
|
||||
(ROTL64H(v, 56) & 0xFF000000FF000000))
|
||||
|
||||
#undef SWAP64
|
||||
#define SWAP64(v) cuda_swab64(v)
|
||||
|
||||
#define PACK64(result, lo, hi) asm("mov.b64 %0, {%1,%2};//pack64" : "=l"(result) : "r"(lo), "r"(hi));
|
||||
#define UNPACK64(lo, hi, input) asm("mov.b64 {%0, %1}, %2;//unpack64" : "=r"(lo),"=r"(hi) : "l"(input));
|
||||
|
||||
#define copy(dst, src, count) for (uint32_t i = 0; i < count; i++) { (dst)[i] = (src)[i]; }
|
||||
|
||||
#define countof(x) (sizeof(x) / sizeof(x[0]))
|
||||
|
||||
#define fnv(x,y) ((x) * FNV_PRIME ^(y))
|
||||
|
||||
__device__ uint4 fnv4(uint4 a, uint4 b)
|
||||
{
|
||||
uint4 c;
|
||||
c.x = a.x * FNV_PRIME ^ b.x;
|
||||
c.y = a.y * FNV_PRIME ^ b.y;
|
||||
c.z = a.z * FNV_PRIME ^ b.z;
|
||||
c.w = a.w * FNV_PRIME ^ b.w;
|
||||
return c;
|
||||
}
|
||||
|
||||
__device__ uint32_t fnv_reduce(uint4 v)
|
||||
{
|
||||
return fnv(fnv(fnv(v.x, v.y), v.z), v.w);
|
||||
}
|
||||
|
||||
|
||||
__device__ void init_hash(hash32_t const* header, uint64_t nonce, hash64_t &init)
|
||||
{
|
||||
// sha3_512(header .. nonce)
|
||||
uint64_t state[25] = { 0 };
|
||||
|
||||
//copy(state, header->uint64s, 4);
|
||||
#pragma unroll
|
||||
for (int i = 0; i < 4; i++) state[i] = header->uint64s[i];
|
||||
|
||||
state[4] = nonce;
|
||||
state[5] = 0x0000000000000001;
|
||||
//state[6] = 0;
|
||||
//state[7] = 0;
|
||||
state[8] = 0x8000000000000000;
|
||||
//for (uint32_t i = 9; i < 25; i++) {
|
||||
// state[i] = 0;
|
||||
//}
|
||||
|
||||
keccak_f1600_block(state, 8);
|
||||
|
||||
//copy(init.uint64s, state, 8);
|
||||
#pragma unroll
|
||||
for (int i = 0; i < 8; i++) init.uint64s[i] = state[i];
|
||||
}
|
||||
|
||||
__device__ uint32_t inner_loop(uint4 mix, uint32_t thread_id, uint32_t* share, hash128_t const* g_dag)
|
||||
{
|
||||
// share init0
|
||||
if (thread_id == 0)
|
||||
*share = mix.x;
|
||||
|
||||
uint32_t init0 = *share;
|
||||
|
||||
uint32_t a = 0;
|
||||
|
||||
do
|
||||
{
|
||||
|
||||
bool update_share = thread_id == ((a >> 2) & (THREADS_PER_HASH-1));
|
||||
|
||||
//#pragma unroll 4
|
||||
for (uint32_t i = 0; i < 4; i++)
|
||||
{
|
||||
|
||||
if (update_share)
|
||||
{
|
||||
uint32_t m[4] = { mix.x, mix.y, mix.z, mix.w };
|
||||
*share = fnv(init0 ^ (a + i), m[i]) % d_dag_size;
|
||||
}
|
||||
__threadfence_block();
|
||||
|
||||
#if __CUDA_ARCH__ >= 350
|
||||
mix = fnv4(mix, __ldg(&g_dag[*share].uint4s[thread_id]));
|
||||
#else
|
||||
mix = fnv4(mix, g_dag[*share].uint4s[thread_id]);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
} while ((a += 4) != ACCESSES);
|
||||
|
||||
return fnv_reduce(mix);
|
||||
}
|
||||
|
||||
__device__ void final_hash(hash64_t const* init, hash32_t const* mix, hash32_t &hash)
|
||||
{
|
||||
uint64_t state[25] = { 0 };
|
||||
|
||||
// keccak_256(keccak_512(header..nonce) .. mix);
|
||||
copy(state, init->uint64s, 8);
|
||||
copy(state + 8, mix->uint64s, 4);
|
||||
state[12] = 0x0000000000000001;
|
||||
//#pragma unroll
|
||||
//for (uint32_t i = 13; i < 16; i++)
|
||||
//{
|
||||
//state[i] = 0;
|
||||
//}
|
||||
state[16] = 0x8000000000000000;
|
||||
//#pragma unroll
|
||||
//for (uint32_t i = 17; i < 25; i++)
|
||||
//{
|
||||
//state[i] = 0;
|
||||
//}
|
||||
|
||||
keccak_f1600_block(state,1);
|
||||
|
||||
// copy out
|
||||
copy(hash.uint64s, state, 4);
|
||||
}
|
||||
|
||||
typedef union
|
||||
{
|
||||
hash64_t init;
|
||||
hash32_t mix;
|
||||
} compute_hash_share;
|
||||
|
||||
#if __CUDA_ARCH__ >= SHUFFLE_MIN_VER
|
||||
__device__ uint64_t compute_hash_shuffle(
|
||||
hash32_t const* g_header,
|
||||
hash128_t const* g_dag,
|
||||
uint64_t nonce
|
||||
)
|
||||
{
|
||||
// sha3_512(header .. nonce)
|
||||
uint64_t state[25];
|
||||
|
||||
copy(state, g_header->uint64s, 4);
|
||||
state[4] = nonce;
|
||||
state[5] = 0x0000000000000001ULL;
|
||||
for (uint32_t i = 6; i < 25; i++)
|
||||
{
|
||||
state[i] = 0;
|
||||
}
|
||||
state[8] = 0x8000000000000000ULL;
|
||||
keccak_f1600_block(state, 8);
|
||||
|
||||
// Threads work together in this phase in groups of 8.
|
||||
const int thread_id = threadIdx.x & (THREADS_PER_HASH - 1);
|
||||
const int start_lane = threadIdx.x & ~(THREADS_PER_HASH - 1);
|
||||
const int mix_idx = (thread_id & 3);
|
||||
|
||||
uint4 mix;
|
||||
|
||||
uint32_t shuffle[16];
|
||||
//uint32_t * init = (uint32_t *)state;
|
||||
|
||||
uint32_t init[16];
|
||||
UNPACK64(init[0], init[1], state[0]);
|
||||
UNPACK64(init[2], init[3], state[1]);
|
||||
UNPACK64(init[4], init[5], state[2]);
|
||||
UNPACK64(init[6], init[7], state[3]);
|
||||
UNPACK64(init[8], init[9], state[4]);
|
||||
UNPACK64(init[10], init[11], state[5]);
|
||||
UNPACK64(init[12], init[13], state[6]);
|
||||
UNPACK64(init[14], init[15], state[7]);
|
||||
|
||||
for (int i = 0; i < THREADS_PER_HASH; i++)
|
||||
{
|
||||
|
||||
// share init among threads
|
||||
for (int j = 0; j < 16; j++)
|
||||
shuffle[j] = __shfl(init[j], start_lane + i);
|
||||
|
||||
// ugly but avoids local reads/writes
|
||||
if (mix_idx == 0) {
|
||||
mix = make_uint4(shuffle[0], shuffle[1], shuffle[2], shuffle[3]);
|
||||
}
|
||||
else if (mix_idx == 1) {
|
||||
mix = make_uint4(shuffle[4], shuffle[5], shuffle[6], shuffle[7]);
|
||||
}
|
||||
else if (mix_idx == 2) {
|
||||
mix = make_uint4(shuffle[8], shuffle[9], shuffle[10], shuffle[11]);
|
||||
}
|
||||
else {
|
||||
mix = make_uint4(shuffle[12], shuffle[13], shuffle[14], shuffle[15]);
|
||||
}
|
||||
|
||||
uint32_t init0 = __shfl(shuffle[0], start_lane);
|
||||
|
||||
|
||||
for (uint32_t a = 0; a < ACCESSES; a+=4)
|
||||
{
|
||||
int t = ((a >> 2) & (THREADS_PER_HASH - 1));
|
||||
|
||||
for (uint32_t b = 0; b < 4; b++)
|
||||
{
|
||||
if (thread_id == t)
|
||||
{
|
||||
shuffle[0] = fnv(init0 ^ (a + b), ((uint32_t *)&mix)[b]) % d_dag_size;;
|
||||
}
|
||||
shuffle[0] = __shfl(shuffle[0], start_lane + t);
|
||||
|
||||
mix = fnv4(mix, g_dag[shuffle[0]].uint4s[thread_id]);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t thread_mix = fnv_reduce(mix);
|
||||
|
||||
// update mix accross threads
|
||||
|
||||
for (int j = 0; j < 8; j++)
|
||||
shuffle[j] = __shfl(thread_mix, start_lane + j);
|
||||
|
||||
if (i == thread_id) {
|
||||
|
||||
//move mix into state:
|
||||
PACK64(state[8], shuffle[0], shuffle[1]);
|
||||
PACK64(state[9], shuffle[2], shuffle[3]);
|
||||
PACK64(state[10], shuffle[4], shuffle[5]);
|
||||
PACK64(state[11], shuffle[6], shuffle[7]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// keccak_256(keccak_512(header..nonce) .. mix);
|
||||
state[12] = 0x0000000000000001ULL;
|
||||
for (uint32_t i = 13; i < 25; i++)
|
||||
{
|
||||
state[i] = 0ULL;
|
||||
}
|
||||
state[16] = 0x8000000000000000;
|
||||
keccak_f1600_block(state, 1);
|
||||
|
||||
return state[0];
|
||||
}
|
||||
#endif
|
||||
|
||||
__device__ void compute_hash(
|
||||
hash32_t const* g_header,
|
||||
hash128_t const* g_dag,
|
||||
uint64_t nonce,
|
||||
hash32_t &out
|
||||
)
|
||||
{
|
||||
extern __shared__ compute_hash_share share[];
|
||||
|
||||
// Compute one init hash per work item.
|
||||
hash64_t init;
|
||||
init_hash(g_header, nonce, init);
|
||||
|
||||
// Threads work together in this phase in groups of 8.
|
||||
uint32_t const thread_id = threadIdx.x & (THREADS_PER_HASH-1);
|
||||
uint32_t const hash_id = threadIdx.x >> 3;
|
||||
|
||||
hash32_t mix;
|
||||
|
||||
for (int i = 0; i < THREADS_PER_HASH; i++)
|
||||
{
|
||||
// share init with other threads
|
||||
if (i == thread_id)
|
||||
share[hash_id].init = init;
|
||||
|
||||
uint4 thread_init = share[hash_id].init.uint4s[thread_id & 3];
|
||||
|
||||
uint32_t thread_mix = inner_loop(thread_init, thread_id, share[hash_id].mix.uint32s, g_dag);
|
||||
|
||||
share[hash_id].mix.uint32s[thread_id] = thread_mix;
|
||||
|
||||
|
||||
if (i == thread_id)
|
||||
mix = share[hash_id].mix;
|
||||
}
|
||||
|
||||
final_hash(&init, &mix, out);
|
||||
}
|
||||
|
||||
__global__ void
|
||||
__launch_bounds__(128, 7)
|
||||
ethash_search(
|
||||
uint32_t* g_output,
|
||||
hash32_t const* g_header,
|
||||
hash128_t const* g_dag,
|
||||
uint64_t start_nonce,
|
||||
uint64_t target
|
||||
)
|
||||
{
|
||||
|
||||
uint32_t const gid = blockIdx.x * blockDim.x + threadIdx.x;
|
||||
|
||||
#if 0 // _CUDA_ARCH__ >= SHUFFLE_MIN_VER
|
||||
uint64_t hash = compute_hash_shuffle(g_header, g_dag, start_nonce + gid);
|
||||
if (SWAP64(hash) < target)
|
||||
{
|
||||
atomicInc(g_output, d_max_outputs);
|
||||
g_output[g_output[0]] = gid;
|
||||
}
|
||||
#else
|
||||
hash32_t hash;
|
||||
compute_hash(g_header, g_dag, start_nonce + gid, hash);
|
||||
if (SWAP64(hash.uint64s[0]) <= target)
|
||||
{
|
||||
atomicInc(g_output,d_max_outputs);
|
||||
g_output[g_output[0]] = gid;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
}
|
||||
|
||||
void run_ethash_hash(
|
||||
hash32_t* g_hashes,
|
||||
hash32_t const* g_header,
|
||||
hash128_t const* g_dag,
|
||||
uint64_t start_nonce
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
void run_ethash_search(
|
||||
uint32_t blocks,
|
||||
uint32_t threads,
|
||||
cudaStream_t stream,
|
||||
uint32_t* g_output,
|
||||
hash32_t const* g_header,
|
||||
hash128_t const* g_dag,
|
||||
uint64_t start_nonce,
|
||||
uint64_t target
|
||||
)
|
||||
{
|
||||
#if __CUDA_ARCH__ >= SHUFFLE_MIN_VER
|
||||
ethash_search <<<blocks, threads, 0, stream>>>(g_output, g_header, g_dag, start_nonce, target);
|
||||
#else
|
||||
ethash_search <<<blocks, threads, (sizeof(compute_hash_share) * threads) / THREADS_PER_HASH, stream>>>(g_output, g_header, g_dag, start_nonce, target);
|
||||
#endif
|
||||
}
|
||||
|
||||
cudaError set_constants(
|
||||
uint32_t * dag_size,
|
||||
uint32_t * max_outputs
|
||||
)
|
||||
{
|
||||
cudaError result;
|
||||
result = cudaMemcpyToSymbol(d_dag_size, dag_size, sizeof(uint32_t));
|
||||
result = cudaMemcpyToSymbol(d_max_outputs, max_outputs, sizeof(uint32_t));
|
||||
return result;
|
||||
}
|
||||
|
||||
static unsigned m_search_batch_size = 262144;
|
||||
static unsigned m_workgroup_size = 64;
|
||||
|
||||
static __thread hash128_t * m_dag_ptr;
|
||||
static __thread hash32_t * m_header;
|
||||
|
||||
//static void* m_hash_buf[MAX_GPUS] = { 0 };
|
||||
static uint32_t* m_search_buf[MAX_GPUS] = { 0 };
|
||||
static cudaStream_t m_streams[MAX_GPUS] = { 0 };
|
||||
|
||||
static uint64_t dagSize = 0;
|
||||
static int fdDAG = -1;
|
||||
static uint8_t const *dag = NULL;
|
||||
|
||||
uint32_t const c_zero = 0;
|
||||
|
||||
#define ETHASH_MIX_BYTES 128
|
||||
#define MIX_WORDS (ETHASH_MIX_BYTES/4)
|
||||
|
||||
|
||||
uint8_t* alloc_dag_file(uint32_t rev, uint32_t* seedhash)
|
||||
{
|
||||
uint8_t* buffer = NULL;
|
||||
char fn[256];
|
||||
struct stat stat_buf;
|
||||
int rc;
|
||||
|
||||
sprintf(fn, "%s/.ethash/full-R%u-%08x%08x", getenv("HOME"), rev, seedhash[7], seedhash[6]);
|
||||
|
||||
rc = stat(fn, &stat_buf);
|
||||
fdDAG = open(fn, O_RDONLY);
|
||||
if (rc != 0) {
|
||||
applog(LOG_ERR, "Unable to open DAG file %s (%d)!", fn, rc);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
dagSize = stat_buf.st_size - 8;
|
||||
|
||||
#ifdef __linux__
|
||||
buffer = (uint8_t*) (mmap(NULL, dagSize, PROT_READ, MAP_FILE | MAP_SHARED | MAP_POPULATE , fdDAG, 0));
|
||||
#else
|
||||
buffer = (uint8_t*) (mmap(NULL, dagSize, PROT_READ, MAP_FILE | MAP_SHARED), fdDAG, 0));
|
||||
#endif
|
||||
if (buffer == MAP_FAILED) {
|
||||
applog(LOG_ERR, "Unable to map DAG file %s!", fn);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (buffer[0] != 0xfe) {
|
||||
applog(LOG_ERR, "DAG file header is bad %s!", fn);
|
||||
close(fdDAG);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return (buffer+8);
|
||||
}
|
||||
|
||||
void close_dag_file(uint8_t const *dag)
|
||||
{
|
||||
uint8_t* buffer = dag ? (uint8_t*) dag - 8 : NULL;
|
||||
munmap(buffer, dagSize);
|
||||
dag = NULL;
|
||||
close(fdDAG);
|
||||
fdDAG = -1;
|
||||
}
|
||||
|
||||
static bool init[MAX_GPUS] = { 0 };
|
||||
|
||||
int scanhash_ether(int thr_id, struct work *work, uint64_t max_nonce, unsigned long *hashes_done)
|
||||
{
|
||||
uint32_t *pdata = work->data;
|
||||
uint32_t *ptarget = work->target;
|
||||
uint32_t *pseed = &work->data[8];
|
||||
|
||||
const uint64_t first_nonce = (((uint64_t)pdata[20]) << 32) + pdata[19];
|
||||
uint64_t nonce = first_nonce;
|
||||
|
||||
uint32_t throughput = device_intensity(thr_id, __func__, 1U << 18);
|
||||
throughput = min(throughput, max_nonce - first_nonce);
|
||||
|
||||
if (!dagSize) {
|
||||
dag = alloc_dag_file(23, pseed);
|
||||
applog(LOG_NOTICE, "DAG size=%ld", (long int) dagSize);
|
||||
}
|
||||
|
||||
//0000.0000 0050.4c39c 047378ad262a995be73cc504643443728e1ca415bae9208
|
||||
uint64_t target64 = ptarget[7];
|
||||
target64 = (target64 << 32) + ptarget[6];
|
||||
|
||||
if (!init[thr_id])
|
||||
{
|
||||
uint32_t dag_size = (unsigned)(dagSize / ETHASH_MIX_BYTES);
|
||||
uint32_t max_outputs=63;
|
||||
|
||||
cudaSetDevice(device_map[thr_id]);
|
||||
|
||||
// create buffer for header256
|
||||
cudaMalloc(&m_header, 32);
|
||||
|
||||
// create mining buffer
|
||||
cudaMalloc(&m_search_buf[thr_id], 8 * sizeof(uint32_t));
|
||||
//cudaMalloc(&m_hash_buf[thr_id], c_hash_batch_size * 32);
|
||||
|
||||
//cudaStreamCreate(&m_streams[thr_id]);
|
||||
m_streams[thr_id] = 0;
|
||||
|
||||
// create buffer for dag
|
||||
CUDA_SAFE_CALL(cudaMalloc(&m_dag_ptr, dagSize));
|
||||
CUDA_SAFE_CALL(cudaMemcpy(m_dag_ptr, dag, dagSize, cudaMemcpyHostToDevice));
|
||||
|
||||
CUDA_SAFE_CALL(set_constants(&dag_size, &max_outputs));
|
||||
|
||||
init[thr_id] = true;
|
||||
}
|
||||
else if (dag) {
|
||||
close_dag_file(dag);
|
||||
}
|
||||
|
||||
CUDA_SAFE_CALL(cudaMemcpy(m_header, work->data, 32, cudaMemcpyHostToDevice));
|
||||
CUDA_SAFE_CALL(cudaMemcpy(m_search_buf[thr_id], &c_zero, 4, cudaMemcpyHostToDevice));
|
||||
|
||||
uint32_t results[8] = { 0 };
|
||||
do {
|
||||
results[0] = 0;
|
||||
CUDA_SAFE_CALL(cudaMemset(m_search_buf[thr_id], 0, sizeof(uint32_t)));
|
||||
|
||||
run_ethash_search(m_search_batch_size / m_workgroup_size, m_workgroup_size, m_streams[thr_id], m_search_buf[thr_id], m_header, m_dag_ptr, nonce, target64);
|
||||
|
||||
CUDA_SAFE_CALL(cudaThreadSynchronize());
|
||||
CUDA_SAFE_CALL(cudaMemcpyAsync(results, m_search_buf[thr_id], 2*sizeof(uint32_t), cudaMemcpyDeviceToHost, m_streams[thr_id]));
|
||||
|
||||
unsigned num_found = results[0];
|
||||
if (num_found) {
|
||||
nonce = nonce + results[1];
|
||||
pdata[19] = (uint32_t) nonce;
|
||||
pdata[20] = (uint32_t) (nonce >> 32);
|
||||
return 1;
|
||||
}
|
||||
|
||||
nonce += throughput;
|
||||
|
||||
} while (nonce < max_nonce && !work_restart[thr_id].restart);
|
||||
|
||||
*hashes_done = nonce - first_nonce + 1;
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
#ifndef _ETHASH_CU_MINER_KERNEL_H_
|
||||
#define _ETHASH_CU_MINER_KERNEL_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
typedef union
|
||||
{
|
||||
uint64_t uint64s[16 / sizeof(uint64_t)];
|
||||
uint32_t uint32s[16 / sizeof(uint32_t)];
|
||||
} hash16_t;
|
||||
|
||||
typedef union
|
||||
{
|
||||
uint32_t uint32s[32 / sizeof(uint32_t)];
|
||||
uint64_t uint64s[32 / sizeof(uint64_t)];
|
||||
} hash32_t;
|
||||
|
||||
|
||||
typedef union
|
||||
{
|
||||
uint32_t uint32s[64 / sizeof(uint32_t)];
|
||||
uint64_t uint64s[64 / sizeof(uint64_t)];
|
||||
uint4 uint4s[64 / sizeof(uint4)];
|
||||
} hash64_t;
|
||||
|
||||
|
||||
typedef union
|
||||
{
|
||||
uint32_t uint32s[128 / sizeof(uint32_t)];
|
||||
uint4 uint4s[128 / sizeof(uint4)];
|
||||
} hash128_t;
|
||||
|
||||
//typedef uint32_t hash128_t;
|
||||
|
||||
cudaError set_constants(
|
||||
uint32_t * dag_size,
|
||||
uint32_t * max_outputs
|
||||
);
|
||||
|
||||
void run_ethash_hash(
|
||||
hash32_t* g_hashes,
|
||||
hash32_t const* g_header,
|
||||
hash128_t const* g_dag,
|
||||
uint64_t start_nonce
|
||||
);
|
||||
|
||||
void run_ethash_search(
|
||||
uint32_t search_batch_size,
|
||||
uint32_t workgroup_size,
|
||||
cudaStream_t stream,
|
||||
uint32_t* g_output,
|
||||
hash32_t const* g_header,
|
||||
hash128_t const* g_dag,
|
||||
uint64_t start_nonce,
|
||||
uint64_t target
|
||||
);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,510 @@
|
||||
#include "cpuminer-config.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <stdarg.h>
|
||||
#include <unistd.h>
|
||||
//#include <jansson.h>
|
||||
|
||||
#include <curl/curl.h>
|
||||
|
||||
#ifdef WIN32
|
||||
#include <winsock2.h>
|
||||
#include <mstcpip.h>
|
||||
#else
|
||||
#include <errno.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/tcp.h>
|
||||
#endif
|
||||
|
||||
#include "miner.h"
|
||||
|
||||
struct data_buffer {
|
||||
void *buf;
|
||||
size_t len;
|
||||
};
|
||||
|
||||
struct upload_buffer {
|
||||
const void *buf;
|
||||
size_t len;
|
||||
size_t pos;
|
||||
};
|
||||
|
||||
struct header_info {
|
||||
char *lp_path;
|
||||
char *reason;
|
||||
char *stratum_url;
|
||||
};
|
||||
|
||||
static void databuf_free(struct data_buffer *db)
|
||||
{
|
||||
if (!db)
|
||||
return;
|
||||
|
||||
free(db->buf);
|
||||
|
||||
memset(db, 0, sizeof(*db));
|
||||
}
|
||||
|
||||
static size_t all_data_cb(const void *ptr, size_t size, size_t nmemb,
|
||||
void *user_data)
|
||||
{
|
||||
struct data_buffer *db = (struct data_buffer *)user_data;
|
||||
size_t len = size * nmemb;
|
||||
size_t oldlen, newlen;
|
||||
void *newmem;
|
||||
static const uchar zero = 0;
|
||||
|
||||
oldlen = db->len;
|
||||
newlen = oldlen + len;
|
||||
|
||||
newmem = realloc(db->buf, newlen + 1);
|
||||
if (!newmem)
|
||||
return 0;
|
||||
|
||||
db->buf = newmem;
|
||||
db->len = newlen;
|
||||
memcpy((char*)db->buf + oldlen, ptr, len);
|
||||
memcpy((char*)db->buf + newlen, &zero, 1); /* null terminate */
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
static size_t upload_data_cb(void *ptr, size_t size, size_t nmemb,
|
||||
void *user_data)
|
||||
{
|
||||
struct upload_buffer *ub = (struct upload_buffer *)user_data;
|
||||
unsigned int len = (unsigned int)(size * nmemb);
|
||||
|
||||
if (len > ub->len - ub->pos)
|
||||
len = (unsigned int)(ub->len - ub->pos);
|
||||
|
||||
if (len) {
|
||||
memcpy(ptr, (char*)ub->buf + ub->pos, len);
|
||||
ub->pos += len;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
#if LIBCURL_VERSION_NUM >= 0x071200
|
||||
static int seek_data_cb(void *user_data, curl_off_t offset, int origin)
|
||||
{
|
||||
struct upload_buffer *ub = (struct upload_buffer *)user_data;
|
||||
|
||||
switch (origin) {
|
||||
case SEEK_SET:
|
||||
ub->pos = (size_t)offset;
|
||||
break;
|
||||
case SEEK_CUR:
|
||||
ub->pos += (size_t)offset;
|
||||
break;
|
||||
case SEEK_END:
|
||||
ub->pos = ub->len + (size_t)offset;
|
||||
break;
|
||||
default:
|
||||
return 1; /* CURL_SEEKFUNC_FAIL */
|
||||
}
|
||||
|
||||
return 0; /* CURL_SEEKFUNC_OK */
|
||||
}
|
||||
#endif
|
||||
|
||||
static size_t resp_hdr_cb(void *ptr, size_t size, size_t nmemb, void *user_data)
|
||||
{
|
||||
struct header_info *hi = (struct header_info *)user_data;
|
||||
size_t remlen, slen, ptrlen = size * nmemb;
|
||||
char *rem, *val = NULL, *key = NULL;
|
||||
void *tmp;
|
||||
|
||||
val = (char*)calloc(1, ptrlen);
|
||||
key = (char*)calloc(1, ptrlen);
|
||||
if (!key || !val)
|
||||
goto out;
|
||||
|
||||
tmp = memchr(ptr, ':', ptrlen);
|
||||
if (!tmp || (tmp == ptr)) /* skip empty keys / blanks */
|
||||
goto out;
|
||||
slen = (size_t)((char*)tmp - (char*)ptr);
|
||||
if ((slen + 1) == ptrlen) /* skip key w/ no value */
|
||||
goto out;
|
||||
memcpy(key, ptr, slen); /* store & nul term key */
|
||||
key[slen] = 0;
|
||||
|
||||
rem = (char*)ptr + slen + 1; /* trim value's leading whitespace */
|
||||
remlen = ptrlen - slen - 1;
|
||||
while ((remlen > 0) && (isspace(*rem))) {
|
||||
remlen--;
|
||||
rem++;
|
||||
}
|
||||
|
||||
memcpy(val, rem, remlen); /* store value, trim trailing ws */
|
||||
val[remlen] = 0;
|
||||
while ((*val) && (isspace(val[strlen(val) - 1]))) {
|
||||
val[strlen(val) - 1] = 0;
|
||||
}
|
||||
if (!*val) /* skip blank value */
|
||||
goto out;
|
||||
|
||||
if (!strcasecmp("X-Long-Polling", key)) {
|
||||
hi->lp_path = val; /* X-Mining-Extensions: longpoll */
|
||||
val = NULL;
|
||||
}
|
||||
|
||||
if (!strcasecmp("X-Reject-Reason", key)) {
|
||||
hi->reason = val; /* X-Mining-Extensions: reject-reason */
|
||||
//applog(LOG_WARNING, "%s:%s", key, val);
|
||||
val = NULL;
|
||||
}
|
||||
|
||||
if (!strcasecmp("X-Stratum", key)) {
|
||||
hi->stratum_url = val; /* steal memory reference */
|
||||
val = NULL;
|
||||
}
|
||||
|
||||
if (!strcasecmp("X-Nonce-Range", key)) {
|
||||
/* todo when available: X-Mining-Extensions: noncerange */
|
||||
}
|
||||
out:
|
||||
free(key);
|
||||
free(val);
|
||||
return ptrlen;
|
||||
}
|
||||
|
||||
#if LIBCURL_VERSION_NUM >= 0x070f06
|
||||
static int sockopt_keepalive_cb(void *userdata, curl_socket_t fd,
|
||||
curlsocktype purpose)
|
||||
{
|
||||
int keepalive = 1;
|
||||
int tcp_keepcnt = 3;
|
||||
int tcp_keepidle = 50;
|
||||
int tcp_keepintvl = 50;
|
||||
#ifdef WIN32
|
||||
DWORD outputBytes;
|
||||
#endif
|
||||
|
||||
#ifndef WIN32
|
||||
if (unlikely(setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &keepalive,
|
||||
sizeof(keepalive))))
|
||||
return 1;
|
||||
#ifdef __linux
|
||||
if (unlikely(setsockopt(fd, SOL_TCP, TCP_KEEPCNT,
|
||||
&tcp_keepcnt, sizeof(tcp_keepcnt))))
|
||||
return 1;
|
||||
if (unlikely(setsockopt(fd, SOL_TCP, TCP_KEEPIDLE,
|
||||
&tcp_keepidle, sizeof(tcp_keepidle))))
|
||||
return 1;
|
||||
if (unlikely(setsockopt(fd, SOL_TCP, TCP_KEEPINTVL,
|
||||
&tcp_keepintvl, sizeof(tcp_keepintvl))))
|
||||
return 1;
|
||||
#endif /* __linux */
|
||||
#ifdef __APPLE_CC__
|
||||
if (unlikely(setsockopt(fd, IPPROTO_TCP, TCP_KEEPALIVE,
|
||||
&tcp_keepintvl, sizeof(tcp_keepintvl))))
|
||||
return 1;
|
||||
#endif /* __APPLE_CC__ */
|
||||
#else /* WIN32 */
|
||||
struct tcp_keepalive vals;
|
||||
vals.onoff = 1;
|
||||
vals.keepalivetime = tcp_keepidle * 1000;
|
||||
vals.keepaliveinterval = tcp_keepintvl * 1000;
|
||||
if (unlikely(WSAIoctl(fd, SIO_KEEPALIVE_VALS, &vals, sizeof(vals),
|
||||
NULL, 0, &outputBytes, NULL, NULL)))
|
||||
return 1;
|
||||
#endif /* WIN32 */
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static json_t *ether_json_rpc(CURL *curl, const char *url, const char *rpc_req, int *curl_err)
|
||||
{
|
||||
char len_hdr[64], hashrate_hdr[64];
|
||||
char curl_err_str[CURL_ERROR_SIZE] = { 0 };
|
||||
struct data_buffer all_data = { 0 };
|
||||
struct upload_buffer upload_data;
|
||||
struct curl_slist *headers = NULL;
|
||||
struct header_info hi = { 0 };
|
||||
char *httpdata;
|
||||
json_t *val, *err_val, *res_val;
|
||||
json_error_t err;
|
||||
int rc;
|
||||
|
||||
long timeout = opt_timeout;
|
||||
bool keepalive = false;
|
||||
|
||||
/* it is assumed that 'curl' is freshly [re]initialized at this pt */
|
||||
|
||||
if (opt_protocol)
|
||||
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
|
||||
curl_easy_setopt(curl, CURLOPT_URL, url);
|
||||
if (opt_cert)
|
||||
curl_easy_setopt(curl, CURLOPT_CAINFO, opt_cert);
|
||||
curl_easy_setopt(curl, CURLOPT_ENCODING, "");
|
||||
curl_easy_setopt(curl, CURLOPT_FAILONERROR, 0);
|
||||
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
|
||||
curl_easy_setopt(curl, CURLOPT_TCP_NODELAY, 1);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, all_data_cb);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &all_data);
|
||||
curl_easy_setopt(curl, CURLOPT_READFUNCTION, upload_data_cb);
|
||||
curl_easy_setopt(curl, CURLOPT_READDATA, &upload_data);
|
||||
#if LIBCURL_VERSION_NUM >= 0x071200
|
||||
curl_easy_setopt(curl, CURLOPT_SEEKFUNCTION, &seek_data_cb);
|
||||
curl_easy_setopt(curl, CURLOPT_SEEKDATA, &upload_data);
|
||||
#endif
|
||||
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curl_err_str);
|
||||
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
|
||||
curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout);
|
||||
curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, resp_hdr_cb);
|
||||
curl_easy_setopt(curl, CURLOPT_HEADERDATA, &hi);
|
||||
if (opt_proxy) {
|
||||
curl_easy_setopt(curl, CURLOPT_PROXY, opt_proxy);
|
||||
curl_easy_setopt(curl, CURLOPT_PROXYTYPE, opt_proxy_type);
|
||||
}
|
||||
#if 0
|
||||
if (userpass) {
|
||||
curl_easy_setopt(curl, CURLOPT_USERPWD, userpass);
|
||||
curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
|
||||
}
|
||||
#endif
|
||||
#if LIBCURL_VERSION_NUM >= 0x070f06
|
||||
if (keepalive)
|
||||
curl_easy_setopt(curl, CURLOPT_SOCKOPTFUNCTION, sockopt_keepalive_cb);
|
||||
#endif
|
||||
curl_easy_setopt(curl, CURLOPT_POST, 1);
|
||||
|
||||
if (opt_protocol)
|
||||
applog(LOG_DEBUG, "JSON protocol request:\n%s", rpc_req);
|
||||
|
||||
upload_data.buf = rpc_req;
|
||||
upload_data.len = strlen(rpc_req);
|
||||
upload_data.pos = 0;
|
||||
sprintf(len_hdr, "Content-Length: %lu", (unsigned long) upload_data.len);
|
||||
sprintf(hashrate_hdr, "X-Mining-Hashrate: %llu", (unsigned long long) global_hashrate);
|
||||
|
||||
headers = curl_slist_append(headers, "Content-Type: application/json");
|
||||
headers = curl_slist_append(headers, len_hdr);
|
||||
headers = curl_slist_append(headers, "User-Agent: " USER_AGENT);
|
||||
headers = curl_slist_append(headers, "X-Mining-Extensions: longpoll noncerange reject-reason");
|
||||
headers = curl_slist_append(headers, hashrate_hdr);
|
||||
headers = curl_slist_append(headers, "Accept:"); /* disable Accept hdr*/
|
||||
headers = curl_slist_append(headers, "Expect:"); /* disable Expect hdr*/
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
|
||||
|
||||
rc = curl_easy_perform(curl);
|
||||
if (curl_err != NULL)
|
||||
*curl_err = rc;
|
||||
if (rc) {
|
||||
if (rc != CURLE_OPERATION_TIMEDOUT) {
|
||||
applog(LOG_ERR, "HTTP request failed: %s", curl_err_str);
|
||||
goto err_out;
|
||||
}
|
||||
}
|
||||
|
||||
if (!all_data.buf || !all_data.len) {
|
||||
applog(LOG_ERR, "Empty data received in json_rpc_call.");
|
||||
goto err_out;
|
||||
}
|
||||
|
||||
httpdata = (char*) all_data.buf;
|
||||
|
||||
if (*httpdata != '{' && *httpdata != '[') {
|
||||
long errcode = 0;
|
||||
CURLcode c = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &errcode);
|
||||
if (c == CURLE_OK && errcode == 401) {
|
||||
applog(LOG_ERR, "You are not authorized, check your login and password.");
|
||||
goto err_out;
|
||||
}
|
||||
}
|
||||
|
||||
val = JSON_LOADS(httpdata, &err);
|
||||
if (!val) {
|
||||
applog(LOG_ERR, "JSON decode failed(%d): %s", err.line, err.text);
|
||||
if (opt_protocol)
|
||||
applog(LOG_DEBUG, "%s", httpdata);
|
||||
goto err_out;
|
||||
}
|
||||
|
||||
if (opt_protocol) {
|
||||
char *s = json_dumps(val, JSON_INDENT(3));
|
||||
applog(LOG_DEBUG, "JSON protocol response:\n%s\n", s);
|
||||
free(s);
|
||||
}
|
||||
|
||||
/* JSON-RPC valid response returns a non-null 'result',
|
||||
* and a null 'error'. */
|
||||
res_val = json_object_get(val, "result");
|
||||
err_val = json_object_get(val, "error");
|
||||
|
||||
if (!res_val || json_is_null(res_val) ||
|
||||
(err_val && !json_is_null(err_val))) {
|
||||
char *s = NULL;
|
||||
|
||||
if (err_val) {
|
||||
s = json_dumps(err_val, 0);
|
||||
json_t *msg = json_object_get(err_val, "message");
|
||||
json_t *err_code = json_object_get(err_val, "code");
|
||||
if (curl_err && json_integer_value(err_code))
|
||||
*curl_err = (int) json_integer_value(err_code);
|
||||
|
||||
if (json_is_string(msg)) {
|
||||
free(s);
|
||||
s = strdup(json_string_value(msg));
|
||||
if (have_longpoll && s && !strcmp(s, "method not getwork")) {
|
||||
json_decref(err_val);
|
||||
free(s);
|
||||
goto err_out;
|
||||
}
|
||||
}
|
||||
json_decref(err_val);
|
||||
}
|
||||
else
|
||||
s = strdup("(unknown reason)");
|
||||
|
||||
if (!curl_err || opt_debug)
|
||||
applog(LOG_ERR, "JSON-RPC call failed: %s", s);
|
||||
|
||||
free(s);
|
||||
|
||||
goto err_out;
|
||||
}
|
||||
|
||||
if (hi.reason)
|
||||
json_object_set_new(val, "reject-reason", json_string(hi.reason));
|
||||
|
||||
databuf_free(&all_data);
|
||||
curl_slist_free_all(headers);
|
||||
curl_easy_reset(curl);
|
||||
return val;
|
||||
|
||||
err_out:
|
||||
free(hi.lp_path);
|
||||
free(hi.reason);
|
||||
free(hi.stratum_url);
|
||||
databuf_free(&all_data);
|
||||
curl_slist_free_all(headers);
|
||||
curl_easy_reset(curl);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Made for len 32
|
||||
bool hex2uint(uint32_t *target, const char *hexstr, int len)
|
||||
{
|
||||
char buf[32];
|
||||
char pad[80];
|
||||
char hex_byte[3];
|
||||
char *ep;
|
||||
char *p = buf;
|
||||
char *hex = pad;
|
||||
|
||||
hex_byte[2] = '\0';
|
||||
|
||||
// pad, we can receive non padded numbers (0x44 => 0x0044)
|
||||
size_t hexlen = strlen(hexstr);
|
||||
if (hexlen < len*2)
|
||||
memset(hex, '0', len*2 - hexlen);
|
||||
sprintf(&hex[len*2 - hexlen],"%s", hexstr);
|
||||
|
||||
while (*hex && len) {
|
||||
if (!hex[1]) {
|
||||
applog(LOG_ERR, "hex2uint str truncated");
|
||||
return false;
|
||||
}
|
||||
hex_byte[0] = hex[0];
|
||||
hex_byte[1] = hex[1];
|
||||
*p = (uchar) strtol(hex_byte, &ep, 16);
|
||||
if (*ep) {
|
||||
applog(LOG_ERR, "hex2uint failed on '%s'", hex_byte);
|
||||
return false;
|
||||
}
|
||||
p++;
|
||||
hex += 2;
|
||||
len--;
|
||||
if (len % 8 == 0) {
|
||||
//..
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < 8; i++) {
|
||||
be32enc(&target[7 - i], ((uint32_t*)buf)[i]);
|
||||
}
|
||||
|
||||
return (len == 0 && *hexstr == 0) ? true : false;
|
||||
}
|
||||
|
||||
void uint2hex(char *out, uint32_t *in, int len)
|
||||
{
|
||||
if (out) {
|
||||
for (int i = 0; i < len/sizeof(uint32_t); i++)
|
||||
sprintf(out + (i * 8), "%08x", in[7-i]);
|
||||
}
|
||||
}
|
||||
|
||||
bool ether_getwork(CURL *curl, struct pool_infos *pool, struct work *work)
|
||||
{
|
||||
char req[512];
|
||||
bool ret = false;
|
||||
|
||||
sprintf(req, "{ \"jsonrpc\": \"2.0\", \"method\": \"eth_getWork\", \"params\": [], \"id\": 4 }\r\n");
|
||||
json_t *result = ether_json_rpc(curl, pool->url, req, NULL);
|
||||
if (result)
|
||||
ret = true;
|
||||
|
||||
json_t *arr = json_object_get(result, "result");
|
||||
if (!json_is_array(arr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const char *header = json_string_value(json_array_get(arr, 0));
|
||||
const char *seed = json_string_value(json_array_get(arr, 1));
|
||||
const char *target = json_string_value(json_array_get(arr, 2));
|
||||
|
||||
//0x2b800e3ffcafdf7ffdd5b2ea1c0ed79c534e92b3459331eae61597943d0743bc
|
||||
//0x356e5a2cc1eba076e650ac7473fccc37952b46bc2e419a200cec0c451dce2336
|
||||
//0x000000000050ec7dea051867e987e3eed0066a128f161b5776a8f5da326b06ec
|
||||
|
||||
applog(LOG_NOTICE, "%s %s %s", header, seed, target);
|
||||
|
||||
hex2uint(work->data, &header[2], 32);
|
||||
hex2uint(&work->data[8], &seed[2], 32);
|
||||
hex2uint(work->target, &target[2], 32);
|
||||
|
||||
//applog(LOG_BLUE, "%08x %08x", work->target[7], work->target[6]);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool ether_submitwork(CURL *curl, struct pool_infos *pool, struct work *work)
|
||||
{
|
||||
char req[512];
|
||||
bool ret = false;
|
||||
char noncehex[32]={0}, header[80]={0}, mixhash[80]={0};
|
||||
|
||||
sprintf(noncehex, "0x%08x%08x", work->data[20], work->data[19]);
|
||||
uint2hex(header, work->data, 32);
|
||||
uint2hex(mixhash, &work->data[24], 32);
|
||||
|
||||
applog(LOG_NOTICE, "%s mixhash:", __func__);
|
||||
applog_hash((uchar*)&work->data[24]);
|
||||
|
||||
sprintf(req, "{ \"jsonrpc\": \"2.0\", \"method\": \"eth_submitWork\","
|
||||
"\"params\": [\"%s\", \"0x%s\", \"0x%s\"], \"id\": 4 }\r\n",
|
||||
noncehex, header, mixhash
|
||||
);
|
||||
json_t *result = ether_json_rpc(curl, pool->url, req, NULL);
|
||||
if (result)
|
||||
ret = true;
|
||||
|
||||
json_t *res = json_object_get(result, "result");
|
||||
if (!json_is_true(res)) {
|
||||
applog(LOG_ERR, "not true! %s", json_dumps(result, JSON_INDENT(3)));
|
||||
exit(0);
|
||||
return false;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
__device__ __constant__ uint64_t const keccak_round_constants[24] = {
|
||||
0x0000000000000001ULL, 0x0000000000008082ULL, 0x800000000000808AULL,
|
||||
0x8000000080008000ULL, 0x000000000000808BULL, 0x0000000080000001ULL,
|
||||
0x8000000080008081ULL, 0x8000000000008009ULL, 0x000000000000008AULL,
|
||||
0x0000000000000088ULL, 0x0000000080008009ULL, 0x000000008000000AULL,
|
||||
0x000000008000808BULL, 0x800000000000008BULL, 0x8000000000008089ULL,
|
||||
0x8000000000008003ULL, 0x8000000000008002ULL, 0x8000000000000080ULL,
|
||||
0x000000000000800AULL, 0x800000008000000AULL, 0x8000000080008081ULL,
|
||||
0x8000000000008080ULL, 0x0000000080000001ULL, 0x8000000080008008ULL
|
||||
};
|
||||
|
||||
__device__ static void keccak_f1600_block(uint64_t* s, uint32_t out_size)//, uint32_t in_size, uint32_t out_size)
|
||||
{
|
||||
uint64_t t[5], u, v;
|
||||
|
||||
for (size_t i = 0; i < 24; i++) {
|
||||
/* theta: c = a[0,i] ^ a[1,i] ^ .. a[4,i] */
|
||||
t[0] = s[0] ^ s[5] ^ s[10] ^ s[15] ^ s[20];
|
||||
t[1] = s[1] ^ s[6] ^ s[11] ^ s[16] ^ s[21];
|
||||
t[2] = s[2] ^ s[7] ^ s[12] ^ s[17] ^ s[22];
|
||||
t[3] = s[3] ^ s[8] ^ s[13] ^ s[18] ^ s[23];
|
||||
t[4] = s[4] ^ s[9] ^ s[14] ^ s[19] ^ s[24];
|
||||
|
||||
/* theta: d[i] = c[i+4] ^ rotl(c[i+1],1) */
|
||||
/* theta: a[0,i], a[1,i], .. a[4,i] ^= d[i] */
|
||||
u = t[4] ^ ROTL64L(t[1], 1);
|
||||
s[0] ^= u; s[5] ^= u; s[10] ^= u; s[15] ^= u; s[20] ^= u;
|
||||
u = t[0] ^ ROTL64L(t[2], 1);
|
||||
s[1] ^= u; s[6] ^= u; s[11] ^= u; s[16] ^= u; s[21] ^= u;
|
||||
u = t[1] ^ ROTL64L(t[3], 1);
|
||||
s[2] ^= u; s[7] ^= u; s[12] ^= u; s[17] ^= u; s[22] ^= u;
|
||||
u = t[2] ^ ROTL64L(t[4], 1);
|
||||
s[3] ^= u; s[8] ^= u; s[13] ^= u; s[18] ^= u; s[23] ^= u;
|
||||
u = t[3] ^ ROTL64L(t[0], 1);
|
||||
s[4] ^= u; s[9] ^= u; s[14] ^= u; s[19] ^= u; s[24] ^= u;
|
||||
|
||||
/* rho pi: b[..] = rotl(a[..], ..) */
|
||||
u = s[1];
|
||||
|
||||
s[1] = ROTL64H(s[6], 44);
|
||||
s[6] = ROTL64L(s[9], 20);
|
||||
s[9] = ROTL64H(s[22], 61);
|
||||
s[22] = ROTL64H(s[14], 39);
|
||||
s[14] = ROTL64L(s[20], 18);
|
||||
s[20] = ROTL64H(s[2], 62);
|
||||
s[2] = ROTL64H(s[12], 43);
|
||||
s[12] = ROTL64L(s[13], 25);
|
||||
s[13] = ROTL64L(s[19], 8);
|
||||
s[19] = ROTL64H(s[23], 56);
|
||||
s[23] = ROTL64H(s[15], 41);
|
||||
s[15] = ROTL64L(s[4], 27);
|
||||
s[4] = ROTL64L(s[24], 14);
|
||||
s[24] = ROTL64L(s[21], 2);
|
||||
s[21] = ROTL64H(s[8], 55);
|
||||
s[8] = ROTL64H(s[16], 45);
|
||||
s[16] = ROTL64H(s[5], 36);
|
||||
s[5] = ROTL64L(s[3], 28);
|
||||
s[3] = ROTL64L(s[18], 21);
|
||||
s[18] = ROTL64L(s[17], 15);
|
||||
s[17] = ROTL64L(s[11], 10);
|
||||
s[11] = ROTL64L(s[7], 6);
|
||||
s[7] = ROTL64L(s[10], 3);
|
||||
s[10] = ROTL64L(u, 1);
|
||||
|
||||
// squeeze this in here
|
||||
/* chi: a[i,j] ^= ~b[i,j+1] & b[i,j+2] */
|
||||
u = s[0]; v = s[1]; s[0] ^= (~v) & s[2];
|
||||
|
||||
/* iota: a[0,0] ^= round constant */
|
||||
s[0] ^= keccak_round_constants[i];
|
||||
if (i == 23 && out_size == 1) return;
|
||||
|
||||
// continue chi
|
||||
s[1] ^= (~s[2]) & s[3]; s[2] ^= (~s[3]) & s[4]; s[3] ^= (~s[4]) & u; s[4] ^= (~u) & v;
|
||||
u = s[5]; v = s[6]; s[5] ^= (~v) & s[7]; s[6] ^= (~s[7]) & s[8]; s[7] ^= (~s[8]) & s[9];
|
||||
|
||||
if (i == 23) return;
|
||||
s[8] ^= (~s[9]) & u; s[9] ^= (~u) & v;
|
||||
u = s[10]; v = s[11]; s[10] ^= (~v) & s[12]; s[11] ^= (~s[12]) & s[13]; s[12] ^= (~s[13]) & s[14]; s[13] ^= (~s[14]) & u; s[14] ^= (~u) & v;
|
||||
u = s[15]; v = s[16]; s[15] ^= (~v) & s[17]; s[16] ^= (~s[17]) & s[18]; s[17] ^= (~s[18]) & s[19]; s[18] ^= (~s[19]) & u; s[19] ^= (~u) & v;
|
||||
u = s[20]; v = s[21]; s[20] ^= (~v) & s[22]; s[21] ^= (~s[22]) & s[23]; s[22] ^= (~s[23]) & s[24]; s[23] ^= (~s[24]) & u; s[24] ^= (~u) & v;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
#include <cuda.h>
|
||||
#include <cuda_runtime.h>
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
// 64-bit ROTATE LEFT
|
||||
|
||||
#if __CUDA_ARCH__ >= 320
|
||||
|
||||
__device__ uint64_t ROTL64H(const uint64_t x, const int offset)
|
||||
{
|
||||
uint64_t res;
|
||||
asm("{\n\t"
|
||||
".reg .u32 tl,th,vl,vh;\n\t"
|
||||
"mov.b64 {tl,th}, %1;\n\t"
|
||||
"shf.l.wrap.b32 vl, tl, th, %2;\n\t"
|
||||
"shf.l.wrap.b32 vh, th, tl, %2;\n\t"
|
||||
"mov.b64 %0, {vl,vh};\n\t"
|
||||
"}"
|
||||
: "=l"(res) : "l"(x), "r"(offset)
|
||||
);
|
||||
return res;
|
||||
}
|
||||
|
||||
__device__ uint64_t ROTL64L(const uint64_t x, const int offset)
|
||||
{
|
||||
uint64_t res;
|
||||
asm("{\n\t"
|
||||
".reg .u32 tl,th,vl,vh;\n\t"
|
||||
"mov.b64 {tl,th}, %1;\n\t"
|
||||
"shf.l.wrap.b32 vl, tl, th, %2;\n\t"
|
||||
"shf.l.wrap.b32 vh, th, tl, %2;\n\t"
|
||||
"mov.b64 %0, {vh,vl};\n\t"
|
||||
"}"
|
||||
: "=l"(res) : "l"(x), "r"(offset)
|
||||
);
|
||||
return res;
|
||||
}
|
||||
#elif __CUDA_ARCH__ >= 120
|
||||
|
||||
#define ROTL64H(x, n) ROTL64(x,n)
|
||||
#define ROTL64L(x, n) ROTL64(x,n)
|
||||
|
||||
__device__ __forceinline__
|
||||
uint64_t ROTL64(const uint64_t x, const int offset)
|
||||
{
|
||||
uint64_t result;
|
||||
asm("{\n\t"
|
||||
".reg .b64 lhs;\n\t"
|
||||
".reg .u32 roff;\n\t"
|
||||
"shl.b64 lhs, %1, %2;\n\t"
|
||||
"sub.u32 roff, 64, %2;\n\t"
|
||||
"shr.b64 %0, %1, roff;\n\t"
|
||||
"add.u64 %0, lhs, %0;\n\t"
|
||||
"}\n"
|
||||
: "=l"(result) : "l"(x), "r"(offset));
|
||||
return result;
|
||||
}
|
||||
#else
|
||||
#define ROTL64H(x, n) ROTL64(x,n)
|
||||
#define ROTL64L(x, n) ROTL64(x,n)
|
||||
/* host */
|
||||
#define ROTL64(x, n) (((x) << (n)) | ((x) >> (64 - (n))))
|
||||
#endif
|
||||
@@ -303,15 +303,13 @@ extern int scanhash_anime(int thr_id, uint32_t *pdata,
|
||||
const uint32_t *ptarget, uint32_t max_nonce,
|
||||
unsigned long *hashes_done);
|
||||
|
||||
extern int scanhash_bitcoin(int thr_id, uint32_t *pdata,
|
||||
uint32_t *ptarget, uint32_t max_nonce, unsigned long *hashes_done);
|
||||
|
||||
extern int scanhash_blake256(int thr_id, uint32_t *pdata,
|
||||
const uint32_t *ptarget, uint32_t max_nonce,
|
||||
unsigned long *hashes_done, int8_t blakerounds);
|
||||
|
||||
extern int scanhash_credits(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
|
||||
const uint32_t *midstate, uint32_t max_nonce, unsigned long *hashes_done);
|
||||
extern int scanhash_c11(int thr_id, uint32_t *pdata,
|
||||
const uint32_t *ptarget, uint32_t max_nonce,
|
||||
unsigned long *hashes_done);
|
||||
|
||||
extern int scanhash_fresh(int thr_id, uint32_t *pdata,
|
||||
const uint32_t *ptarget, uint32_t max_nonce,
|
||||
@@ -332,10 +330,6 @@ extern int scanhash_pentablake(int thr_id, uint32_t *pdata,
|
||||
const uint32_t *ptarget, uint32_t max_nonce,
|
||||
unsigned long *hashes_done);
|
||||
|
||||
extern int scanhash_pluck(int thr_id, uint32_t *pdata,
|
||||
const uint32_t *ptarget, uint32_t max_nonce,
|
||||
unsigned long *hashes_done);
|
||||
|
||||
extern int scanhash_qubit(int thr_id, uint32_t *pdata,
|
||||
const uint32_t *ptarget, uint32_t max_nonce,
|
||||
unsigned long *hashes_done);
|
||||
@@ -380,9 +374,16 @@ extern int scanhash_x17(int thr_id, uint32_t *pdata,
|
||||
const uint32_t *ptarget, uint32_t max_nonce,
|
||||
unsigned long *hashes_done);
|
||||
|
||||
extern int scanhash_whirlpoolx(int thr_id, uint32_t *pdata,
|
||||
const uint32_t *ptarget, uint32_t max_nonce,
|
||||
unsigned long *hashes_done);
|
||||
|
||||
extern int scanhash_zr5(int thr_id, struct work *work, uint32_t max_nonce,
|
||||
unsigned long *hashes_done);
|
||||
|
||||
extern int scanhash_ether(int thr_id, struct work *work, uint64_t max_nonce,
|
||||
unsigned long *hashes_done);
|
||||
|
||||
/* api related */
|
||||
void *api_thread(void *userdata);
|
||||
void api_set_throughput(int thr_id, uint32_t throughput);
|
||||
@@ -403,7 +404,7 @@ struct cgpu_info {
|
||||
int gpu_clock;
|
||||
int gpu_memclock;
|
||||
size_t gpu_mem;
|
||||
uint32_t gpu_usage;
|
||||
uint32_t gpu_power;
|
||||
double gpu_vddc;
|
||||
int16_t gpu_pstate;
|
||||
int16_t gpu_bus;
|
||||
@@ -625,8 +626,7 @@ struct tx {
|
||||
};
|
||||
|
||||
struct work {
|
||||
uint32_t data[48]; /* 168 bytes req */
|
||||
uint32_t midstate[8];
|
||||
uint32_t data[32];
|
||||
uint32_t target[8];
|
||||
uint32_t maxvote;
|
||||
|
||||
@@ -662,6 +662,7 @@ struct pool_infos {
|
||||
#define POOL_GETWORK 1
|
||||
#define POOL_STRATUM 2
|
||||
#define POOL_LONGPOLL 4
|
||||
#define POOL_ETHER 128
|
||||
uint8_t type;
|
||||
#define POOL_ST_DEFINED 1
|
||||
#define POOL_ST_VALID 2
|
||||
@@ -714,6 +715,9 @@ json_t * json_rpc_call_pool(CURL *curl, struct pool_infos*,
|
||||
json_t * json_rpc_longpoll(CURL *curl, char *lp_url, struct pool_infos*,
|
||||
const char *req, int *err);
|
||||
|
||||
bool ether_getwork(CURL *curl, struct pool_infos *pool, struct work *work);
|
||||
bool ether_submitwork(CURL *curl, struct pool_infos *pool, struct work *work);
|
||||
|
||||
bool stratum_socket_full(struct stratum_ctx *sctx, int timeout);
|
||||
bool stratum_send_line(struct stratum_ctx *sctx, char *s);
|
||||
char *stratum_recv_line(struct stratum_ctx *sctx);
|
||||
@@ -774,9 +778,8 @@ void applog_compare_hash(unsigned char *hash, unsigned char *hash2);
|
||||
|
||||
void print_hash_tests(void);
|
||||
void animehash(void *state, const void *input);
|
||||
void bitcoin_hash(uint32_t *output, const uint32_t *data, uint32_t nonce, const uint32_t *midstate);
|
||||
void blake256hash(void *output, const void *input, int8_t rounds);
|
||||
void creditshash(void *state, const void *input);
|
||||
void c11hash(void *output, const void *input);
|
||||
void deephash(void *state, const void *input);
|
||||
void luffa_hash(void *state, const void *input);
|
||||
void fresh_hash(void *state, const void *input);
|
||||
@@ -790,7 +793,6 @@ void myriadhash(void *state, const void *input);
|
||||
void neoscrypt(uchar *output, const uchar *input, uint32_t profile);
|
||||
void nist5hash(void *state, const void *input);
|
||||
void pentablakehash(void *output, const void *input);
|
||||
void pluckhash(uint32_t *hash, const uint32_t *data, uchar *hashbuffer, const int N);
|
||||
void quarkhash(void *state, const void *input);
|
||||
void qubithash(void *state, const void *input);
|
||||
void scrypthash(void* output, const void* input);
|
||||
@@ -798,6 +800,7 @@ void scryptjane_hash(void* output, const void* input);
|
||||
void skeincoinhash(void *output, const void *input);
|
||||
void skein2hash(void *output, const void *input);
|
||||
void s3hash(void *output, const void *input);
|
||||
void whirlxHash(void *state, const void *input);
|
||||
void x11hash(void *output, const void *input);
|
||||
void x13hash(void *output, const void *input);
|
||||
void x14hash(void *output, const void *input);
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -36,8 +37,12 @@ static uint32_t device_bus_ids[MAX_GPUS] = { 0 };
|
||||
|
||||
extern uint32_t device_gpu_clocks[MAX_GPUS];
|
||||
extern uint32_t device_mem_clocks[MAX_GPUS];
|
||||
extern uint32_t device_plimit[MAX_GPUS];
|
||||
extern int8_t device_pstate[MAX_GPUS];
|
||||
|
||||
uint8_t gpu_clocks_changed[MAX_GPUS] = { 0 };
|
||||
uint32_t clock_prev[MAX_GPUS] = { 0 };
|
||||
uint32_t clock_prev_mem[MAX_GPUS] = { 0 };
|
||||
uint32_t limit_prev[MAX_GPUS] = { 0 };
|
||||
|
||||
/*
|
||||
* Wrappers to emulate dlopen() on other systems like Windows
|
||||
@@ -113,14 +118,12 @@ nvml_handle * nvml_create()
|
||||
|
||||
nvmlh->nvml_dll = nvml_dll;
|
||||
|
||||
nvmlh->nvmlInit = (nvmlReturn_t (*)(void))
|
||||
wrap_dlsym(nvmlh->nvml_dll, "nvmlInit_v2");
|
||||
if (!nvmlh->nvmlInit) {
|
||||
nvmlh->nvmlInit = (nvmlReturn_t (*)(void))
|
||||
wrap_dlsym(nvmlh->nvml_dll, "nvmlInit");
|
||||
}
|
||||
nvmlh->nvmlDeviceGetCount = (nvmlReturn_t (*)(int *))
|
||||
wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceGetCount_v2");
|
||||
nvmlh->nvmlInit = (nvmlReturn_t (*)(void)) wrap_dlsym(nvmlh->nvml_dll, "nvmlInit_v2");
|
||||
if (!nvmlh->nvmlInit)
|
||||
nvmlh->nvmlInit = (nvmlReturn_t (*)(void)) wrap_dlsym(nvmlh->nvml_dll, "nvmlInit");
|
||||
nvmlh->nvmlDeviceGetCount = (nvmlReturn_t (*)(int *)) wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceGetCount_v2");
|
||||
if (!nvmlh->nvmlDeviceGetCount)
|
||||
nvmlh->nvmlDeviceGetCount = (nvmlReturn_t (*)(int *)) wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceGetCount");
|
||||
nvmlh->nvmlDeviceGetHandleByIndex = (nvmlReturn_t (*)(int, nvmlDevice_t *))
|
||||
wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceGetHandleByIndex_v2");
|
||||
nvmlh->nvmlDeviceGetAPIRestriction = (nvmlReturn_t (*)(nvmlDevice_t, nvmlRestrictedAPI_t, nvmlEnableState_t *))
|
||||
@@ -139,15 +142,31 @@ nvml_handle * nvml_create()
|
||||
wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceGetSupportedGraphicsClocks");
|
||||
nvmlh->nvmlDeviceGetSupportedMemoryClocks = (nvmlReturn_t (*)(nvmlDevice_t, unsigned int *count, unsigned int *clocksMHz))
|
||||
wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceGetSupportedMemoryClocks");
|
||||
/* NVML_ERROR_NOT_SUPPORTED
|
||||
nvmlh->nvmlDeviceGetAutoBoostedClocksEnabled = (nvmlReturn_t (*)(nvmlDevice_t, nvmlEnableState_t *isEnabled, nvmlEnableState_t *defaultIsEnabled))
|
||||
wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceGetAutoBoostedClocksEnabled");
|
||||
nvmlh->nvmlDeviceSetAutoBoostedClocksEnabled = (nvmlReturn_t (*)(nvmlDevice_t, nvmlEnableState_t enabled))
|
||||
wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceSetAutoBoostedClocksEnabled"); */
|
||||
nvmlh->nvmlDeviceGetClockInfo = (nvmlReturn_t (*)(nvmlDevice_t, nvmlClockType_t, unsigned int *clock))
|
||||
wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceGetClockInfo");
|
||||
nvmlh->nvmlDeviceGetPciInfo = (nvmlReturn_t (*)(nvmlDevice_t, nvmlPciInfo_t *))
|
||||
wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceGetPciInfo");
|
||||
nvmlh->nvmlDeviceGetMaxClockInfo = (nvmlReturn_t (*)(nvmlDevice_t, nvmlClockType_t, unsigned int *clock))
|
||||
wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceGetMaxClockInfo");
|
||||
nvmlh->nvmlDeviceGetPciInfo = (nvmlReturn_t (*)(nvmlDevice_t, nvmlPciInfo_t *)) wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceGetPciInfo_v2");
|
||||
if (!nvmlh->nvmlDeviceGetPciInfo)
|
||||
nvmlh->nvmlDeviceGetPciInfo = (nvmlReturn_t (*)(nvmlDevice_t, nvmlPciInfo_t *)) wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceGetPciInfo");
|
||||
nvmlh->nvmlDeviceGetCurrPcieLinkGeneration = (nvmlReturn_t (*)(nvmlDevice_t, unsigned int *gen))
|
||||
wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceGetCurrPcieLinkGeneration");
|
||||
nvmlh->nvmlDeviceGetCurrPcieLinkWidth = (nvmlReturn_t (*)(nvmlDevice_t, unsigned int *width))
|
||||
wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceGetCurrPcieLinkWidth");
|
||||
nvmlh->nvmlDeviceGetMaxPcieLinkGeneration = (nvmlReturn_t (*)(nvmlDevice_t, unsigned int *gen))
|
||||
wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceGetMaxPcieLinkGeneration");
|
||||
nvmlh->nvmlDeviceGetMaxPcieLinkWidth = (nvmlReturn_t (*)(nvmlDevice_t, unsigned int *width))
|
||||
wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceGetMaxPcieLinkWidth");
|
||||
nvmlh->nvmlDeviceGetPowerUsage = (nvmlReturn_t (*)(nvmlDevice_t, unsigned int *))
|
||||
wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceGetPowerUsage");
|
||||
nvmlh->nvmlDeviceGetPowerManagementDefaultLimit = (nvmlReturn_t (*)(nvmlDevice_t, unsigned int *limit))
|
||||
wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceGetPowerManagementDefaultLimit");
|
||||
nvmlh->nvmlDeviceGetPowerManagementLimit = (nvmlReturn_t (*)(nvmlDevice_t, unsigned int *limit))
|
||||
wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceGetPowerManagementLimit");
|
||||
nvmlh->nvmlDeviceGetPowerManagementLimitConstraints = (nvmlReturn_t (*)(nvmlDevice_t, unsigned int *min, unsigned int *max))
|
||||
wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceGetPowerManagementLimitConstraints");
|
||||
nvmlh->nvmlDeviceSetPowerManagementLimit = (nvmlReturn_t (*)(nvmlDevice_t, unsigned int limit))
|
||||
wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceSetPowerManagementLimit");
|
||||
nvmlh->nvmlDeviceGetName = (nvmlReturn_t (*)(nvmlDevice_t, char *, int))
|
||||
wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceGetName");
|
||||
nvmlh->nvmlDeviceGetTemperature = (nvmlReturn_t (*)(nvmlDevice_t, int, unsigned int *))
|
||||
@@ -168,25 +187,26 @@ nvml_handle * nvml_create()
|
||||
wrap_dlsym(nvmlh->nvml_dll, "nvmlErrorString");
|
||||
nvmlh->nvmlShutdown = (nvmlReturn_t (*)())
|
||||
wrap_dlsym(nvmlh->nvml_dll, "nvmlShutdown");
|
||||
|
||||
/*
|
||||
nvmlDeviceGetBrand(nvmlDevice_t device, nvmlBrandType_t *type)
|
||||
nvmlDeviceGetMaxPcieLinkWidth(nvmlDevice_t device, unsigned int *maxLinkWidth)
|
||||
nvmlDeviceGetMaxPcieLinkGeneration(nvmlDevice_t device, unsigned int *maxLinkGen)
|
||||
nvmlDeviceGetCurrPcieLinkWidth(nvmlDevice_t device, unsigned int *currLinkWidth)
|
||||
nvmlDeviceGetCurrPcieLinkGeneration(nvmlDevice_t device, unsigned int *currLinkGen)
|
||||
*/
|
||||
// v331
|
||||
nvmlh->nvmlDeviceGetEnforcedPowerLimit = (nvmlReturn_t (*)(nvmlDevice_t, unsigned int *limit))
|
||||
wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceGetEnforcedPowerLimit");
|
||||
// v340
|
||||
/* NVML_ERROR_NOT_SUPPORTED
|
||||
nvmlh->nvmlDeviceGetAutoBoostedClocksEnabled = (nvmlReturn_t (*)(nvmlDevice_t, nvmlEnableState_t *isEnabled, nvmlEnableState_t *defaultIsEnabled))
|
||||
wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceGetAutoBoostedClocksEnabled");
|
||||
nvmlh->nvmlDeviceSetAutoBoostedClocksEnabled = (nvmlReturn_t (*)(nvmlDevice_t, nvmlEnableState_t enabled))
|
||||
wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceSetAutoBoostedClocksEnabled"); */
|
||||
// v346
|
||||
nvmlh->nvmlDeviceGetPcieThroughput = (nvmlReturn_t (*)(nvmlDevice_t, nvmlPcieUtilCounter_t, unsigned int *value))
|
||||
wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceGetPcieThroughput");
|
||||
|
||||
if (nvmlh->nvmlInit == NULL ||
|
||||
nvmlh->nvmlShutdown == NULL ||
|
||||
nvmlh->nvmlErrorString == NULL ||
|
||||
nvmlh->nvmlSystemGetDriverVersion == NULL ||
|
||||
nvmlh->nvmlDeviceGetCount == NULL ||
|
||||
nvmlh->nvmlDeviceGetHandleByIndex == NULL ||
|
||||
nvmlh->nvmlDeviceGetPciInfo == NULL ||
|
||||
nvmlh->nvmlDeviceGetName == NULL ||
|
||||
nvmlh->nvmlDeviceGetTemperature == NULL ||
|
||||
nvmlh->nvmlDeviceGetFanSpeed == NULL)
|
||||
nvmlh->nvmlDeviceGetName == NULL)
|
||||
{
|
||||
if (opt_debug)
|
||||
applog(LOG_DEBUG, "Failed to obtain required NVML function pointers");
|
||||
@@ -196,7 +216,8 @@ nvml_handle * nvml_create()
|
||||
}
|
||||
|
||||
nvmlh->nvmlInit();
|
||||
nvmlh->nvmlSystemGetDriverVersion(driver_version, sizeof(driver_version));
|
||||
if (nvmlh->nvmlSystemGetDriverVersion)
|
||||
nvmlh->nvmlSystemGetDriverVersion(driver_version, sizeof(driver_version));
|
||||
nvmlh->nvmlDeviceGetCount(&nvmlh->nvml_gpucount);
|
||||
|
||||
/* Query CUDA device count, in case it doesn't agree with NVML, since */
|
||||
@@ -232,7 +253,7 @@ nvml_handle * nvml_create()
|
||||
nvmlh->nvml_pci_domain_id[i] = pciinfo.domain;
|
||||
nvmlh->nvml_pci_bus_id[i] = pciinfo.bus;
|
||||
nvmlh->nvml_pci_device_id[i] = pciinfo.device;
|
||||
nvmlh->nvml_pci_subsys_id[i] = pciinfo.pci_device_id;
|
||||
nvmlh->nvml_pci_subsys_id[i] = pciinfo.pci_subsystem_id;
|
||||
|
||||
nvmlh->app_clocks[i] = NVML_FEATURE_UNKNOWN;
|
||||
if (nvmlh->nvmlDeviceSetAPIRestriction) {
|
||||
@@ -280,41 +301,45 @@ int nvml_set_clocks(nvml_handle *nvmlh, int dev_id)
|
||||
uint32_t gpu_clk = 0, mem_clk = 0;
|
||||
int n = nvmlh->cuda_nvml_device_id[dev_id];
|
||||
if (n < 0 || n >= nvmlh->nvml_gpucount)
|
||||
return -1;
|
||||
|
||||
// prevent double operations on the same gpu... to enhance
|
||||
if (gpu_clocks_changed[dev_id])
|
||||
return 0;
|
||||
return -ENODEV;
|
||||
|
||||
if (!device_gpu_clocks[dev_id] && !device_mem_clocks[dev_id])
|
||||
return 0; // nothing to do
|
||||
|
||||
if (nvmlh->app_clocks[n] != NVML_FEATURE_ENABLED) {
|
||||
applog(LOG_WARNING, "GPU #%d: NVML application clock feature is not allowed!", dev_id);
|
||||
return -1;
|
||||
return -EPERM;
|
||||
}
|
||||
|
||||
uint32_t mem_prev = clock_prev_mem[dev_id];
|
||||
if (!mem_prev)
|
||||
nvmlh->nvmlDeviceGetApplicationsClock(nvmlh->devs[n], NVML_CLOCK_MEM, &mem_prev);
|
||||
uint32_t gpu_prev = clock_prev[dev_id];
|
||||
if (!gpu_prev)
|
||||
nvmlh->nvmlDeviceGetApplicationsClock(nvmlh->devs[n], NVML_CLOCK_GRAPHICS, &gpu_prev);
|
||||
|
||||
nvmlh->nvmlDeviceGetDefaultApplicationsClock(nvmlh->devs[n], NVML_CLOCK_MEM, &mem_clk);
|
||||
rc = nvmlh->nvmlDeviceGetDefaultApplicationsClock(nvmlh->devs[n], NVML_CLOCK_GRAPHICS, &gpu_clk);
|
||||
if (rc != NVML_SUCCESS) {
|
||||
applog(LOG_WARNING, "GPU #%d: unable to query application clocks", dev_id);
|
||||
return -1;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (opt_debug)
|
||||
applog(LOG_DEBUG, "GPU #%d: default clocks are %u/%u", dev_id, mem_clk, gpu_clk);
|
||||
applog(LOG_DEBUG, "GPU #%d: default application clocks are %u/%u", dev_id, mem_clk, gpu_clk);
|
||||
|
||||
// get application config values
|
||||
if (device_mem_clocks[dev_id]) mem_clk = device_mem_clocks[dev_id];
|
||||
if (device_gpu_clocks[dev_id]) gpu_clk = device_gpu_clocks[dev_id];
|
||||
|
||||
// these functions works for the 960 and the 970 (346.72+), not for the 750 Ti
|
||||
uint32_t nclocks = 0, clocks[128] = { 0 };
|
||||
uint32_t nclocks = 0, clocks[127] = { 0 };
|
||||
nvmlh->nvmlDeviceGetSupportedMemoryClocks(nvmlh->devs[n], &nclocks, NULL);
|
||||
nclocks = min(nclocks, 128);
|
||||
nvmlh->nvmlDeviceGetSupportedMemoryClocks(nvmlh->devs[n], &nclocks, clocks);
|
||||
for (uint8_t u=0; u < nclocks; u++) {
|
||||
// ordered desc, so get first
|
||||
nclocks = min(nclocks, 127);
|
||||
if (nclocks)
|
||||
nvmlh->nvmlDeviceGetSupportedMemoryClocks(nvmlh->devs[n], &nclocks, clocks);
|
||||
for (int8_t u=0; u < nclocks; u++) {
|
||||
// ordered by pstate (so highest is first memory clock - P0)
|
||||
if (clocks[u] <= mem_clk) {
|
||||
mem_clk = clocks[u];
|
||||
break;
|
||||
@@ -323,8 +348,9 @@ int nvml_set_clocks(nvml_handle *nvmlh, int dev_id)
|
||||
|
||||
nclocks = 0;
|
||||
nvmlh->nvmlDeviceGetSupportedGraphicsClocks(nvmlh->devs[n], mem_clk, &nclocks, NULL);
|
||||
nclocks = min(nclocks, 128);
|
||||
nvmlh->nvmlDeviceGetSupportedGraphicsClocks(nvmlh->devs[n], mem_clk, &nclocks, clocks);
|
||||
nclocks = min(nclocks, 127);
|
||||
if (nclocks)
|
||||
nvmlh->nvmlDeviceGetSupportedGraphicsClocks(nvmlh->devs[n], mem_clk, &nclocks, clocks);
|
||||
for (uint8_t u=0; u < nclocks; u++) {
|
||||
// ordered desc, so get first
|
||||
if (clocks[u] <= gpu_clk) {
|
||||
@@ -337,32 +363,162 @@ int nvml_set_clocks(nvml_handle *nvmlh, int dev_id)
|
||||
if (rc == NVML_SUCCESS)
|
||||
applog(LOG_INFO, "GPU #%d: application clocks set to %u/%u", dev_id, mem_clk, gpu_clk);
|
||||
else {
|
||||
applog(LOG_ERR, "GPU #%d: %u/%u - %s", dev_id, mem_clk, gpu_clk, nvmlh->nvmlErrorString(rc));
|
||||
applog(LOG_WARNING, "GPU #%d: %u/%u - %s", dev_id, mem_clk, gpu_clk, nvmlh->nvmlErrorString(rc));
|
||||
return -1;
|
||||
}
|
||||
|
||||
gpu_clocks_changed[dev_id] = 1;
|
||||
// store previous clocks for reset on exit (or during wait...)
|
||||
clock_prev[dev_id] = gpu_prev;
|
||||
clock_prev_mem[dev_id] = mem_prev;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* reset default app clocks to an used device */
|
||||
/* reset default app clocks and limits on exit */
|
||||
int nvml_reset_clocks(nvml_handle *nvmlh, int dev_id)
|
||||
{
|
||||
int ret = 0;
|
||||
nvmlReturn_t rc;
|
||||
uint32_t gpu_clk = 0, mem_clk = 0;
|
||||
int n = nvmlh->cuda_nvml_device_id[dev_id];
|
||||
if (n < 0 || n >= nvmlh->nvml_gpucount)
|
||||
return -ENODEV;
|
||||
|
||||
if (clock_prev[dev_id]) {
|
||||
rc = nvmlh->nvmlDeviceResetApplicationsClocks(nvmlh->devs[n]);
|
||||
if (rc != NVML_SUCCESS) {
|
||||
applog(LOG_WARNING, "GPU #%d: unable to reset application clocks", dev_id);
|
||||
}
|
||||
clock_prev[dev_id] = 0;
|
||||
ret = 1;
|
||||
}
|
||||
|
||||
if (limit_prev[dev_id]) {
|
||||
uint32_t plimit = limit_prev[dev_id];
|
||||
if (nvmlh->nvmlDeviceGetPowerManagementDefaultLimit && !plimit) {
|
||||
rc = nvmlh->nvmlDeviceGetPowerManagementDefaultLimit(nvmlh->devs[n], &plimit);
|
||||
} else if (plimit) {
|
||||
rc = NVML_SUCCESS;
|
||||
}
|
||||
if (rc == NVML_SUCCESS)
|
||||
nvmlh->nvmlDeviceSetPowerManagementLimit(nvmlh->devs[n], plimit);
|
||||
ret = 1;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set power state of a device (9xx)
|
||||
* Code is similar as clocks one, which allow the change of the pstate
|
||||
*/
|
||||
int nvml_set_pstate(nvml_handle *nvmlh, int dev_id)
|
||||
{
|
||||
nvmlReturn_t rc;
|
||||
uint32_t gpu_clk = 0, mem_clk = 0;
|
||||
int n = nvmlh->cuda_nvml_device_id[dev_id];
|
||||
if (n < 0 || n >= nvmlh->nvml_gpucount)
|
||||
return -1;
|
||||
return -ENODEV;
|
||||
|
||||
if (!gpu_clocks_changed[dev_id])
|
||||
return 0; // nothing to do
|
||||
if (device_pstate[dev_id] < 0)
|
||||
return 0;
|
||||
|
||||
rc = nvmlh->nvmlDeviceResetApplicationsClocks(nvmlh->devs[n]);
|
||||
if (nvmlh->app_clocks[n] != NVML_FEATURE_ENABLED) {
|
||||
applog(LOG_WARNING, "GPU #%d: NVML app. clock feature is not allowed!", dev_id);
|
||||
return -EPERM;
|
||||
}
|
||||
|
||||
nvmlh->nvmlDeviceGetDefaultApplicationsClock(nvmlh->devs[n], NVML_CLOCK_MEM, &mem_clk);
|
||||
rc = nvmlh->nvmlDeviceGetDefaultApplicationsClock(nvmlh->devs[n], NVML_CLOCK_GRAPHICS, &gpu_clk);
|
||||
if (rc != NVML_SUCCESS) {
|
||||
applog(LOG_WARNING, "GPU #%d: unable to reset application clocks", dev_id);
|
||||
applog(LOG_WARNING, "GPU #%d: unable to query application clocks", dev_id);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
// get application config values
|
||||
if (device_mem_clocks[dev_id]) mem_clk = device_mem_clocks[dev_id];
|
||||
if (device_gpu_clocks[dev_id]) gpu_clk = device_gpu_clocks[dev_id];
|
||||
|
||||
// these functions works for the 960 and the 970 (346.72+), not for the 750 Ti
|
||||
uint32_t nclocks = 0, clocks[127] = { 0 };
|
||||
int8_t wanted_pstate = device_pstate[dev_id];
|
||||
nvmlh->nvmlDeviceGetSupportedMemoryClocks(nvmlh->devs[n], &nclocks, NULL);
|
||||
nclocks = min(nclocks, 127);
|
||||
if (nclocks)
|
||||
nvmlh->nvmlDeviceGetSupportedMemoryClocks(nvmlh->devs[n], &nclocks, clocks);
|
||||
for (uint8_t u=0; u < nclocks; u++) {
|
||||
// ordered by pstate (so highest P0 first)
|
||||
if (u == wanted_pstate) {
|
||||
mem_clk = clocks[u];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
nclocks = 0;
|
||||
nvmlh->nvmlDeviceGetSupportedGraphicsClocks(nvmlh->devs[n], mem_clk, &nclocks, NULL);
|
||||
nclocks = min(nclocks, 127);
|
||||
if (nclocks)
|
||||
nvmlh->nvmlDeviceGetSupportedGraphicsClocks(nvmlh->devs[n], mem_clk, &nclocks, clocks);
|
||||
for (uint8_t u=0; u < nclocks; u++) {
|
||||
// ordered desc, so get first
|
||||
if (clocks[u] <= gpu_clk) {
|
||||
gpu_clk = clocks[u];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
rc = nvmlh->nvmlDeviceSetApplicationsClocks(nvmlh->devs[n], mem_clk, gpu_clk);
|
||||
if (rc != NVML_SUCCESS) {
|
||||
applog(LOG_WARNING, "GPU #%d: pstate %s", dev_id, nvmlh->nvmlErrorString(rc));
|
||||
return -1;
|
||||
}
|
||||
gpu_clocks_changed[dev_id] = 0;
|
||||
|
||||
if (!opt_quiet)
|
||||
applog(LOG_INFO, "GPU #%d: app clocks set to P%d (%u/%u)", dev_id, (int) wanted_pstate, mem_clk, gpu_clk);
|
||||
|
||||
clock_prev[dev_id] = 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int nvml_set_plimit(nvml_handle *nvmlh, int dev_id)
|
||||
{
|
||||
nvmlReturn_t rc = NVML_ERROR_UNKNOWN;
|
||||
uint32_t gpu_clk = 0, mem_clk = 0;
|
||||
int n = nvmlh->cuda_nvml_device_id[dev_id];
|
||||
if (n < 0 || n >= nvmlh->nvml_gpucount)
|
||||
return -ENODEV;
|
||||
|
||||
if (!device_plimit[dev_id])
|
||||
return 0; // nothing to do
|
||||
|
||||
if (!nvmlh->nvmlDeviceSetPowerManagementLimit)
|
||||
return -ENOSYS;
|
||||
|
||||
uint32_t plimit = device_plimit[dev_id] * 1000;
|
||||
uint32_t pmin = 1000, pmax = 0, prev_limit = 0;
|
||||
if (nvmlh->nvmlDeviceGetPowerManagementLimitConstraints)
|
||||
rc = nvmlh->nvmlDeviceGetPowerManagementLimitConstraints(nvmlh->devs[n], &pmin, &pmax);
|
||||
|
||||
if (rc != NVML_SUCCESS) {
|
||||
if (!nvmlh->nvmlDeviceGetPowerManagementLimit)
|
||||
return -ENOSYS;
|
||||
}
|
||||
nvmlh->nvmlDeviceGetPowerManagementLimit(nvmlh->devs[n], &prev_limit);
|
||||
if (!pmax) pmax = prev_limit;
|
||||
|
||||
plimit = min(plimit, pmax);
|
||||
plimit = max(plimit, pmin);
|
||||
rc = nvmlh->nvmlDeviceSetPowerManagementLimit(nvmlh->devs[n], plimit);
|
||||
if (rc != NVML_SUCCESS) {
|
||||
applog(LOG_WARNING, "GPU #%d: plimit %s", dev_id, nvmlh->nvmlErrorString(rc));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!opt_quiet) {
|
||||
applog(LOG_INFO, "GPU #%d: power limit set to %uW (allowed range is %u-%u)",
|
||||
dev_id, plimit/1000U, pmin/1000U, pmax/1000U);
|
||||
}
|
||||
|
||||
limit_prev[dev_id] = prev_limit;
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -383,7 +539,10 @@ int nvml_get_gpu_name(nvml_handle *nvmlh, int cudaindex, char *namebuf, int bufs
|
||||
{
|
||||
int gpuindex = nvmlh->cuda_nvml_device_id[cudaindex];
|
||||
if (gpuindex < 0 || gpuindex >= nvmlh->nvml_gpucount)
|
||||
return -1;
|
||||
return -ENODEV;
|
||||
|
||||
if (!nvmlh->nvmlDeviceGetName)
|
||||
return -ENOSYS;
|
||||
|
||||
if (nvmlh->nvmlDeviceGetName(nvmlh->devs[gpuindex], namebuf, bufsize) != NVML_SUCCESS)
|
||||
return -1;
|
||||
@@ -397,7 +556,10 @@ int nvml_get_tempC(nvml_handle *nvmlh, int cudaindex, unsigned int *tempC)
|
||||
nvmlReturn_t rc;
|
||||
int gpuindex = nvmlh->cuda_nvml_device_id[cudaindex];
|
||||
if (gpuindex < 0 || gpuindex >= nvmlh->nvml_gpucount)
|
||||
return -1;
|
||||
return -ENODEV;
|
||||
|
||||
if (!nvmlh->nvmlDeviceGetTemperature)
|
||||
return -ENOSYS;
|
||||
|
||||
rc = nvmlh->nvmlDeviceGetTemperature(nvmlh->devs[gpuindex], 0u /* NVML_TEMPERATURE_GPU */, tempC);
|
||||
if (rc != NVML_SUCCESS) {
|
||||
@@ -413,7 +575,10 @@ int nvml_get_fanpcnt(nvml_handle *nvmlh, int cudaindex, unsigned int *fanpcnt)
|
||||
nvmlReturn_t rc;
|
||||
int gpuindex = nvmlh->cuda_nvml_device_id[cudaindex];
|
||||
if (gpuindex < 0 || gpuindex >= nvmlh->nvml_gpucount)
|
||||
return -1;
|
||||
return -ENODEV;
|
||||
|
||||
if (!nvmlh->nvmlDeviceGetFanSpeed)
|
||||
return -ENOSYS;
|
||||
|
||||
rc = nvmlh->nvmlDeviceGetFanSpeed(nvmlh->devs[gpuindex], fanpcnt);
|
||||
if (rc != NVML_SUCCESS) {
|
||||
@@ -428,12 +593,15 @@ int nvml_get_power_usage(nvml_handle *nvmlh, int cudaindex, unsigned int *milliw
|
||||
{
|
||||
int gpuindex = nvmlh->cuda_nvml_device_id[cudaindex];
|
||||
if (gpuindex < 0 || gpuindex >= nvmlh->nvml_gpucount)
|
||||
return -1;
|
||||
return -ENODEV;
|
||||
|
||||
if (!nvmlh->nvmlDeviceGetPowerUsage)
|
||||
return -ENOSYS;
|
||||
|
||||
nvmlReturn_t res = nvmlh->nvmlDeviceGetPowerUsage(nvmlh->devs[gpuindex], milliwatts);
|
||||
if (res != NVML_SUCCESS) {
|
||||
if (opt_debug)
|
||||
applog(LOG_DEBUG, "nvmlDeviceGetPowerUsage: %s", nvmlh->nvmlErrorString(res));
|
||||
//if (opt_debug)
|
||||
// applog(LOG_DEBUG, "nvmlDeviceGetPowerUsage: %s", nvmlh->nvmlErrorString(res));
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -445,7 +613,10 @@ int nvml_get_pstate(nvml_handle *nvmlh, int cudaindex, int *pstate)
|
||||
{
|
||||
int gpuindex = nvmlh->cuda_nvml_device_id[cudaindex];
|
||||
if (gpuindex < 0 || gpuindex >= nvmlh->nvml_gpucount)
|
||||
return -1;
|
||||
return -ENODEV;
|
||||
|
||||
if (!nvmlh->nvmlDeviceGetPerformanceState)
|
||||
return -ENOSYS;
|
||||
|
||||
nvmlReturn_t res = nvmlh->nvmlDeviceGetPerformanceState(nvmlh->devs[gpuindex], pstate);
|
||||
if (res != NVML_SUCCESS) {
|
||||
@@ -461,7 +632,7 @@ int nvml_get_busid(nvml_handle *nvmlh, int cudaindex, int *busid)
|
||||
{
|
||||
int gpuindex = nvmlh->cuda_nvml_device_id[cudaindex];
|
||||
if (gpuindex < 0 || gpuindex >= nvmlh->nvml_gpucount)
|
||||
return -1;
|
||||
return -ENODEV;
|
||||
|
||||
(*busid) = nvmlh->nvml_pci_bus_id[gpuindex];
|
||||
return 0;
|
||||
@@ -474,13 +645,17 @@ int nvml_get_serial(nvml_handle *nvmlh, int cudaindex, char *sn, int maxlen)
|
||||
int gpuindex = nvmlh->cuda_nvml_device_id[cudaindex];
|
||||
nvmlReturn_t res;
|
||||
if (gpuindex < 0 || gpuindex >= nvmlh->nvml_gpucount)
|
||||
return -1;
|
||||
return -ENODEV;
|
||||
|
||||
res = nvmlh->nvmlDeviceGetSerial(nvmlh->devs[gpuindex], sn, maxlen);
|
||||
if (res == NVML_SUCCESS) {
|
||||
return 0;
|
||||
if (nvmlh->nvmlDeviceGetSerial) {
|
||||
res = nvmlh->nvmlDeviceGetSerial(nvmlh->devs[gpuindex], sn, maxlen);
|
||||
if (res == NVML_SUCCESS)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!nvmlh->nvmlDeviceGetUUID)
|
||||
return -ENOSYS;
|
||||
|
||||
// nvmlDeviceGetUUID: GPU-f2bd642c-369f-5a14-e0b4-0d22dfe9a1fc
|
||||
// use a part of uuid to generate an unique serial
|
||||
// todo: check if there is vendor id is inside
|
||||
@@ -501,7 +676,10 @@ int nvml_get_bios(nvml_handle *nvmlh, int cudaindex, char *desc, int maxlen)
|
||||
uint32_t subids = 0;
|
||||
int gpuindex = nvmlh->cuda_nvml_device_id[cudaindex];
|
||||
if (gpuindex < 0 || gpuindex >= nvmlh->nvml_gpucount)
|
||||
return -1;
|
||||
return -ENODEV;
|
||||
|
||||
if (!nvmlh->nvmlDeviceGetVbiosVersion)
|
||||
return -ENOSYS;
|
||||
|
||||
nvmlReturn_t res = nvmlh->nvmlDeviceGetVbiosVersion(nvmlh->devs[gpuindex], desc, maxlen);
|
||||
if (res != NVML_SUCCESS) {
|
||||
@@ -512,16 +690,16 @@ int nvml_get_bios(nvml_handle *nvmlh, int cudaindex, char *desc, int maxlen)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int nvml_get_info(nvml_handle *nvmlh, int cudaindex, uint16_t *vid, uint16_t *pid)
|
||||
int nvml_get_info(nvml_handle *nvmlh, int cudaindex, uint16_t &vid, uint16_t &pid)
|
||||
{
|
||||
uint32_t subids = 0;
|
||||
int gpuindex = nvmlh->cuda_nvml_device_id[cudaindex];
|
||||
if (gpuindex < 0 || gpuindex >= nvmlh->nvml_gpucount)
|
||||
return -1;
|
||||
return -ENODEV;
|
||||
|
||||
subids = nvmlh->nvml_pci_subsys_id[gpuindex];
|
||||
(*pid) = subids >> 16;
|
||||
(*vid) = subids & 0xFFFF;
|
||||
pid = subids >> 16;
|
||||
vid = subids & 0xFFFF;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -561,7 +739,7 @@ int nvapi_temperature(unsigned int devNum, unsigned int *temperature)
|
||||
NvAPI_Status ret;
|
||||
|
||||
if (devNum >= nvapi_dev_cnt)
|
||||
return -1;
|
||||
return -ENODEV;
|
||||
|
||||
NV_GPU_THERMAL_SETTINGS thermal;
|
||||
thermal.version = NV_GPU_THERMAL_SETTINGS_VER;
|
||||
@@ -584,7 +762,7 @@ int nvapi_fanspeed(unsigned int devNum, unsigned int *speed)
|
||||
NvAPI_Status ret;
|
||||
|
||||
if (devNum >= nvapi_dev_cnt)
|
||||
return -1;
|
||||
return -ENODEV;
|
||||
|
||||
NvU32 fanspeed = 0;
|
||||
ret = NvAPI_GPU_GetTachReading(phys[devNum], &fanspeed);
|
||||
@@ -606,7 +784,7 @@ int nvapi_getpstate(unsigned int devNum, unsigned int *power)
|
||||
NvAPI_Status ret;
|
||||
|
||||
if (devNum >= nvapi_dev_cnt)
|
||||
return -1;
|
||||
return -ENODEV;
|
||||
|
||||
NV_GPU_PERF_PSTATE_ID CurrentPstate = NVAPI_GPU_PERF_PSTATE_UNDEFINED; /* 16 */
|
||||
ret = NvAPI_GPU_GetCurrentPstate(phys[devNum], &CurrentPstate);
|
||||
@@ -631,7 +809,7 @@ int nvapi_getusage(unsigned int devNum, unsigned int *pct)
|
||||
NvAPI_Status ret;
|
||||
|
||||
if (devNum >= nvapi_dev_cnt)
|
||||
return -1;
|
||||
return -ENODEV;
|
||||
|
||||
NV_GPU_DYNAMIC_PSTATES_INFO_EX info;
|
||||
info.version = NV_GPU_DYNAMIC_PSTATES_INFO_EX_VER;
|
||||
@@ -651,13 +829,13 @@ int nvapi_getusage(unsigned int devNum, unsigned int *pct)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int nvapi_getinfo(unsigned int devNum, uint16_t *vid, uint16_t *pid)
|
||||
int nvapi_getinfo(unsigned int devNum, uint16_t &vid, uint16_t &pid)
|
||||
{
|
||||
NvAPI_Status ret;
|
||||
NvU32 pDeviceId, pSubSystemId, pRevisionId, pExtDeviceId;
|
||||
|
||||
if (devNum >= nvapi_dev_cnt)
|
||||
return -1;
|
||||
return -ENODEV;
|
||||
|
||||
ret = NvAPI_GPU_GetPCIIdentifiers(phys[devNum], &pDeviceId, &pSubSystemId, &pRevisionId, &pExtDeviceId);
|
||||
if (ret != NVAPI_OK) {
|
||||
@@ -668,8 +846,8 @@ int nvapi_getinfo(unsigned int devNum, uint16_t *vid, uint16_t *pid)
|
||||
return -1;
|
||||
}
|
||||
|
||||
(*pid) = pDeviceId >> 16;
|
||||
(*vid) = pDeviceId & 0xFFFF;
|
||||
pid = pDeviceId >> 16;
|
||||
vid = pDeviceId & 0xFFFF;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -678,7 +856,7 @@ int nvapi_getserial(unsigned int devNum, char *serial, unsigned int maxlen)
|
||||
{
|
||||
// NvAPI_Status ret;
|
||||
if (devNum >= nvapi_dev_cnt)
|
||||
return -1;
|
||||
return -ENODEV;
|
||||
|
||||
sprintf(serial, "");
|
||||
|
||||
@@ -702,7 +880,7 @@ int nvapi_getbios(unsigned int devNum, char *desc, unsigned int maxlen)
|
||||
{
|
||||
NvAPI_Status ret;
|
||||
if (devNum >= nvapi_dev_cnt)
|
||||
return -1;
|
||||
return -ENODEV;
|
||||
|
||||
if (maxlen < 64) // Short String
|
||||
return -1;
|
||||
@@ -779,7 +957,7 @@ int nvapi_init()
|
||||
NvAPI_ShortString str;
|
||||
ret = NvAPI_SYS_GetDriverAndBranchVersion(&udv, str);
|
||||
if (ret == NVAPI_OK) {
|
||||
sprintf(driver_version,"%d.%d", udv/100, udv % 100);
|
||||
sprintf(driver_version,"%d.%02d", udv / 100, udv % 100);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -888,9 +1066,107 @@ unsigned int gpu_power(struct cgpu_info *gpu)
|
||||
return mw;
|
||||
}
|
||||
|
||||
static int translate_vendor_id(uint16_t vid, char *vendorname)
|
||||
{
|
||||
struct VENDORS {
|
||||
const uint16_t vid;
|
||||
const char *name;
|
||||
} vendors[] = {
|
||||
{ 0x1043, "ASUS" },
|
||||
{ 0x107D, "Leadtek" },
|
||||
{ 0x10B0, "Gainward" },
|
||||
// { 0x10DE, "NVIDIA" },
|
||||
{ 0x1458, "Gigabyte" },
|
||||
{ 0x1462, "MSI" },
|
||||
{ 0x154B, "PNY" },
|
||||
{ 0x1682, "XFX" },
|
||||
{ 0x196D, "Club3D" },
|
||||
{ 0x19DA, "Zotac" },
|
||||
{ 0x19F1, "BFG" },
|
||||
{ 0x1ACC, "PoV" },
|
||||
{ 0x1B4C, "KFA2" },
|
||||
{ 0x3842, "EVGA" },
|
||||
{ 0x7377, "Colorful" },
|
||||
{ 0, "" }
|
||||
};
|
||||
|
||||
if (!vendorname)
|
||||
return -EINVAL;
|
||||
|
||||
for(int v=0; v < ARRAY_SIZE(vendors); v++) {
|
||||
if (vid == vendors[v].vid) {
|
||||
strcpy(vendorname, vendors[v].name);
|
||||
return vid;
|
||||
}
|
||||
}
|
||||
if (opt_debug)
|
||||
applog(LOG_DEBUG, "nvml: Unknown vendor %04x\n", vid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef HAVE_PCIDEV
|
||||
extern "C" {
|
||||
#include <pci/pci.h>
|
||||
}
|
||||
static int linux_gpu_vendor(uint8_t pci_bus_id, char* vendorname, uint16_t &pid)
|
||||
{
|
||||
uint16_t subvendor = 0;
|
||||
struct pci_access *pci;
|
||||
struct pci_dev *dev;
|
||||
uint16_t subdevice;
|
||||
|
||||
if (!vendorname)
|
||||
return -EINVAL;
|
||||
|
||||
pci = pci_alloc();
|
||||
if (!pci)
|
||||
return -ENODEV;
|
||||
|
||||
pci_init(pci);
|
||||
pci_scan_bus(pci);
|
||||
|
||||
for(dev = pci->devices; dev; dev = dev->next)
|
||||
{
|
||||
if (dev->bus == pci_bus_id && dev->vendor_id == 0x10DE)
|
||||
{
|
||||
if (!(dev->known_fields & PCI_FILL_CLASS))
|
||||
pci_fill_info(dev, PCI_FILL_CLASS);
|
||||
if (dev->device_class != PCI_CLASS_DISPLAY_VGA)
|
||||
continue;
|
||||
subvendor = pci_read_word(dev, PCI_SUBSYSTEM_VENDOR_ID);
|
||||
subdevice = pci_read_word(dev, PCI_SUBSYSTEM_ID); // model
|
||||
|
||||
translate_vendor_id(subvendor, vendorname);
|
||||
}
|
||||
}
|
||||
pci_cleanup(pci);
|
||||
return (int) subvendor;
|
||||
}
|
||||
#endif
|
||||
|
||||
int gpu_vendor(uint8_t pci_bus_id, char *vendorname)
|
||||
{
|
||||
#ifdef HAVE_PCIDEV
|
||||
uint16_t pid = 0;
|
||||
return linux_gpu_vendor(pci_bus_id, vendorname, pid);
|
||||
#else
|
||||
uint16_t vid = 0, pid = 0;
|
||||
if (hnvml) { // may not be initialized on start...
|
||||
for (int id=0; id < hnvml->nvml_gpucount; id++) {
|
||||
if (hnvml->nvml_pci_bus_id[id] == pci_bus_id) {
|
||||
nvml_get_info(hnvml, id, vid, pid);
|
||||
}
|
||||
}
|
||||
}
|
||||
return translate_vendor_id(vid, vendorname);
|
||||
#endif
|
||||
}
|
||||
|
||||
int gpu_info(struct cgpu_info *gpu)
|
||||
{
|
||||
char vendorname[32] = { 0 };
|
||||
int id = gpu->gpu_id;
|
||||
uint8_t bus_id = 0;
|
||||
|
||||
gpu->nvml_id = -1;
|
||||
gpu->nvapi_id = -1;
|
||||
@@ -900,13 +1176,19 @@ int gpu_info(struct cgpu_info *gpu)
|
||||
|
||||
if (hnvml) {
|
||||
gpu->nvml_id = (int8_t) hnvml->cuda_nvml_device_id[id];
|
||||
nvml_get_info(hnvml, id, &gpu->gpu_vid, &gpu->gpu_pid);
|
||||
#ifdef HAVE_PCIDEV
|
||||
gpu->gpu_vid = linux_gpu_vendor(hnvml->nvml_pci_bus_id[id], vendorname, gpu->gpu_pid);
|
||||
if (!gpu->gpu_vid || !gpu->gpu_pid)
|
||||
nvml_get_info(hnvml, id, gpu->gpu_vid, gpu->gpu_pid);
|
||||
#else
|
||||
nvml_get_info(hnvml, id, gpu->gpu_vid, gpu->gpu_pid);
|
||||
#endif
|
||||
nvml_get_serial(hnvml, id, gpu->gpu_sn, sizeof(gpu->gpu_sn));
|
||||
nvml_get_bios(hnvml, id, gpu->gpu_desc, sizeof(gpu->gpu_desc));
|
||||
}
|
||||
#ifdef WIN32
|
||||
gpu->nvapi_id = (int8_t) nvapi_dev_map[id];
|
||||
nvapi_getinfo(nvapi_dev_map[id], &gpu->gpu_vid, &gpu->gpu_pid);
|
||||
nvapi_getinfo(nvapi_dev_map[id], gpu->gpu_vid, gpu->gpu_pid);
|
||||
nvapi_getserial(nvapi_dev_map[id], gpu->gpu_sn, sizeof(gpu->gpu_sn));
|
||||
nvapi_getbios(nvapi_dev_map[id], gpu->gpu_desc, sizeof(gpu->gpu_desc));
|
||||
#endif
|
||||
|
||||
@@ -66,6 +66,20 @@ enum nvmlClockType_t {
|
||||
NVML_CLOCK_MEM = 2
|
||||
};
|
||||
|
||||
enum nvmlPcieUtilCounter_t {
|
||||
NVML_PCIE_UTIL_TX_BYTES = 0,
|
||||
NVML_PCIE_UTIL_RX_BYTES = 1,
|
||||
NVML_PCIE_UTIL_COUNT
|
||||
};
|
||||
|
||||
enum nvmlValueType_t {
|
||||
NVML_VALUE_TYPE_DOUBLE = 0,
|
||||
NVML_VALUE_TYPE_UNSIGNED_INT = 1,
|
||||
NVML_VALUE_TYPE_UNSIGNED_LONG = 2,
|
||||
NVML_VALUE_TYPE_UNSIGNED_LONG_LONG = 3,
|
||||
NVML_VALUE_TYPE_COUNT
|
||||
};
|
||||
|
||||
#define NVML_DEVICE_SERIAL_BUFFER_SIZE 30
|
||||
#define NVML_DEVICE_UUID_BUFFER_SIZE 80
|
||||
#define NVML_DEVICE_VBIOS_VERSION_BUFFER_SIZE 32
|
||||
@@ -97,10 +111,17 @@ typedef struct {
|
||||
nvmlReturn_t (*nvmlDeviceResetApplicationsClocks)(nvmlDevice_t);
|
||||
nvmlReturn_t (*nvmlDeviceGetSupportedGraphicsClocks)(nvmlDevice_t, uint32_t mem, uint32_t *num, uint32_t *arr);
|
||||
nvmlReturn_t (*nvmlDeviceGetSupportedMemoryClocks)(nvmlDevice_t, unsigned int *count, unsigned int *clocksMHz);
|
||||
nvmlReturn_t (*nvmlDeviceGetAutoBoostedClocksEnabled)(nvmlDevice_t, nvmlEnableState_t *isEnabled, nvmlEnableState_t *defaultIsEnabled);
|
||||
nvmlReturn_t (*nvmlDeviceSetAutoBoostedClocksEnabled)(nvmlDevice_t, nvmlEnableState_t enabled);
|
||||
nvmlReturn_t (*nvmlDeviceGetClockInfo)(nvmlDevice_t, nvmlClockType_t, unsigned int *);
|
||||
nvmlReturn_t (*nvmlDeviceGetMaxClockInfo)(nvmlDevice_t, nvmlClockType_t, unsigned int *);
|
||||
nvmlReturn_t (*nvmlDeviceGetPowerManagementDefaultLimit)(nvmlDevice_t, unsigned int *limit);
|
||||
nvmlReturn_t (*nvmlDeviceGetPowerManagementLimit)(nvmlDevice_t, unsigned int *limit);
|
||||
nvmlReturn_t (*nvmlDeviceGetPowerManagementLimitConstraints)(nvmlDevice_t, unsigned int *min, unsigned int *max);
|
||||
nvmlReturn_t (*nvmlDeviceSetPowerManagementLimit)(nvmlDevice_t device, unsigned int limit);
|
||||
nvmlReturn_t (*nvmlDeviceGetPciInfo)(nvmlDevice_t, nvmlPciInfo_t *);
|
||||
nvmlReturn_t (*nvmlDeviceGetCurrPcieLinkGeneration)(nvmlDevice_t device, unsigned int *gen);
|
||||
nvmlReturn_t (*nvmlDeviceGetCurrPcieLinkWidth)(nvmlDevice_t device, unsigned int *width);
|
||||
nvmlReturn_t (*nvmlDeviceGetMaxPcieLinkGeneration)(nvmlDevice_t device, unsigned int *gen);
|
||||
nvmlReturn_t (*nvmlDeviceGetMaxPcieLinkWidth)(nvmlDevice_t device, unsigned int *width);
|
||||
nvmlReturn_t (*nvmlDeviceGetName)(nvmlDevice_t, char *, int);
|
||||
nvmlReturn_t (*nvmlDeviceGetTemperature)(nvmlDevice_t, int, unsigned int *);
|
||||
nvmlReturn_t (*nvmlDeviceGetFanSpeed)(nvmlDevice_t, unsigned int *);
|
||||
@@ -112,6 +133,15 @@ typedef struct {
|
||||
nvmlReturn_t (*nvmlSystemGetDriverVersion)(char *version, unsigned int len);
|
||||
char* (*nvmlErrorString)(nvmlReturn_t);
|
||||
nvmlReturn_t (*nvmlShutdown)(void);
|
||||
// v331
|
||||
nvmlReturn_t (*nvmlDeviceGetEnforcedPowerLimit)(nvmlDevice_t, unsigned int *limit);
|
||||
// v340
|
||||
//nvmlReturn_t (*nvmlDeviceGetCpuAffinity)(nvmlDevice_t, unsigned int cpuSetSize, unsigned long* cpuSet);
|
||||
//nvmlReturn_t (*nvmlDeviceSetCpuAffinity)(nvmlDevice_t);
|
||||
//nvmlReturn_t (*nvmlDeviceGetAutoBoostedClocksEnabled)(nvmlDevice_t, nvmlEnableState_t *isEnabled, nvmlEnableState_t *defaultIsEnabled);
|
||||
//nvmlReturn_t (*nvmlDeviceSetAutoBoostedClocksEnabled)(nvmlDevice_t, nvmlEnableState_t enabled);
|
||||
// v346
|
||||
nvmlReturn_t (*nvmlDeviceGetPcieThroughput)(nvmlDevice_t, nvmlPcieUtilCounter_t, unsigned int *value);
|
||||
} nvml_handle;
|
||||
|
||||
|
||||
@@ -123,43 +153,8 @@ int nvml_destroy(nvml_handle *nvmlh);
|
||||
*/
|
||||
int nvml_get_gpucount(nvml_handle *nvmlh, int *gpucount);
|
||||
|
||||
/*
|
||||
* Query the number of GPUs seen by CUDA
|
||||
*/
|
||||
int cuda_get_gpucount(nvml_handle *nvmlh, int *gpucount);
|
||||
|
||||
|
||||
/*
|
||||
* query the name of the GPU model from the CUDA device ID
|
||||
*
|
||||
*/
|
||||
int nvml_get_gpu_name(nvml_handle *nvmlh,
|
||||
int gpuindex,
|
||||
char *namebuf,
|
||||
int bufsize);
|
||||
|
||||
/*
|
||||
* Query the current GPU temperature (Celsius), from the CUDA device ID
|
||||
*/
|
||||
int nvml_get_tempC(nvml_handle *nvmlh,
|
||||
int gpuindex, unsigned int *tempC);
|
||||
|
||||
/*
|
||||
* Query the current GPU fan speed (percent) from the CUDA device ID
|
||||
*/
|
||||
int nvml_get_fanpcnt(nvml_handle *nvmlh,
|
||||
int gpuindex, unsigned int *fanpcnt);
|
||||
|
||||
/*
|
||||
* Query the current GPU power usage in millwatts from the CUDA device ID
|
||||
*
|
||||
* This feature is only available on recent GPU generations and may be
|
||||
* limited in some cases only to Tesla series GPUs.
|
||||
* If the query is run on an unsupported GPU, this routine will return -1.
|
||||
*/
|
||||
int nvml_get_power_usage(nvml_handle *nvmlh,
|
||||
int gpuindex,
|
||||
unsigned int *milliwatts);
|
||||
int nvml_set_plimit(nvml_handle *nvmlh, int dev_id);
|
||||
int nvml_set_pstate(nvml_handle *nvmlh, int dev_id);
|
||||
|
||||
int nvml_set_clocks(nvml_handle *nvmlh, int dev_id);
|
||||
int nvml_reset_clocks(nvml_handle *nvmlh, int dev_id);
|
||||
@@ -170,12 +165,13 @@ unsigned int gpu_fanpercent(struct cgpu_info *gpu);
|
||||
unsigned int gpu_fanrpm(struct cgpu_info *gpu);
|
||||
float gpu_temp(struct cgpu_info *gpu);
|
||||
unsigned int gpu_power(struct cgpu_info *gpu);
|
||||
unsigned int gpu_usage(struct cgpu_info *gpu);
|
||||
int gpu_pstate(struct cgpu_info *gpu);
|
||||
int gpu_busid(struct cgpu_info *gpu);
|
||||
|
||||
/* pid/vid, sn and bios rev */
|
||||
int gpu_info(struct cgpu_info *gpu);
|
||||
int gpu_vendor(uint8_t pci_bus_id, char *vendorname);
|
||||
|
||||
|
||||
/* nvapi functions */
|
||||
#ifdef WIN32
|
||||
|
||||
@@ -1,573 +0,0 @@
|
||||
/*
|
||||
* "pluck" kernel implementation.
|
||||
*
|
||||
* ==========================(LICENSE BEGIN)============================
|
||||
*
|
||||
* Copyright (c) 2015 djm34
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* ===========================(LICENSE END)=============================
|
||||
*
|
||||
* @author djm34
|
||||
* @author tpruvot
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <memory.h>
|
||||
|
||||
#include "cuda_vector.h"
|
||||
|
||||
#include "miner.h"
|
||||
|
||||
uint32_t *d_PlNonce[MAX_GPUS];
|
||||
|
||||
__device__ uint8_t * hashbuffer;
|
||||
__constant__ uint32_t pTarget[8];
|
||||
__constant__ uint32_t c_data[20];
|
||||
|
||||
#define HASH_MEMORY_8bit 131072
|
||||
#define HASH_MEMORY_32bit 32768
|
||||
#define HASH_MEMORY 4096
|
||||
|
||||
static __constant__ uint32_t H256[8] = {
|
||||
0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A,
|
||||
0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19
|
||||
};
|
||||
|
||||
static __constant__ uint32_t Ksha[64] = {
|
||||
0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5,
|
||||
0x3956C25B, 0x59F111F1, 0x923F82A4, 0xAB1C5ED5,
|
||||
0xD807AA98, 0x12835B01, 0x243185BE, 0x550C7DC3,
|
||||
0x72BE5D74, 0x80DEB1FE, 0x9BDC06A7, 0xC19BF174,
|
||||
0xE49B69C1, 0xEFBE4786, 0x0FC19DC6, 0x240CA1CC,
|
||||
0x2DE92C6F, 0x4A7484AA, 0x5CB0A9DC, 0x76F988DA,
|
||||
0x983E5152, 0xA831C66D, 0xB00327C8, 0xBF597FC7,
|
||||
0xC6E00BF3, 0xD5A79147, 0x06CA6351, 0x14292967,
|
||||
0x27B70A85, 0x2E1B2138, 0x4D2C6DFC, 0x53380D13,
|
||||
0x650A7354, 0x766A0ABB, 0x81C2C92E, 0x92722C85,
|
||||
0xA2BFE8A1, 0xA81A664B, 0xC24B8B70, 0xC76C51A3,
|
||||
0xD192E819, 0xD6990624, 0xF40E3585, 0x106AA070,
|
||||
0x19A4C116, 0x1E376C08, 0x2748774C, 0x34B0BCB5,
|
||||
0x391C0CB3, 0x4ED8AA4A, 0x5B9CCA4F, 0x682E6FF3,
|
||||
0x748F82EE, 0x78A5636F, 0x84C87814, 0x8CC70208,
|
||||
0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2
|
||||
};
|
||||
|
||||
|
||||
#define SALSA(a,b,c,d) { \
|
||||
t = a+d; b^=rotateL(t, 7); \
|
||||
t = b+a; c^=rotateL(t, 9); \
|
||||
t = c+b; d^=rotateL(t, 13); \
|
||||
t = d+c; a^=rotateL(t, 18); \
|
||||
}
|
||||
|
||||
#define SALSA_CORE(state) { \
|
||||
SALSA(state.s0,state.s4,state.s8,state.sc); \
|
||||
SALSA(state.s5,state.s9,state.sd,state.s1); \
|
||||
SALSA(state.sa,state.se,state.s2,state.s6); \
|
||||
SALSA(state.sf,state.s3,state.s7,state.sb); \
|
||||
SALSA(state.s0,state.s1,state.s2,state.s3); \
|
||||
SALSA(state.s5,state.s6,state.s7,state.s4); \
|
||||
SALSA(state.sa,state.sb,state.s8,state.s9); \
|
||||
SALSA(state.sf,state.sc,state.sd,state.se); \
|
||||
}
|
||||
|
||||
#if __CUDA_ARCH__ >= 320
|
||||
static __device__ __forceinline__ uint16 xor_salsa8(const uint16 &Bx)
|
||||
{
|
||||
uint32_t t;
|
||||
uint16 state = Bx;
|
||||
SALSA_CORE(state);
|
||||
SALSA_CORE(state);
|
||||
SALSA_CORE(state);
|
||||
SALSA_CORE(state);
|
||||
return(state+Bx);
|
||||
}
|
||||
#endif
|
||||
|
||||
// sha256
|
||||
|
||||
static __device__ __forceinline__ uint32_t bsg2_0(const uint32_t x)
|
||||
{
|
||||
uint32_t r1 = ROTR32(x, 2);
|
||||
uint32_t r2 = ROTR32(x, 13);
|
||||
uint32_t r3 = ROTR32(x, 22);
|
||||
return xor3b(r1, r2, r3);
|
||||
}
|
||||
|
||||
static __device__ __forceinline__ uint32_t bsg2_1(const uint32_t x)
|
||||
{
|
||||
uint32_t r1 = ROTR32(x, 6);
|
||||
uint32_t r2 = ROTR32(x, 11);
|
||||
uint32_t r3 = ROTR32(x, 25);
|
||||
return xor3b(r1, r2, r3);
|
||||
}
|
||||
|
||||
static __device__ __forceinline__ uint32_t ssg2_0(const uint32_t x)
|
||||
{
|
||||
uint64_t r1 = ROTR32(x, 7);
|
||||
uint64_t r2 = ROTR32(x, 18);
|
||||
uint64_t r3 = shr_t32(x, 3);
|
||||
return xor3b(r1, r2, r3);
|
||||
}
|
||||
|
||||
static __device__ __forceinline__ uint32_t ssg2_1(const uint32_t x)
|
||||
{
|
||||
uint64_t r1 = ROTR32(x, 17);
|
||||
uint64_t r2 = ROTR32(x, 19);
|
||||
uint64_t r3 = shr_t32(x, 10);
|
||||
return xor3b(r1, r2, r3);
|
||||
}
|
||||
|
||||
static __device__ __forceinline__ void sha2_step1(const uint32_t a, const uint32_t b, const uint32_t c, uint32_t &d, const uint32_t e,
|
||||
const uint32_t f, const uint32_t g, uint32_t &h, const uint32_t in, const uint32_t Kshared)
|
||||
{
|
||||
uint32_t t1, t2;
|
||||
uint32_t vxandx = xandx(e, f, g);
|
||||
uint32_t bsg21 = bsg2_1(e);
|
||||
uint32_t bsg20 = bsg2_0(a);
|
||||
uint32_t andorv = andor32(a, b, c);
|
||||
|
||||
t1 = h + bsg21 + vxandx + Kshared + in;
|
||||
t2 = bsg20 + andorv;
|
||||
d = d + t1;
|
||||
h = t1 + t2;
|
||||
}
|
||||
|
||||
static __device__ __forceinline__ void sha2_step2(const uint32_t a, const uint32_t b, const uint32_t c, uint32_t &d, const uint32_t e,
|
||||
const uint32_t f, const uint32_t g, uint32_t &h, uint32_t* in, const uint32_t pc, const uint32_t Kshared)
|
||||
{
|
||||
uint32_t t1, t2;
|
||||
|
||||
int pcidx1 = (pc - 2) & 0xF;
|
||||
int pcidx2 = (pc - 7) & 0xF;
|
||||
int pcidx3 = (pc - 15) & 0xF;
|
||||
uint32_t inx0 = in[pc];
|
||||
uint32_t inx1 = in[pcidx1];
|
||||
uint32_t inx2 = in[pcidx2];
|
||||
uint32_t inx3 = in[pcidx3];
|
||||
|
||||
uint32_t ssg21 = ssg2_1(inx1);
|
||||
uint32_t ssg20 = ssg2_0(inx3);
|
||||
uint32_t vxandx = xandx(e, f, g);
|
||||
uint32_t bsg21 = bsg2_1(e);
|
||||
uint32_t bsg20 = bsg2_0(a);
|
||||
uint32_t andorv = andor32(a, b, c);
|
||||
|
||||
in[pc] = ssg21 + inx2 + ssg20 + inx0;
|
||||
|
||||
t1 = h + bsg21 + vxandx + Kshared + in[pc];
|
||||
t2 = bsg20 + andorv;
|
||||
d = d + t1;
|
||||
h = t1 + t2;
|
||||
}
|
||||
|
||||
static __device__ __forceinline__
|
||||
void sha2_round_body(uint32_t* in, uint32_t* r)
|
||||
{
|
||||
uint32_t a = r[0];
|
||||
uint32_t b = r[1];
|
||||
uint32_t c = r[2];
|
||||
uint32_t d = r[3];
|
||||
uint32_t e = r[4];
|
||||
uint32_t f = r[5];
|
||||
uint32_t g = r[6];
|
||||
uint32_t h = r[7];
|
||||
|
||||
sha2_step1(a, b, c, d, e, f, g, h, in[0], Ksha[0]);
|
||||
sha2_step1(h, a, b, c, d, e, f, g, in[1], Ksha[1]);
|
||||
sha2_step1(g, h, a, b, c, d, e, f, in[2], Ksha[2]);
|
||||
sha2_step1(f, g, h, a, b, c, d, e, in[3], Ksha[3]);
|
||||
sha2_step1(e, f, g, h, a, b, c, d, in[4], Ksha[4]);
|
||||
sha2_step1(d, e, f, g, h, a, b, c, in[5], Ksha[5]);
|
||||
sha2_step1(c, d, e, f, g, h, a, b, in[6], Ksha[6]);
|
||||
sha2_step1(b, c, d, e, f, g, h, a, in[7], Ksha[7]);
|
||||
sha2_step1(a, b, c, d, e, f, g, h, in[8], Ksha[8]);
|
||||
sha2_step1(h, a, b, c, d, e, f, g, in[9], Ksha[9]);
|
||||
sha2_step1(g, h, a, b, c, d, e, f, in[10], Ksha[10]);
|
||||
sha2_step1(f, g, h, a, b, c, d, e, in[11], Ksha[11]);
|
||||
sha2_step1(e, f, g, h, a, b, c, d, in[12], Ksha[12]);
|
||||
sha2_step1(d, e, f, g, h, a, b, c, in[13], Ksha[13]);
|
||||
sha2_step1(c, d, e, f, g, h, a, b, in[14], Ksha[14]);
|
||||
sha2_step1(b, c, d, e, f, g, h, a, in[15], Ksha[15]);
|
||||
|
||||
#pragma unroll 3
|
||||
for (int i = 0; i<3; i++) {
|
||||
|
||||
sha2_step2(a, b, c, d, e, f, g, h, in, 0, Ksha[16 + 16 * i]);
|
||||
sha2_step2(h, a, b, c, d, e, f, g, in, 1, Ksha[17 + 16 * i]);
|
||||
sha2_step2(g, h, a, b, c, d, e, f, in, 2, Ksha[18 + 16 * i]);
|
||||
sha2_step2(f, g, h, a, b, c, d, e, in, 3, Ksha[19 + 16 * i]);
|
||||
sha2_step2(e, f, g, h, a, b, c, d, in, 4, Ksha[20 + 16 * i]);
|
||||
sha2_step2(d, e, f, g, h, a, b, c, in, 5, Ksha[21 + 16 * i]);
|
||||
sha2_step2(c, d, e, f, g, h, a, b, in, 6, Ksha[22 + 16 * i]);
|
||||
sha2_step2(b, c, d, e, f, g, h, a, in, 7, Ksha[23 + 16 * i]);
|
||||
sha2_step2(a, b, c, d, e, f, g, h, in, 8, Ksha[24 + 16 * i]);
|
||||
sha2_step2(h, a, b, c, d, e, f, g, in, 9, Ksha[25 + 16 * i]);
|
||||
sha2_step2(g, h, a, b, c, d, e, f, in, 10, Ksha[26 + 16 * i]);
|
||||
sha2_step2(f, g, h, a, b, c, d, e, in, 11, Ksha[27 + 16 * i]);
|
||||
sha2_step2(e, f, g, h, a, b, c, d, in, 12, Ksha[28 + 16 * i]);
|
||||
sha2_step2(d, e, f, g, h, a, b, c, in, 13, Ksha[29 + 16 * i]);
|
||||
sha2_step2(c, d, e, f, g, h, a, b, in, 14, Ksha[30 + 16 * i]);
|
||||
sha2_step2(b, c, d, e, f, g, h, a, in, 15, Ksha[31 + 16 * i]);
|
||||
|
||||
}
|
||||
|
||||
r[0] += a;
|
||||
r[1] += b;
|
||||
r[2] += c;
|
||||
r[3] += d;
|
||||
r[4] += e;
|
||||
r[5] += f;
|
||||
r[6] += g;
|
||||
r[7] += h;
|
||||
}
|
||||
|
||||
static __device__ __forceinline__ uint8 sha256_64(uint32_t *data)
|
||||
{
|
||||
uint32_t __align__(64) in[16];
|
||||
uint32_t __align__(32) buf[8];
|
||||
|
||||
((uint16 *)in)[0] = swapvec((uint16*)data);
|
||||
|
||||
((uint8*)buf)[0] = ((uint8*)H256)[0];
|
||||
|
||||
sha2_round_body(in, buf);
|
||||
|
||||
#pragma unroll 14
|
||||
for (int i = 0; i<14; i++) { in[i + 1] = 0; }
|
||||
|
||||
in[0] = 0x80000000;
|
||||
in[15] = 0x200;
|
||||
|
||||
sha2_round_body(in, buf);
|
||||
return swapvec((uint8*)buf);
|
||||
}
|
||||
|
||||
static __device__ __forceinline__ uint8 sha256_80(uint32_t nonce)
|
||||
{
|
||||
uint32_t __align__(64) in[16];
|
||||
uint32_t __align__(32) buf[8];
|
||||
|
||||
((uint16 *)in)[0] = swapvec((uint16*)c_data);
|
||||
((uint8*)buf)[0] = ((uint8*)H256)[0];
|
||||
|
||||
sha2_round_body(in, buf);
|
||||
|
||||
#pragma unroll 3
|
||||
for (int i = 0; i<3; i++) { in[i] = cuda_swab32(c_data[i + 16]); }
|
||||
|
||||
// in[3] = cuda_swab32(nonce);
|
||||
in[3] = nonce;
|
||||
in[4] = 0x80000000;
|
||||
in[15] = 0x280;
|
||||
|
||||
#pragma unroll
|
||||
for (int i = 5; i<15; i++) { in[i] = 0; }
|
||||
|
||||
sha2_round_body(in, buf);
|
||||
return swapvec((uint8*)buf);
|
||||
}
|
||||
|
||||
// Pluck Factor 128
|
||||
#define SHIFT (1024 * 128)
|
||||
|
||||
__global__ __launch_bounds__(256, 1)
|
||||
void pluck_gpu_hash0_v50(uint32_t threads, uint32_t startNonce)
|
||||
{
|
||||
uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x);
|
||||
if (thread < threads)
|
||||
{
|
||||
#if __CUDA_ARCH__ >= 320
|
||||
const uint32_t nonce = startNonce + thread;
|
||||
uint32_t shift = SHIFT * thread;
|
||||
((uint8*)(hashbuffer + shift))[0] = sha256_80(nonce);
|
||||
((uint8*)(hashbuffer + shift))[1] = make_uint8(0, 0, 0, 0, 0, 0, 0, 0);
|
||||
for (int i = 2; i < 5; i++)
|
||||
{
|
||||
uint32_t randmax = i * 32 - 4;
|
||||
uint32_t randseed[16];
|
||||
uint32_t randbuffer[16];
|
||||
uint32_t joint[16];
|
||||
|
||||
((uint8*)randseed)[0] = __ldg8(&(hashbuffer + shift)[32 * i - 64]);
|
||||
((uint8*)randseed)[1] = __ldg8(&(hashbuffer + shift)[32 * i - 32]);
|
||||
|
||||
((uint16*)randbuffer)[0] = xor_salsa8(((uint16*)randseed)[0]);
|
||||
|
||||
((uint8*)joint)[0] = ((uint8*)randseed)[1];
|
||||
|
||||
#pragma unroll
|
||||
for (int j = 0; j < 8; j++) {
|
||||
uint32_t rand = randbuffer[j] % (randmax - 32);
|
||||
joint[j + 8] = __ldgtoint_unaligned(&(hashbuffer + shift)[rand]);
|
||||
}
|
||||
|
||||
uint8 truc = sha256_64(joint);
|
||||
((uint8*)(hashbuffer + shift))[i] = truc;
|
||||
((uint8*)randseed)[0] = ((uint8*)joint)[0];
|
||||
((uint8*)randseed)[1] = truc;
|
||||
|
||||
((uint16*)randbuffer)[0] = xor_salsa8(((uint16*)randseed)[0]);
|
||||
|
||||
for (int j = 0; j < 32; j += 2)
|
||||
{
|
||||
uint32_t rand = randbuffer[j / 2] % randmax;
|
||||
(hashbuffer + shift)[rand] = __ldg(&(hashbuffer + shift)[randmax + j]);
|
||||
(hashbuffer + shift)[rand + 1] = __ldg(&(hashbuffer + shift)[randmax + j + 1]);
|
||||
(hashbuffer + shift)[rand + 2] = __ldg(&(hashbuffer + shift)[randmax + j + 2]);
|
||||
(hashbuffer + shift)[rand + 3] = __ldg(&(hashbuffer + shift)[randmax + j + 3]);
|
||||
}
|
||||
} // main loop
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
__global__ __launch_bounds__(256, 1)
|
||||
void pluck_gpu_hash_v50(uint32_t threads, uint32_t startNonce, uint32_t *nonceVector)
|
||||
{
|
||||
uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x);
|
||||
if (thread < threads)
|
||||
{
|
||||
#if __CUDA_ARCH__ >= 320
|
||||
const uint32_t nonce = startNonce + thread;
|
||||
uint32_t shift = SHIFT * thread;
|
||||
|
||||
for (int i = 5; i < HASH_MEMORY - 1; i++)
|
||||
{
|
||||
uint32_t randmax = i*32-4;
|
||||
uint32_t randseed[16];
|
||||
uint32_t randbuffer[16];
|
||||
uint32_t joint[16];
|
||||
uint8 Buffbuffer[2];
|
||||
|
||||
((uint8*)randseed)[0] = __ldg8(&(hashbuffer + shift)[32*i-64]);
|
||||
((uint8*)randseed)[1] = __ldg8(&(hashbuffer + shift)[32*i-32]);
|
||||
|
||||
|
||||
Buffbuffer[0] = __ldg8(&(hashbuffer + shift)[32*i - 128]);
|
||||
Buffbuffer[1] = __ldg8(&(hashbuffer + shift)[32*i - 96]);
|
||||
|
||||
((uint16*)randseed)[0] ^= ((uint16*)Buffbuffer)[0];
|
||||
((uint16*)randbuffer)[0]= xor_salsa8(((uint16*)randseed)[0]);
|
||||
((uint8*)joint)[0] = __ldg8(&(hashbuffer + shift)[(i-1)<<5]);
|
||||
|
||||
#pragma unroll
|
||||
for (int j = 0; j < 8; j++) {
|
||||
uint32_t rand = randbuffer[j] % (randmax - 32);
|
||||
joint[j+8] = __ldgtoint_unaligned(&(hashbuffer + shift)[rand]);
|
||||
}
|
||||
|
||||
uint8 truc = sha256_64(joint);
|
||||
((uint8*)(hashbuffer + shift))[i] = truc;
|
||||
((uint8*)randseed)[0] = ((uint8*)joint)[0];
|
||||
((uint8*)randseed)[1] = truc;
|
||||
|
||||
((uint16*)randseed)[0] ^= ((uint16*)Buffbuffer)[0];
|
||||
((uint16*)randbuffer)[0] = xor_salsa8(((uint16*)randseed)[0]);
|
||||
|
||||
for (int j = 0; j < 32; j += 2)
|
||||
{
|
||||
uint32_t rand = randbuffer[j / 2] % randmax;
|
||||
|
||||
(hashbuffer+shift)[rand] = __ldg(&(hashbuffer+shift)[randmax+j]);
|
||||
(hashbuffer + shift)[rand + 1] = __ldg(&(hashbuffer + shift)[randmax + j + 1]);
|
||||
(hashbuffer + shift)[rand + 2] = __ldg(&(hashbuffer + shift)[randmax + j + 2]);
|
||||
(hashbuffer + shift)[rand + 3] = __ldg(&(hashbuffer + shift)[randmax + j + 3]);
|
||||
}
|
||||
|
||||
} // main loop
|
||||
|
||||
uint32_t outbuf = __ldgtoint(&(hashbuffer + shift)[28]);
|
||||
|
||||
if (outbuf <= pTarget[7]) {
|
||||
nonceVector[0] = nonce;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
__global__ __launch_bounds__(128, 3)
|
||||
void pluck_gpu_hash0(uint32_t threads, uint32_t startNonce)
|
||||
{
|
||||
uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x);
|
||||
if (thread < threads)
|
||||
{
|
||||
#if __CUDA_ARCH__ >= 320
|
||||
const uint32_t nonce = startNonce + thread;
|
||||
|
||||
uint32_t shift = SHIFT * thread;
|
||||
((uint8*)(hashbuffer + shift))[0] = sha256_80(nonce);
|
||||
((uint8*)(hashbuffer + shift))[1] = make_uint8(0, 0, 0, 0, 0, 0, 0, 0);
|
||||
for (int i = 2; i < 5; i++)
|
||||
{
|
||||
uint32_t randmax = i * 32 - 4;
|
||||
uint32_t randseed[16];
|
||||
uint32_t randbuffer[16];
|
||||
uint32_t joint[16];
|
||||
|
||||
((uint8*)randseed)[0] = __ldg8(&(hashbuffer + shift)[32 * i - 64]);
|
||||
((uint8*)randseed)[1] = __ldg8(&(hashbuffer + shift)[32 * i - 32]);
|
||||
|
||||
((uint16*)randbuffer)[0] = xor_salsa8(((uint16*)randseed)[0]);
|
||||
|
||||
((uint8*)joint)[0] = ((uint8*)randseed)[1];
|
||||
|
||||
#pragma unroll
|
||||
for (int j = 0; j < 8; j++) {
|
||||
uint32_t rand = randbuffer[j] % (randmax - 32);
|
||||
joint[j + 8] = __ldgtoint_unaligned(&(hashbuffer + shift)[rand]);
|
||||
}
|
||||
|
||||
uint8 truc = sha256_64(joint);
|
||||
((uint8*)(hashbuffer + shift))[i] = truc;
|
||||
((uint8*)randseed)[0] = ((uint8*)joint)[0];
|
||||
((uint8*)randseed)[1] = truc;
|
||||
|
||||
((uint16*)randbuffer)[0] = xor_salsa8(((uint16*)randseed)[0]);
|
||||
|
||||
for (int j = 0; j < 32; j += 2)
|
||||
{
|
||||
uint32_t rand = randbuffer[j / 2] % randmax;
|
||||
(hashbuffer + shift)[rand] = __ldg(&(hashbuffer + shift)[randmax + j]);
|
||||
(hashbuffer + shift)[rand + 1] = __ldg(&(hashbuffer + shift)[randmax + j + 1]);
|
||||
(hashbuffer + shift)[rand + 2] = __ldg(&(hashbuffer + shift)[randmax + j + 2]);
|
||||
(hashbuffer + shift)[rand + 3] = __ldg(&(hashbuffer + shift)[randmax + j + 3]);
|
||||
}
|
||||
} // main loop
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
__global__ __launch_bounds__(128, 3)
|
||||
void pluck_gpu_hash(uint32_t threads, uint32_t startNonce, uint32_t *nonceVector)
|
||||
{
|
||||
uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x);
|
||||
if (thread < threads)
|
||||
{
|
||||
#if __CUDA_ARCH__ >= 320
|
||||
const uint32_t nonce = startNonce + thread;
|
||||
|
||||
uint32_t shift = SHIFT * thread;
|
||||
|
||||
for (int i = 5; i < HASH_MEMORY - 1; i++)
|
||||
{
|
||||
uint32_t randmax = i * 32 - 4;
|
||||
uint32_t randseed[16];
|
||||
uint32_t randbuffer[16];
|
||||
uint32_t joint[16];
|
||||
uint8 Buffbuffer[2];
|
||||
|
||||
((uint8*)randseed)[0] = __ldg8(&(hashbuffer + shift)[32 * i - 64]);
|
||||
((uint8*)randseed)[1] = __ldg8(&(hashbuffer + shift)[32 * i - 32]);
|
||||
|
||||
|
||||
Buffbuffer[0] = __ldg8(&(hashbuffer + shift)[32 * i - 128]);
|
||||
Buffbuffer[1] = __ldg8(&(hashbuffer + shift)[32 * i - 96]);
|
||||
((uint16*)randseed)[0] ^= ((uint16*)Buffbuffer)[0];
|
||||
|
||||
((uint16*)randbuffer)[0] = xor_salsa8(((uint16*)randseed)[0]);
|
||||
|
||||
((uint8*)joint)[0] = __ldg8(&(hashbuffer + shift)[(i - 1) << 5]);
|
||||
|
||||
#pragma unroll
|
||||
for (int j = 0; j < 8; j++)
|
||||
{
|
||||
uint32_t rand = randbuffer[j] % (randmax - 32);
|
||||
joint[j + 8] = __ldgtoint_unaligned(&(hashbuffer + shift)[rand]);
|
||||
}
|
||||
|
||||
uint8 truc = sha256_64(joint);
|
||||
((uint8*)(hashbuffer + shift))[i] = truc;
|
||||
((uint8*)randseed)[0] = ((uint8*)joint)[0];
|
||||
((uint8*)randseed)[1] = truc;
|
||||
|
||||
|
||||
((uint16*)randseed)[0] ^= ((uint16*)Buffbuffer)[0];
|
||||
((uint16*)randbuffer)[0] = xor_salsa8(((uint16*)randseed)[0]);
|
||||
for (int j = 0; j < 32; j += 2)
|
||||
{
|
||||
uint32_t rand = randbuffer[j / 2] % randmax;
|
||||
|
||||
(hashbuffer + shift)[rand] = __ldg(&(hashbuffer + shift)[randmax + j]);
|
||||
(hashbuffer + shift)[rand + 1] = __ldg(&(hashbuffer + shift)[randmax + j + 1]);
|
||||
(hashbuffer + shift)[rand + 2] = __ldg(&(hashbuffer + shift)[randmax + j + 2]);
|
||||
(hashbuffer + shift)[rand + 3] = __ldg(&(hashbuffer + shift)[randmax + j + 3]);
|
||||
}
|
||||
} // main loop
|
||||
|
||||
uint32_t outbuf = __ldgtoint(&(hashbuffer + shift)[28]);
|
||||
|
||||
if (outbuf <= pTarget[7]) {
|
||||
nonceVector[0] = nonce;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void pluck_cpu_init(int thr_id, uint32_t threads, uint32_t* hash)
|
||||
{
|
||||
cuda_get_arch(thr_id);
|
||||
cudaMemcpyToSymbol(hashbuffer, &hash, sizeof(hash), 0, cudaMemcpyHostToDevice);
|
||||
cudaMalloc(&d_PlNonce[thr_id], sizeof(uint32_t));
|
||||
}
|
||||
|
||||
__host__
|
||||
uint32_t pluck_cpu_hash(int thr_id, uint32_t threads, uint32_t startNounce, int order)
|
||||
{
|
||||
uint32_t result[8] = { 0xffffffff };
|
||||
cudaMemset(d_PlNonce[thr_id], 0xff, sizeof(uint32_t));
|
||||
|
||||
const uint32_t threadsperblock = 128;
|
||||
|
||||
dim3 grid((threads + threadsperblock - 1) / threadsperblock);
|
||||
dim3 block(threadsperblock);
|
||||
dim3 grid50((threads + 256 - 1) / 256);
|
||||
dim3 block50(256);
|
||||
|
||||
if (device_sm[device_map[thr_id]] <= 300) {
|
||||
applog(LOG_ERR,"Sorry pluck not supported on SM 3.0 devices");
|
||||
return 0;
|
||||
} else if (device_sm[device_map[thr_id]] >= 500) {
|
||||
pluck_gpu_hash0_v50 <<< grid50, block50 >>>(threads, startNounce);
|
||||
pluck_gpu_hash_v50 <<< grid50, block50 >>>(threads, startNounce, d_PlNonce[thr_id]);
|
||||
} else {
|
||||
pluck_gpu_hash0 <<< grid, block >>>(threads, startNounce);
|
||||
pluck_gpu_hash <<< grid, block >>>(threads, startNounce, d_PlNonce[thr_id]);
|
||||
}
|
||||
|
||||
//MyStreamSynchronize(NULL, order, thr_id);
|
||||
CUDA_SAFE_CALL(cudaThreadSynchronize());
|
||||
cudaMemcpy(&result[thr_id], d_PlNonce[thr_id], sizeof(uint32_t), cudaMemcpyDeviceToHost);
|
||||
|
||||
return result[thr_id];
|
||||
}
|
||||
|
||||
__host__
|
||||
void pluck_setBlockTarget(const void *pdata, const void *ptarget)
|
||||
{
|
||||
unsigned char PaddedMessage[80];
|
||||
memcpy(PaddedMessage, pdata, 80);
|
||||
|
||||
cudaMemcpyToSymbol(c_data, PaddedMessage, 80, 0, cudaMemcpyHostToDevice);
|
||||
cudaMemcpyToSymbol(pTarget, ptarget, 32, 0, cudaMemcpyHostToDevice);
|
||||
}
|
||||
-240
@@ -1,240 +0,0 @@
|
||||
/* Based on djm code */
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "miner.h"
|
||||
#include "cuda_helper.h"
|
||||
|
||||
#include <openssl/sha.h>
|
||||
|
||||
static uint32_t *d_hash[MAX_GPUS] ;
|
||||
|
||||
extern void pluck_setBlockTarget(const void* data, const void *ptarget);
|
||||
extern void pluck_cpu_init(int thr_id, uint32_t threads, uint32_t *d_outputHash);
|
||||
extern uint32_t pluck_cpu_hash(int thr_id, uint32_t threads, uint32_t startNounce, int order);
|
||||
|
||||
extern float tp_coef[MAX_GPUS];
|
||||
|
||||
#define ROTL(a, b) (((a) << (b)) | ((a) >> (32 - (b))))
|
||||
//note, this is 64 bytes
|
||||
static inline void xor_salsa8(uint32_t B[16], const uint32_t Bx[16])
|
||||
{
|
||||
#define ROTL(a, b) (((a) << (b)) | ((a) >> (32 - (b))))
|
||||
uint32_t x00, x01, x02, x03, x04, x05, x06, x07, x08, x09, x10, x11, x12, x13, x14, x15;
|
||||
int i;
|
||||
|
||||
x00 = (B[0] ^= Bx[0]);
|
||||
x01 = (B[1] ^= Bx[1]);
|
||||
x02 = (B[2] ^= Bx[2]);
|
||||
x03 = (B[3] ^= Bx[3]);
|
||||
x04 = (B[4] ^= Bx[4]);
|
||||
x05 = (B[5] ^= Bx[5]);
|
||||
x06 = (B[6] ^= Bx[6]);
|
||||
x07 = (B[7] ^= Bx[7]);
|
||||
x08 = (B[8] ^= Bx[8]);
|
||||
x09 = (B[9] ^= Bx[9]);
|
||||
x10 = (B[10] ^= Bx[10]);
|
||||
x11 = (B[11] ^= Bx[11]);
|
||||
x12 = (B[12] ^= Bx[12]);
|
||||
x13 = (B[13] ^= Bx[13]);
|
||||
x14 = (B[14] ^= Bx[14]);
|
||||
x15 = (B[15] ^= Bx[15]);
|
||||
for (i = 0; i < 8; i += 2) {
|
||||
/* Operate on columns. */
|
||||
x04 ^= ROTL(x00 + x12, 7); x09 ^= ROTL(x05 + x01, 7);
|
||||
x14 ^= ROTL(x10 + x06, 7); x03 ^= ROTL(x15 + x11, 7);
|
||||
|
||||
x08 ^= ROTL(x04 + x00, 9); x13 ^= ROTL(x09 + x05, 9);
|
||||
x02 ^= ROTL(x14 + x10, 9); x07 ^= ROTL(x03 + x15, 9);
|
||||
|
||||
x12 ^= ROTL(x08 + x04, 13); x01 ^= ROTL(x13 + x09, 13);
|
||||
x06 ^= ROTL(x02 + x14, 13); x11 ^= ROTL(x07 + x03, 13);
|
||||
|
||||
x00 ^= ROTL(x12 + x08, 18); x05 ^= ROTL(x01 + x13, 18);
|
||||
x10 ^= ROTL(x06 + x02, 18); x15 ^= ROTL(x11 + x07, 18);
|
||||
|
||||
/* Operate on rows. */
|
||||
x01 ^= ROTL(x00 + x03, 7); x06 ^= ROTL(x05 + x04, 7);
|
||||
x11 ^= ROTL(x10 + x09, 7); x12 ^= ROTL(x15 + x14, 7);
|
||||
|
||||
x02 ^= ROTL(x01 + x00, 9); x07 ^= ROTL(x06 + x05, 9);
|
||||
x08 ^= ROTL(x11 + x10, 9); x13 ^= ROTL(x12 + x15, 9);
|
||||
|
||||
x03 ^= ROTL(x02 + x01, 13); x04 ^= ROTL(x07 + x06, 13);
|
||||
x09 ^= ROTL(x08 + x11, 13); x14 ^= ROTL(x13 + x12, 13);
|
||||
|
||||
x00 ^= ROTL(x03 + x02, 18); x05 ^= ROTL(x04 + x07, 18);
|
||||
x10 ^= ROTL(x09 + x08, 18); x15 ^= ROTL(x14 + x13, 18);
|
||||
}
|
||||
B[0] += x00;
|
||||
B[1] += x01;
|
||||
B[2] += x02;
|
||||
B[3] += x03;
|
||||
B[4] += x04;
|
||||
B[5] += x05;
|
||||
B[6] += x06;
|
||||
B[7] += x07;
|
||||
B[8] += x08;
|
||||
B[9] += x09;
|
||||
B[10] += x10;
|
||||
B[11] += x11;
|
||||
B[12] += x12;
|
||||
B[13] += x13;
|
||||
B[14] += x14;
|
||||
B[15] += x15;
|
||||
#undef ROTL
|
||||
}
|
||||
|
||||
static void sha256_hash(uchar *hash, const uchar *data, int len)
|
||||
{
|
||||
SHA256_CTX ctx;
|
||||
SHA256_Init(&ctx);
|
||||
SHA256_Update(&ctx, data, len);
|
||||
SHA256_Final(hash, &ctx);
|
||||
}
|
||||
|
||||
// hash exactly 64 bytes (ie, sha256 block size)
|
||||
static void sha256_hash512(uint32_t *hash, const uint32_t *data)
|
||||
{
|
||||
uint32_t _ALIGN(64) S[16];
|
||||
uint32_t _ALIGN(64) T[16];
|
||||
uchar _ALIGN(64) E[64] = { 0 };
|
||||
int i;
|
||||
|
||||
sha256_init(S);
|
||||
|
||||
for (i = 0; i < 16; i++)
|
||||
T[i] = be32dec(&data[i]);
|
||||
sha256_transform(S, T, 0);
|
||||
|
||||
E[3] = 0x80;
|
||||
E[61] = 0x02; // T[15] = 8 * 64 => 0x200;
|
||||
sha256_transform(S, (uint32_t*)E, 0);
|
||||
|
||||
for (i = 0; i < 8; i++)
|
||||
be32enc(&hash[i], S[i]);
|
||||
}
|
||||
|
||||
#define BLOCK_HEADER_SIZE 80
|
||||
void pluckhash(uint32_t *hash, const uint32_t *data, uchar *hashbuffer, const int N)
|
||||
{
|
||||
int size = N * 1024;
|
||||
sha256_hash(hashbuffer, (uchar*)data, BLOCK_HEADER_SIZE);
|
||||
memset(&hashbuffer[32], 0, 32);
|
||||
|
||||
for (int i = 64; i < size - 32; i += 32)
|
||||
{
|
||||
uint32_t _ALIGN(64) randseed[16];
|
||||
uint32_t _ALIGN(64) randbuffer[16];
|
||||
uint32_t _ALIGN(64) joint[16];
|
||||
//i-4 because we use integers for all references against this, and we don't want to go 3 bytes over the defined area
|
||||
//we could use size here, but then it's probable to use 0 as the value in most cases
|
||||
int randmax = i - 4;
|
||||
|
||||
//setup randbuffer to be an array of random indexes
|
||||
memcpy(randseed, &hashbuffer[i - 64], 64);
|
||||
|
||||
if (i > 128) memcpy(randbuffer, &hashbuffer[i - 128], 64);
|
||||
else memset(randbuffer, 0, 64);
|
||||
|
||||
xor_salsa8((uint32_t*)randbuffer, (uint32_t*)randseed);
|
||||
memcpy(joint, &hashbuffer[i - 32], 32);
|
||||
|
||||
//use the last hash value as the seed
|
||||
for (int j = 32; j < 64; j += 4)
|
||||
{
|
||||
//every other time, change to next random index
|
||||
//randmax - 32 as otherwise we go beyond memory that's already been written to
|
||||
uint32_t rand = randbuffer[(j - 32) >> 2] % (randmax - 32);
|
||||
joint[j >> 2] = *((uint32_t *)&hashbuffer[rand]);
|
||||
}
|
||||
|
||||
sha256_hash512((uint32_t*)&hashbuffer[i], joint);
|
||||
|
||||
//setup randbuffer to be an array of random indexes
|
||||
//use last hash value and previous hash value(post-mixing)
|
||||
memcpy(randseed, &hashbuffer[i - 32], 64);
|
||||
|
||||
if (i > 128) memcpy(randbuffer, &hashbuffer[i - 128], 64);
|
||||
else memset(randbuffer, 0, 64);
|
||||
|
||||
xor_salsa8((uint32_t*)randbuffer, (uint32_t*)randseed);
|
||||
|
||||
//use the last hash value as the seed
|
||||
for (int j = 0; j < 32; j += 2)
|
||||
{
|
||||
uint32_t rand = randbuffer[j >> 1] % randmax;
|
||||
*((uint32_t *)(hashbuffer + rand)) = *((uint32_t *)(hashbuffer + j + randmax));
|
||||
}
|
||||
}
|
||||
|
||||
memcpy(hash, hashbuffer, 32);
|
||||
}
|
||||
|
||||
static bool init[MAX_GPUS] = { 0 };
|
||||
|
||||
static __thread uchar* scratchbuf = NULL;
|
||||
|
||||
extern "C" int scanhash_pluck(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
|
||||
uint32_t max_nonce, unsigned long *hashes_done)
|
||||
{
|
||||
const uint32_t first_nonce = pdata[19];
|
||||
uint32_t endiandata[20];
|
||||
int opt_pluck_n = 128;
|
||||
|
||||
int intensity = is_windows() ? 17 : 19; /* beware > 20 could work and create diff problems later */
|
||||
uint32_t throughput = device_intensity(thr_id, __func__, 1U << intensity);
|
||||
// divide by 128 for this algo which require a lot of memory
|
||||
throughput = throughput / 128 - 256;
|
||||
throughput = min(throughput, max_nonce - first_nonce + 1);
|
||||
|
||||
if (opt_benchmark)
|
||||
((uint32_t*)ptarget)[7] = 0x0000ff;
|
||||
|
||||
if (!init[thr_id])
|
||||
{
|
||||
cudaSetDevice(device_map[thr_id]);
|
||||
//cudaSetDeviceFlags(cudaDeviceScheduleBlockingSync);
|
||||
//cudaDeviceSetCacheConfig(cudaFuncCachePreferL1);
|
||||
cudaMalloc(&d_hash[thr_id], opt_pluck_n * 1024 * throughput);
|
||||
|
||||
if (!scratchbuf)
|
||||
scratchbuf = (uchar*) calloc(opt_pluck_n, 1024);
|
||||
|
||||
pluck_cpu_init(thr_id, throughput, d_hash[thr_id]);
|
||||
|
||||
CUDA_SAFE_CALL(cudaGetLastError());
|
||||
applog(LOG_INFO, "Using %d cuda threads", throughput);
|
||||
|
||||
init[thr_id] = true;
|
||||
}
|
||||
|
||||
for (int k = 0; k < 20; k++)
|
||||
be32enc(&endiandata[k], ((uint32_t*)pdata)[k]);
|
||||
|
||||
pluck_setBlockTarget(endiandata,ptarget);
|
||||
|
||||
do {
|
||||
uint32_t foundNonce = pluck_cpu_hash(thr_id, throughput, pdata[19], 0);
|
||||
if (foundNonce != UINT32_MAX)
|
||||
{
|
||||
const uint32_t Htarg = ptarget[7];
|
||||
uint32_t vhash64[8];
|
||||
be32enc(&endiandata[19], foundNonce);
|
||||
pluckhash(vhash64, endiandata, scratchbuf, opt_pluck_n);
|
||||
if (vhash64[7] <= Htarg && fulltest(vhash64, ptarget)) {
|
||||
*hashes_done = pdata[19] - first_nonce + throughput;
|
||||
pdata[19] = foundNonce;
|
||||
return 1;
|
||||
} else {
|
||||
applog(LOG_WARNING, "GPU #%d: result for %08x does not validate on CPU!", device_map[thr_id], foundNonce);
|
||||
}
|
||||
}
|
||||
|
||||
pdata[19] += throughput;
|
||||
|
||||
} while (pdata[19] < max_nonce && !work_restart[thr_id].restart);
|
||||
|
||||
*hashes_done = pdata[19] - first_nonce;
|
||||
return 0;
|
||||
}
|
||||
@@ -35,6 +35,7 @@ extern time_t firstwork_time;
|
||||
extern volatile time_t g_work_time;
|
||||
extern volatile int pool_switch_count;
|
||||
extern volatile bool pool_is_switching;
|
||||
extern uint8_t conditional_state[MAX_GPUS];
|
||||
|
||||
extern struct option options[];
|
||||
|
||||
@@ -197,6 +198,9 @@ bool pool_switch(int pooln)
|
||||
// used to get the pool uptime
|
||||
firstwork_time = time(NULL);
|
||||
restart_threads();
|
||||
// reset wait states
|
||||
for (int n=0; n<opt_n_threads; n++)
|
||||
conditional_state[n] = false;
|
||||
|
||||
// restore flags
|
||||
allow_gbt = p->allow_gbt;
|
||||
|
||||
+4
-4
@@ -60,8 +60,8 @@ IDI_ICON1 ICON "ccminer.ico"
|
||||
//
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 1,6,4,0
|
||||
PRODUCTVERSION 1,6,4,0
|
||||
FILEVERSION 1,6,5,0
|
||||
PRODUCTVERSION 1,6,5,0
|
||||
FILEFLAGSMASK 0x3fL
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x21L
|
||||
@@ -76,10 +76,10 @@ BEGIN
|
||||
BEGIN
|
||||
BLOCK "040904e4"
|
||||
BEGIN
|
||||
VALUE "FileVersion", "1.6.4"
|
||||
VALUE "FileVersion", "1.6.5"
|
||||
VALUE "LegalCopyright", "Copyright (C) 2015"
|
||||
VALUE "ProductName", "ccminer"
|
||||
VALUE "ProductVersion", "1.6.4"
|
||||
VALUE "ProductVersion", "1.6.5"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
|
||||
@@ -1,206 +0,0 @@
|
||||
/* bitcoin algo (by klaus) */
|
||||
|
||||
#include "miner.h"
|
||||
#include "cuda_helper.h"
|
||||
|
||||
static __thread uint32_t *h_nounce;
|
||||
|
||||
extern cudaStream_t gpustream[MAX_GPUS];
|
||||
|
||||
extern void bitcoin_cpu_init(int thr_id);
|
||||
extern void bitcoin_cpu_hash(int thr_id, uint32_t threads, uint32_t startNounce, const uint32_t *const ms, uint32_t merkle, uint32_t time, uint32_t compacttarget, uint32_t *const h_nounce);
|
||||
extern void bitcoin_midstate(const uint32_t *data, uint32_t *midstate);
|
||||
|
||||
uint32_t rrot(uint32_t x, unsigned int n)
|
||||
{
|
||||
return (x >> n) | (x << (32 - n));
|
||||
}
|
||||
|
||||
// CPU HASH
|
||||
void bitcoin_hash(uint32_t *output, const uint32_t *data, uint32_t nonce, const uint32_t *midstate)
|
||||
{
|
||||
uint32_t w[64];
|
||||
uint32_t s0, s1, t1, t2, maj, ch, a, b, c, d, e, f, g, h;
|
||||
int i;
|
||||
|
||||
const uint32_t k[64] = {
|
||||
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
|
||||
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
|
||||
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
|
||||
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
|
||||
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
|
||||
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
|
||||
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
|
||||
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
|
||||
};
|
||||
const uint32_t hc[8] = {
|
||||
0x6a09e667U, 0xbb67ae85U, 0x3c6ef372U, 0xa54ff53aU,
|
||||
0x510e527fU, 0x9b05688cU, 0x1f83d9abU, 0x5be0cd19U
|
||||
};
|
||||
|
||||
for (i = 0; i <= 15; i++)
|
||||
{
|
||||
w[i] = data[i + 16];
|
||||
}
|
||||
w[3] = nonce;
|
||||
for (i = 16; i <= 63; i++)
|
||||
{
|
||||
s0 = rrot(w[i - 15], 7) ^ rrot(w[i - 15], 18) ^ (w[i - 15] >> 3);
|
||||
s1 = rrot(w[i - 2], 17) ^ rrot(w[i - 2], 19) ^ (w[i - 2] >> 10);
|
||||
w[i] = w[i - 16] + s0 + w[i - 7] + s1;
|
||||
}
|
||||
a = midstate[0];
|
||||
b = midstate[1];
|
||||
c = midstate[2];
|
||||
d = midstate[3];
|
||||
e = midstate[4];
|
||||
f = midstate[5];
|
||||
g = midstate[6];
|
||||
h = midstate[7];
|
||||
for (i = 0; i <= 63; i++)
|
||||
{
|
||||
s0 = rrot(a, 2) ^ rrot(a, 13) ^ rrot(a, 22);
|
||||
maj = (a & b) ^ (a & c) ^ (b & c);
|
||||
t2 = s0 + maj;
|
||||
s1 = rrot(e, 6) ^ rrot(e, 11) ^ rrot(e, 25);
|
||||
ch = (e & f) ^ ((~e) & g);
|
||||
t1 = h + s1 + ch + k[i] + w[i];
|
||||
h = g;
|
||||
g = f;
|
||||
f = e;
|
||||
e = d + t1;
|
||||
d = c;
|
||||
c = b;
|
||||
b = a;
|
||||
a = t1 + t2;
|
||||
}
|
||||
w[0] = a + midstate[0];
|
||||
w[1] = b + midstate[1];
|
||||
w[2] = c + midstate[2];
|
||||
w[3] = d + midstate[3];
|
||||
w[4] = e + midstate[4];
|
||||
w[5] = f + midstate[5];
|
||||
w[6] = g + midstate[6];
|
||||
w[7] = h + midstate[7];
|
||||
w[8] = 0x80000000U;
|
||||
for (i = 9; i <= 14; i++)
|
||||
w[i] = 0U;
|
||||
w[15] = 0x100U;
|
||||
for (i = 16; i <= 63; i++)
|
||||
{
|
||||
s0 = rrot(w[i - 15], 7) ^ rrot(w[i - 15], 18) ^ (w[i - 15] >> 3);
|
||||
s1 = rrot(w[i - 2], 17) ^ rrot(w[i - 2], 19) ^ (w[i - 2] >> 10);
|
||||
w[i] = w[i - 16] + s0 + w[i - 7] + s1;
|
||||
}
|
||||
a = hc[0];
|
||||
b = hc[1];
|
||||
c = hc[2];
|
||||
d = hc[3];
|
||||
e = hc[4];
|
||||
f = hc[5];
|
||||
g = hc[6];
|
||||
h = hc[7];
|
||||
for (i = 0; i <= 63; i++)
|
||||
{
|
||||
s0 = rrot(a, 2) ^ rrot(a, 13) ^ rrot(a, 22);
|
||||
maj = (a & b) ^ (a & c) ^ (b & c);
|
||||
t2 = s0 + maj;
|
||||
s1 = rrot(e, 6) ^ rrot(e, 11) ^ rrot(e, 25);
|
||||
ch = (e & f) ^ ((~e) & g);
|
||||
t1 = h + s1 + ch + k[i] + w[i];
|
||||
h = g;
|
||||
g = f;
|
||||
f = e;
|
||||
e = d + t1;
|
||||
d = c;
|
||||
c = b;
|
||||
b = a;
|
||||
a = t1 + t2;
|
||||
}
|
||||
be32enc(&output[0], a + hc[0]);
|
||||
be32enc(&output[1], b + hc[1]);
|
||||
be32enc(&output[2], c + hc[2]);
|
||||
be32enc(&output[3], d + hc[3]);
|
||||
be32enc(&output[4], e + hc[4]);
|
||||
be32enc(&output[5], f + hc[5]);
|
||||
be32enc(&output[6], g + hc[6]);
|
||||
be32enc(&output[7], h + hc[7]);
|
||||
}
|
||||
|
||||
static bool init[MAX_GPUS] = { 0 };
|
||||
|
||||
int scanhash_bitcoin(int thr_id, uint32_t *pdata, uint32_t *ptarget,
|
||||
uint32_t max_nonce, unsigned long *hashes_done)
|
||||
{
|
||||
const uint32_t first_nonce = pdata[19];
|
||||
uint32_t throughput = device_intensity(thr_id, __func__, 1U << 25);
|
||||
throughput = min(throughput, (max_nonce - first_nonce));
|
||||
|
||||
if (opt_benchmark)
|
||||
ptarget[7] = 0x0005;
|
||||
|
||||
if (!init[thr_id])
|
||||
{
|
||||
CUDA_SAFE_CALL(cudaSetDevice(device_map[thr_id]));
|
||||
//cudaSetDeviceFlags(cudaDeviceScheduleBlockingSync);
|
||||
//cudaDeviceSetCacheConfig(cudaFuncCachePreferL1);
|
||||
|
||||
CUDA_SAFE_CALL(cudaStreamCreate(&gpustream[thr_id]));
|
||||
bitcoin_cpu_init(thr_id);
|
||||
CUDA_SAFE_CALL(cudaMallocHost(&h_nounce, 2 * sizeof(uint32_t)));
|
||||
init[thr_id] = true;
|
||||
}
|
||||
|
||||
uint32_t ms[8];
|
||||
bitcoin_midstate(pdata, ms);
|
||||
|
||||
do
|
||||
{
|
||||
bitcoin_cpu_hash(thr_id, throughput, pdata[19], ms, pdata[16], pdata[17], pdata[18], h_nounce);
|
||||
if (abort_flag) {
|
||||
cudaStreamDestroy(gpustream[thr_id]);
|
||||
pthread_exit(NULL);
|
||||
return -1;
|
||||
}
|
||||
if (h_nounce[0] != UINT32_MAX)
|
||||
{
|
||||
uint32_t _ALIGN(64) vhash64[8];
|
||||
bitcoin_hash(vhash64, pdata, h_nounce[0], ms);
|
||||
if (vhash64[7] == 0 && fulltest(vhash64, ptarget))
|
||||
{
|
||||
int res = 1;
|
||||
// check if there was some other ones...
|
||||
*hashes_done = pdata[19] - first_nonce + throughput;
|
||||
if (h_nounce[1] != UINT32_MAX)
|
||||
{
|
||||
bitcoin_hash(vhash64, pdata, h_nounce[1], ms);
|
||||
if (vhash64[7] == 0 && fulltest(vhash64, ptarget))
|
||||
{
|
||||
pdata[21] = h_nounce[1];
|
||||
res++;
|
||||
if (opt_benchmark)
|
||||
applog(LOG_INFO, "GPU #%d Found second nounce %08x", device_map[thr_id], h_nounce[1]);
|
||||
}
|
||||
else if (vhash64[7] > 0)
|
||||
applog(LOG_WARNING, "GPU #%d: result for %08x does not validate on CPU!", device_map[thr_id], h_nounce[1]);
|
||||
}
|
||||
pdata[19] = h_nounce[0];
|
||||
if (opt_benchmark)
|
||||
applog(LOG_INFO, "GPU #%d Found nounce %08x", device_map[thr_id], h_nounce[0]);
|
||||
|
||||
cudaStreamSynchronize(NULL);
|
||||
return res;
|
||||
}
|
||||
else if (vhash64[7] > 0)
|
||||
applog(LOG_WARNING, "GPU #%d: result for %08x does not validate on CPU!", device_map[thr_id], h_nounce[0]);
|
||||
}
|
||||
|
||||
pdata[19] += throughput; CUDA_SAFE_CALL(cudaGetLastError());
|
||||
|
||||
} while (!work_restart[thr_id].restart && (max_nonce > (uint64_t)(pdata[19]) + throughput));
|
||||
|
||||
cudaStreamSynchronize(NULL);
|
||||
|
||||
*hashes_done = pdata[19] - first_nonce;
|
||||
return 0;
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
/* creditscoin SHA256 djm34 implementation - 2015 */
|
||||
|
||||
extern "C" {
|
||||
#include "sph/sph_types.h"
|
||||
#include "sph/sph_sha2.h"
|
||||
}
|
||||
|
||||
#include "miner.h"
|
||||
#include "cuda_helper.h"
|
||||
|
||||
static uint32_t *d_hash[MAX_GPUS] ;
|
||||
|
||||
extern void bitcredit_setBlockTarget(uint32_t * data,const uint32_t * midstate, const void *ptarget);
|
||||
extern void bitcredit_cpu_init(uint32_t thr_id, int threads, uint32_t* hash);
|
||||
|
||||
extern uint32_t bitcredit_cpu_hash(uint32_t thr_id, int threads, uint32_t startNounce, int order);
|
||||
|
||||
// CPU HASH
|
||||
void creditshash(void *state, const void *input)
|
||||
{
|
||||
uint32_t hash[8], hash2[8];
|
||||
sph_sha256_context sha1,sha2;
|
||||
|
||||
sph_sha256_init(&sha1);
|
||||
sph_sha256(&sha1, input, 168);
|
||||
sph_sha256_close(&sha1, hash);
|
||||
|
||||
sph_sha256_init(&sha2);
|
||||
sph_sha256(&sha2, hash, 32);
|
||||
sph_sha256_close(&sha2, hash2);
|
||||
|
||||
memcpy(state, hash2, 32);
|
||||
}
|
||||
|
||||
static bool init[MAX_GPUS] = { 0 };
|
||||
|
||||
extern "C" int scanhash_credits(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
|
||||
const uint32_t *midstate, uint32_t max_nonce, unsigned long *hashes_done)
|
||||
{
|
||||
uint32_t endiandata[42];
|
||||
const uint32_t first_nonce = pdata[35];
|
||||
|
||||
uint32_t throughput = device_intensity(thr_id, __func__, 1U << 25); // 256*256*64*8
|
||||
throughput = min(throughput, (max_nonce - first_nonce));
|
||||
|
||||
if (opt_benchmark)
|
||||
((uint32_t*)ptarget)[7] = 0x0000ff;
|
||||
|
||||
if (!init[thr_id])
|
||||
{
|
||||
cudaSetDevice(device_map[thr_id]);
|
||||
cudaSetDeviceFlags(cudaDeviceScheduleBlockingSync);
|
||||
cudaDeviceSetCacheConfig(cudaFuncCachePreferL1);
|
||||
|
||||
bitcredit_cpu_init(thr_id, throughput, d_hash[thr_id]);
|
||||
|
||||
CUDA_SAFE_CALL(cudaMalloc(&d_hash[thr_id], throughput * 32));
|
||||
|
||||
init[thr_id] = true;
|
||||
}
|
||||
|
||||
for (int k = 0; k < 42; k++)
|
||||
be32enc(&endiandata[k], ((uint32_t*)pdata)[k]);
|
||||
|
||||
bitcredit_setBlockTarget(pdata,midstate,ptarget);
|
||||
|
||||
// uint64_t nloop = max_nonce/throughput + 1;
|
||||
|
||||
do {
|
||||
int order = 0;
|
||||
uint32_t foundNonce = bitcredit_cpu_hash(thr_id, throughput, pdata[35], order++);
|
||||
if (foundNonce != UINT32_MAX)
|
||||
{
|
||||
pdata[35] = foundNonce;
|
||||
*hashes_done = foundNonce - first_nonce + 1;
|
||||
return 1;
|
||||
}
|
||||
if ((uint64_t)pdata[35] + throughput > UINT32_MAX) {
|
||||
pdata[35]= UINT32_MAX;
|
||||
*hashes_done = pdata[35] - first_nonce + 1; return 0;
|
||||
} else {
|
||||
pdata[35] += throughput;
|
||||
}
|
||||
|
||||
} while (pdata[19] < max_nonce && !work_restart[thr_id].restart);
|
||||
|
||||
*hashes_done = pdata[35] - first_nonce + 1;
|
||||
return 0;
|
||||
}
|
||||
@@ -1,679 +0,0 @@
|
||||
// Original version written by Schleicher (KlausT @github)
|
||||
// Redistribution and use in source and binary forms, with or without modification, are permitted
|
||||
|
||||
//#ifdef __cplusplus
|
||||
//#include <cstdint>
|
||||
//#else
|
||||
#include <stdint.h>
|
||||
//#endif
|
||||
#include "miner.h"
|
||||
#include "cuda_helper.h"
|
||||
|
||||
void bitcoin_cpu_init(int thr_id);
|
||||
void bitcoin_cpu_hash(int thr_id, uint32_t threads, uint32_t startNounce, const uint32_t *const ms, uint32_t merkle, uint32_t time, uint32_t compacttarget, uint32_t *const h_nounce);
|
||||
void bitcoin_midstate(const uint32_t *data, uint32_t *midstate);
|
||||
|
||||
cudaStream_t gpustream[MAX_GPUS] = { 0 };
|
||||
|
||||
__constant__ uint32_t pTarget[8];
|
||||
static uint32_t *d_result[MAX_GPUS];
|
||||
|
||||
#define TPB 512
|
||||
#define NONCES_PER_THREAD 32
|
||||
|
||||
#define rrot(x, n) ((x >> n) | (x << (32 - n)))
|
||||
|
||||
__global__ __launch_bounds__(TPB, 2)
|
||||
void bitcoin_gpu_hash(const uint32_t threads, const uint32_t startNounce, uint32_t *const result, const uint32_t t1c, const uint32_t t2c,
|
||||
const uint32_t w16, const uint32_t w16rot, const uint32_t w17, const uint32_t w17rot, const uint32_t b2, const uint32_t c2, const uint32_t d2, const uint32_t f2, const uint32_t g2, const uint32_t h2,
|
||||
const uint32_t ms0, const uint32_t ms1, const uint32_t ms2, const uint32_t ms3, const uint32_t ms4, const uint32_t ms5, const uint32_t ms6, const uint32_t ms7, const uint32_t compacttarget)
|
||||
{
|
||||
uint32_t threadindex = (blockDim.x * blockIdx.x + threadIdx.x);
|
||||
if (threadindex < threads)
|
||||
{
|
||||
uint32_t t1, a, b, c, d, e, f, g, h;
|
||||
uint32_t w[64];
|
||||
const uint32_t numberofthreads = blockDim.x*gridDim.x;
|
||||
const uint32_t maxnonce = startNounce + threadindex + numberofthreads*NONCES_PER_THREAD - 1;
|
||||
const uint32_t threadindex = blockIdx.x*blockDim.x + threadIdx.x;
|
||||
|
||||
|
||||
#pragma unroll
|
||||
for (uint32_t nonce = startNounce + threadindex; nonce <= maxnonce; nonce += numberofthreads)
|
||||
{
|
||||
w[18] = (rrot(nonce, 7) ^ rrot(nonce, 18) ^ (nonce >> 3)) + w16rot;
|
||||
w[19] = nonce + w17rot;
|
||||
w[20] = 0x80000000U + (rrot(w[18], 17) ^ rrot(w[18], 19) ^ (w[18] >> 10));
|
||||
w[21] = (rrot(w[19], 17) ^ rrot(w[19], 19) ^ (w[19] >> 10));
|
||||
w[22] = 0x280U + (rrot(w[20], 17) ^ rrot(w[20], 19) ^ (w[20] >> 10));
|
||||
w[23] = w16 + (rrot(w[21], 17) ^ rrot(w[21], 19) ^ (w[21] >> 10));
|
||||
w[24] = w17 + (rrot(w[22], 17) ^ rrot(w[22], 19) ^ (w[22] >> 10));
|
||||
w[25] = w[18] + (rrot(w[23], 17) ^ rrot(w[23], 19) ^ (w[23] >> 10));
|
||||
w[26] = w[19] + (rrot(w[24], 17) ^ rrot(w[24], 19) ^ (w[24] >> 10));
|
||||
w[27] = w[20] + (rrot(w[25], 17) ^ rrot(w[25], 19) ^ (w[25] >> 10));
|
||||
w[28] = w[21] + (rrot(w[26], 17) ^ rrot(w[26], 19) ^ (w[26] >> 10));
|
||||
w[29] = w[22] + (rrot(w[27], 17) ^ rrot(w[27], 19) ^ (w[27] >> 10));
|
||||
w[30] = w[23] + 0xa00055U + (rrot(w[28], 17) ^ rrot(w[28], 19) ^ (w[28] >> 10));
|
||||
w[31] = 0x280U + w[24] + (rrot(w16, 7) ^ rrot(w16, 18) ^ (w16 >> 3)) + (rrot(w[29], 17) ^ rrot(w[29], 19) ^ (w[29] >> 10));
|
||||
w[32] = w16 + w[25] + (rrot(w17, 7) ^ rrot(w17, 18) ^ (w17 >> 3)) + (rrot(w[30], 17) ^ rrot(w[30], 19) ^ (w[30] >> 10));
|
||||
w[33] = w17 + w[26] + (rrot(w[18], 7) ^ rrot(w[18], 18) ^ (w[18] >> 3)) + (rrot(w[31], 17) ^ rrot(w[31], 19) ^ (w[31] >> 10));
|
||||
#pragma unroll
|
||||
for (int i = 34; i < 62; i++)
|
||||
w[i] = w[i-16] + w[i-7] + (rrot(w[i-15], 7) ^ rrot(w[i-15], 18) ^ (w[i-15] >> 3)) + (rrot(w[i-2], 17) ^ rrot(w[i-2], 19) ^ (w[i-2] >> 10));
|
||||
|
||||
t1 = t1c + (uint32_t)nonce;
|
||||
a = ms0 + t1;
|
||||
e = t1 + t2c;
|
||||
//
|
||||
t1 = d2 + (rrot(a, 6) ^ rrot(a, 11) ^ rrot(a, 25)) + (c2 ^ (a & (b2 ^ c2))) + 0xb956c25bU;
|
||||
h = h2 + t1;
|
||||
d = t1 + (rrot(e, 2) ^ rrot(e, 13) ^ rrot(e, 22)) + ((g2 & f2) | (e & (g2 | f2)));
|
||||
//
|
||||
t1 = c2 + (rrot(h, 6) ^ rrot(h, 11) ^ rrot(h, 25)) + (b2 ^ (h & (a ^ b2))) + 0x59f111f1U;
|
||||
g = g2 + t1;
|
||||
c = t1 + (rrot(d, 2) ^ rrot(d, 13) ^ rrot(d, 22)) + ((f2 & e) | (d & (f2 | e)));
|
||||
//
|
||||
t1 = b2 + (rrot(g, 6) ^ rrot(g, 11) ^ rrot(g, 25)) + (a ^ (g & (h ^ a))) + 0x923f82a4U;
|
||||
f = f2 + t1;
|
||||
b = t1 + (rrot(c, 2) ^ rrot(c, 13) ^ rrot(c, 22)) + ((e & d) | (c & (e | d)));
|
||||
//
|
||||
t1 = a + (rrot(f, 6) ^ rrot(f, 11) ^ rrot(f, 25)) + (h ^ (f & (g ^ h))) + 0xab1c5ed5U;
|
||||
e += t1;
|
||||
a = t1 + (rrot(b, 2) ^ rrot(b, 13) ^ rrot(b, 22)) + ((d & c) | (b & (d | c)));
|
||||
//
|
||||
t1 = h + (rrot(e, 6) ^ rrot(e, 11) ^ rrot(e, 25)) + (g ^ (e & (f ^ g))) + 0xd807aa98U;
|
||||
d += t1;
|
||||
h = t1 + (rrot(a, 2) ^ rrot(a, 13) ^ rrot(a, 22)) + ((c & b) | (a & (c | b)));
|
||||
//
|
||||
t1 = g + (rrot(d, 6) ^ rrot(d, 11) ^ rrot(d, 25)) + (f ^ (d & (e ^ f))) + 0x12835b01U;
|
||||
c += t1;
|
||||
g = t1 + (rrot(h, 2) ^ rrot(h, 13) ^ rrot(h, 22)) + ((b & a) | (h & (b | a)));
|
||||
//
|
||||
t1 = f + (rrot(c, 6) ^ rrot(c, 11) ^ rrot(c, 25)) + (e ^ (c & (d ^ e))) + 0x243185beU;
|
||||
b += t1;
|
||||
f = t1 + (rrot(g, 2) ^ rrot(g, 13) ^ rrot(g, 22)) + ((a & h) | (g & (a | h)));
|
||||
//
|
||||
t1 = e + (rrot(b, 6) ^ rrot(b, 11) ^ rrot(b, 25)) + (d ^ (b & (c ^ d))) + 0x550c7dc3U;
|
||||
a += t1;
|
||||
e = t1 + (rrot(f, 2) ^ rrot(f, 13) ^ rrot(f, 22)) + ((h & g) | (f & (h | g)));
|
||||
//
|
||||
t1 = d + (rrot(a, 6) ^ rrot(a, 11) ^ rrot(a, 25)) + (c ^ (a & (b ^ c))) + 0x72be5d74U;
|
||||
h += t1;
|
||||
d = t1 + (rrot(e, 2) ^ rrot(e, 13) ^ rrot(e, 22)) + ((g & f) | (e & (g | f)));
|
||||
//
|
||||
t1 = c + (rrot(h, 6) ^ rrot(h, 11) ^ rrot(h, 25)) + (b ^ (h & (a ^ b))) + 0x80deb1feU;
|
||||
g += t1;
|
||||
c = t1 + (rrot(d, 2) ^ rrot(d, 13) ^ rrot(d, 22)) + ((f & e) | (d & (f | e)));
|
||||
//
|
||||
t1 = b + (rrot(g, 6) ^ rrot(g, 11) ^ rrot(g, 25)) + (a ^ (g & (h ^ a))) + 0x9bdc06a7U;
|
||||
f += t1;
|
||||
b = t1 + (rrot(c, 2) ^ rrot(c, 13) ^ rrot(c, 22)) + ((e & d) | (c & (e | d)));
|
||||
//
|
||||
t1 = a + (rrot(f, 6) ^ rrot(f, 11) ^ rrot(f, 25)) + (h ^ (f & (g ^ h))) + 0xc19bf3f4U;
|
||||
e += t1;
|
||||
a = t1 + (rrot(b, 2) ^ rrot(b, 13) ^ rrot(b, 22)) + ((d & c) | (b & (d | c)));
|
||||
//
|
||||
t1 = h + (rrot(e, 6) ^ rrot(e, 11) ^ rrot(e, 25)) + (g ^ (e & (f ^ g))) + 0xe49b69c1U + w16;
|
||||
d += t1;
|
||||
h = t1 + (rrot(a, 2) ^ rrot(a, 13) ^ rrot(a, 22)) + ((c & b) | (a & (c | b)));
|
||||
//
|
||||
t1 = g + (rrot(d, 6) ^ rrot(d, 11) ^ rrot(d, 25)) + (f ^ (d & (e ^ f))) + 0xefbe4786U + w17;
|
||||
c += t1;
|
||||
g = t1 + (rrot(h, 2) ^ rrot(h, 13) ^ rrot(h, 22)) + ((b & a) | (h & (b | a)));
|
||||
//
|
||||
t1 = f + (rrot(c, 6) ^ rrot(c, 11) ^ rrot(c, 25)) + (e ^ (c & (d ^ e))) + 0x0fc19dc6U + w[18];
|
||||
b += t1;
|
||||
f = t1 + (rrot(g, 2) ^ rrot(g, 13) ^ rrot(g, 22)) + ((a & h) | (g & (a | h)));
|
||||
//
|
||||
t1 = e + (rrot(b, 6) ^ rrot(b, 11) ^ rrot(b, 25)) + (d ^ (b & (c ^ d))) + 0x240ca1ccU + w[19];
|
||||
a += t1;
|
||||
e = t1 + (rrot(f, 2) ^ rrot(f, 13) ^ rrot(f, 22)) + ((h & g) | (f & (h | g)));
|
||||
//
|
||||
t1 = d + (rrot(a, 6) ^ rrot(a, 11) ^ rrot(a, 25)) + (c ^ (a & (b ^ c))) + 0x2de92c6fU + w[20];
|
||||
h += t1;
|
||||
d = t1 + (rrot(e, 2) ^ rrot(e, 13) ^ rrot(e, 22)) + ((g & f) | (e & (g | f)));
|
||||
//
|
||||
t1 = c + (rrot(h, 6) ^ rrot(h, 11) ^ rrot(h, 25)) + (b ^ (h & (a ^ b))) + 0x4a7484aaU + w[21];
|
||||
g += t1;
|
||||
c = t1 + (rrot(d, 2) ^ rrot(d, 13) ^ rrot(d, 22)) + ((f & e) | (d & (f | e)));
|
||||
//
|
||||
t1 = b + (rrot(g, 6) ^ rrot(g, 11) ^ rrot(g, 25)) + (a ^ (g & (h ^ a))) + 0x5cb0a9dcU + w[22];
|
||||
f += t1;
|
||||
b = t1 + (rrot(c, 2) ^ rrot(c, 13) ^ rrot(c, 22)) + ((e & d) | (c & (e | d)));
|
||||
//
|
||||
t1 = a + (rrot(f, 6) ^ rrot(f, 11) ^ rrot(f, 25)) + (h ^ (f & (g ^ h))) + 0x76f988daU + w[23];
|
||||
e += t1;
|
||||
a = t1 + (rrot(b, 2) ^ rrot(b, 13) ^ rrot(b, 22)) + ((d & c) | (b & (d | c)));
|
||||
//
|
||||
t1 = h + (rrot(e, 6) ^ rrot(e, 11) ^ rrot(e, 25)) + (g ^ (e & (f ^ g))) + 0x983e5152U + w[24];
|
||||
d += t1;
|
||||
h = t1 + (rrot(a, 2) ^ rrot(a, 13) ^ rrot(a, 22)) + ((c & b) | (a & (c | b)));
|
||||
//
|
||||
t1 = g + (rrot(d, 6) ^ rrot(d, 11) ^ rrot(d, 25)) + (f ^ (d & (e ^ f))) + 0xa831c66dU + w[25];
|
||||
c += t1;
|
||||
g = t1 + (rrot(h, 2) ^ rrot(h, 13) ^ rrot(h, 22)) + ((b & a) | (h & (b | a)));
|
||||
//
|
||||
t1 = f + (rrot(c, 6) ^ rrot(c, 11) ^ rrot(c, 25)) + (e ^ (c & (d ^ e))) + 0xb00327c8U + w[26];
|
||||
b += t1;
|
||||
f = t1 + (rrot(g, 2) ^ rrot(g, 13) ^ rrot(g, 22)) + ((a & h) | (g & (a | h)));
|
||||
//
|
||||
t1 = e + (rrot(b, 6) ^ rrot(b, 11) ^ rrot(b, 25)) + (d ^ (b & (c ^ d))) + 0xbf597fc7U + w[27];
|
||||
a += t1;
|
||||
e = t1 + (rrot(f, 2) ^ rrot(f, 13) ^ rrot(f, 22)) + ((h & g) | (f & (h | g)));
|
||||
//
|
||||
t1 = d + (rrot(a, 6) ^ rrot(a, 11) ^ rrot(a, 25)) + (c ^ (a & (b ^ c))) + 0xc6e00bf3U + w[28];
|
||||
h += t1;
|
||||
d = t1 + (rrot(e, 2) ^ rrot(e, 13) ^ rrot(e, 22)) + ((g & f) | (e & (g | f)));
|
||||
//
|
||||
t1 = c + (rrot(h, 6) ^ rrot(h, 11) ^ rrot(h, 25)) + (b ^ (h & (a ^ b))) + 0xd5a79147U + w[29];
|
||||
g += t1;
|
||||
c = t1 + (rrot(d, 2) ^ rrot(d, 13) ^ rrot(d, 22)) + ((f & e) | (d & (f | e)));
|
||||
//
|
||||
t1 = b + (rrot(g, 6) ^ rrot(g, 11) ^ rrot(g, 25)) + (a ^ (g & (h ^ a))) + 0x06ca6351U + w[30];
|
||||
f += t1;
|
||||
b = t1 + (rrot(c, 2) ^ rrot(c, 13) ^ rrot(c, 22)) + ((e & d) | (c & (e | d)));
|
||||
//
|
||||
t1 = a + (rrot(f, 6) ^ rrot(f, 11) ^ rrot(f, 25)) + (h ^ (f & (g ^ h))) + 0x14292967U + w[31];
|
||||
e += t1;
|
||||
a = t1 + (rrot(b, 2) ^ rrot(b, 13) ^ rrot(b, 22)) + ((d & c) | (b & (d | c)));
|
||||
//
|
||||
t1 = h + (rrot(e, 6) ^ rrot(e, 11) ^ rrot(e, 25)) + (g ^ (e & (f ^ g))) + 0x27b70a85U + w[32];
|
||||
d += t1;
|
||||
h = t1 + (rrot(a, 2) ^ rrot(a, 13) ^ rrot(a, 22)) + ((c & b) | (a & (c | b)));
|
||||
//
|
||||
t1 = g + (rrot(d, 6) ^ rrot(d, 11) ^ rrot(d, 25)) + (f ^ (d & (e ^ f))) + 0x2e1b2138U + w[33];
|
||||
c += t1;
|
||||
g = t1 + (rrot(h, 2) ^ rrot(h, 13) ^ rrot(h, 22)) + ((b & a) | (h & (b | a)));
|
||||
//
|
||||
t1 = f + (rrot(c, 6) ^ rrot(c, 11) ^ rrot(c, 25)) + (e ^ (c & (d ^ e))) + 0x4d2c6dfcU + w[34];
|
||||
b += t1;
|
||||
f = t1 + (rrot(g, 2) ^ rrot(g, 13) ^ rrot(g, 22)) + ((a & h) | (g & (a | h)));
|
||||
//
|
||||
t1 = e + (rrot(b, 6) ^ rrot(b, 11) ^ rrot(b, 25)) + (d ^ (b & (c ^ d))) + 0x53380d13U + w[35];
|
||||
a += t1;
|
||||
e = t1 + (rrot(f, 2) ^ rrot(f, 13) ^ rrot(f, 22)) + ((h & g) | (f & (h | g)));
|
||||
//
|
||||
t1 = d + (rrot(a, 6) ^ rrot(a, 11) ^ rrot(a, 25)) + (c ^ (a & (b ^ c))) + 0x650a7354U + w[36];
|
||||
h += t1;
|
||||
d = t1 + (rrot(e, 2) ^ rrot(e, 13) ^ rrot(e, 22)) + ((g & f) | (e & (g | f)));
|
||||
//
|
||||
t1 = c + (rrot(h, 6) ^ rrot(h, 11) ^ rrot(h, 25)) + (b ^ (h & (a ^ b))) + 0x766a0abbU + w[37];
|
||||
g += t1;
|
||||
c = t1 + (rrot(d, 2) ^ rrot(d, 13) ^ rrot(d, 22)) + ((f & e) | (d & (f | e)));
|
||||
//
|
||||
t1 = b + (rrot(g, 6) ^ rrot(g, 11) ^ rrot(g, 25)) + (a ^ (g & (h ^ a))) + 0x81c2c92eU + w[38];
|
||||
f += t1;
|
||||
b = t1 + (rrot(c, 2) ^ rrot(c, 13) ^ rrot(c, 22)) + ((e & d) | (c & (e | d)));
|
||||
//
|
||||
t1 = a + (rrot(f, 6) ^ rrot(f, 11) ^ rrot(f, 25)) + (h ^ (f & (g ^ h))) + 0x92722c85U + w[39];
|
||||
e += t1;
|
||||
a = t1 + (rrot(b, 2) ^ rrot(b, 13) ^ rrot(b, 22)) + ((d & c) | (b & (d | c)));
|
||||
//
|
||||
t1 = h + (rrot(e, 6) ^ rrot(e, 11) ^ rrot(e, 25)) + (g ^ (e & (f ^ g))) + 0xa2bfe8a1U + w[40];
|
||||
d += t1;
|
||||
h = t1 + (rrot(a, 2) ^ rrot(a, 13) ^ rrot(a, 22)) + ((c & b) | (a & (c | b)));
|
||||
//
|
||||
t1 = g + (rrot(d, 6) ^ rrot(d, 11) ^ rrot(d, 25)) + (f ^ (d & (e ^ f))) + 0xa81a664bU + w[41];
|
||||
c += t1;
|
||||
g = t1 + (rrot(h, 2) ^ rrot(h, 13) ^ rrot(h, 22)) + ((b & a) | (h & (b | a)));
|
||||
//
|
||||
t1 = f + (rrot(c, 6) ^ rrot(c, 11) ^ rrot(c, 25)) + (e ^ (c & (d ^ e))) + 0xc24b8b70U + w[42];
|
||||
b += t1;
|
||||
f = t1 + (rrot(g, 2) ^ rrot(g, 13) ^ rrot(g, 22)) + ((a & h) | (g & (a | h)));
|
||||
//
|
||||
t1 = e + (rrot(b, 6) ^ rrot(b, 11) ^ rrot(b, 25)) + (d ^ (b & (c ^ d))) + 0xc76c51a3U + w[43];
|
||||
a += t1;
|
||||
e = t1 + (rrot(f, 2) ^ rrot(f, 13) ^ rrot(f, 22)) + ((h & g) | (f & (h | g)));
|
||||
//
|
||||
t1 = d + (rrot(a, 6) ^ rrot(a, 11) ^ rrot(a, 25)) + (c ^ (a & (b ^ c))) + 0xd192e819U + w[44];
|
||||
h += t1;
|
||||
d = t1 + (rrot(e, 2) ^ rrot(e, 13) ^ rrot(e, 22)) + ((g & f) | (e & (g | f)));
|
||||
//
|
||||
t1 = c + (rrot(h, 6) ^ rrot(h, 11) ^ rrot(h, 25)) + (b ^ (h & (a ^ b))) + 0xd6990624U + w[45];
|
||||
g += t1;
|
||||
c = t1 + (rrot(d, 2) ^ rrot(d, 13) ^ rrot(d, 22)) + ((f & e) | (d & (f | e)));
|
||||
//
|
||||
t1 = b + (rrot(g, 6) ^ rrot(g, 11) ^ rrot(g, 25)) + (a ^ (g & (h ^ a))) + 0xf40e3585U + w[46];
|
||||
f += t1;
|
||||
b = t1 + (rrot(c, 2) ^ rrot(c, 13) ^ rrot(c, 22)) + ((e & d) | (c & (e | d)));
|
||||
//
|
||||
t1 = a + (rrot(f, 6) ^ rrot(f, 11) ^ rrot(f, 25)) + (h ^ (f & (g ^ h))) + 0x106aa070U + w[47];
|
||||
e += t1;
|
||||
a = t1 + (rrot(b, 2) ^ rrot(b, 13) ^ rrot(b, 22)) + ((d & c) | (b & (d | c)));
|
||||
//
|
||||
t1 = h + (rrot(e, 6) ^ rrot(e, 11) ^ rrot(e, 25)) + (g ^ (e & (f ^ g))) + 0x19a4c116U + w[48];
|
||||
d += t1;
|
||||
h = t1 + (rrot(a, 2) ^ rrot(a, 13) ^ rrot(a, 22)) + ((c & b) | (a & (c | b)));
|
||||
//
|
||||
t1 = g + (rrot(d, 6) ^ rrot(d, 11) ^ rrot(d, 25)) + (f ^ (d & (e ^ f))) + 0x1e376c08U + w[49];
|
||||
c += t1;
|
||||
g = t1 + (rrot(h, 2) ^ rrot(h, 13) ^ rrot(h, 22)) + ((b & a) | (h & (b | a)));
|
||||
//
|
||||
t1 = f + (rrot(c, 6) ^ rrot(c, 11) ^ rrot(c, 25)) + (e ^ (c & (d ^ e))) + 0x2748774cU + w[50];
|
||||
b += t1;
|
||||
f = t1 + (rrot(g, 2) ^ rrot(g, 13) ^ rrot(g, 22)) + ((a & h) | (g & (a | h)));
|
||||
//
|
||||
t1 = e + (rrot(b, 6) ^ rrot(b, 11) ^ rrot(b, 25)) + (d ^ (b & (c ^ d))) + 0x34b0bcb5U + w[51];
|
||||
a += t1;
|
||||
e = t1 + (rrot(f, 2) ^ rrot(f, 13) ^ rrot(f, 22)) + ((h & g) | (f & (h | g)));
|
||||
//
|
||||
t1 = d + (rrot(a, 6) ^ rrot(a, 11) ^ rrot(a, 25)) + (c ^ (a & (b ^ c))) + 0x391c0cb3U + w[52];
|
||||
h += t1;
|
||||
d = t1 + (rrot(e, 2) ^ rrot(e, 13) ^ rrot(e, 22)) + ((g & f) | (e & (g | f)));
|
||||
//
|
||||
t1 = c + (rrot(h, 6) ^ rrot(h, 11) ^ rrot(h, 25)) + (b ^ (h & (a ^ b))) + 0x4ed8aa4aU + w[53];
|
||||
g += t1;
|
||||
c = t1 + (rrot(d, 2) ^ rrot(d, 13) ^ rrot(d, 22)) + ((f & e) | (d & (f | e)));
|
||||
//
|
||||
t1 = b + (rrot(g, 6) ^ rrot(g, 11) ^ rrot(g, 25)) + (a ^ (g & (h ^ a))) + 0x5b9cca4fU + w[54];
|
||||
f += t1;
|
||||
b = t1 + (rrot(c, 2) ^ rrot(c, 13) ^ rrot(c, 22)) + ((e & d) | (c & (e | d)));
|
||||
//
|
||||
t1 = a + (rrot(f, 6) ^ rrot(f, 11) ^ rrot(f, 25)) + (h ^ (f & (g ^ h))) + 0x682e6ff3U + w[55];
|
||||
e += t1;
|
||||
a = t1 + (rrot(b, 2) ^ rrot(b, 13) ^ rrot(b, 22)) + ((d & c) | (b & (d | c)));
|
||||
//
|
||||
t1 = h + (rrot(e, 6) ^ rrot(e, 11) ^ rrot(e, 25)) + (g ^ (e & (f ^ g))) + 0x748f82eeU + w[56];
|
||||
d += t1;
|
||||
h = t1 + (rrot(a, 2) ^ rrot(a, 13) ^ rrot(a, 22)) + ((c & b) | (a & (c | b)));
|
||||
//
|
||||
t1 = g + (rrot(d, 6) ^ rrot(d, 11) ^ rrot(d, 25)) + (f ^ (d & (e ^ f))) + 0x78a5636fU + w[57];
|
||||
c += t1;
|
||||
g = t1 + (rrot(h, 2) ^ rrot(h, 13) ^ rrot(h, 22)) + ((b & a) | (h & (b | a)));
|
||||
//
|
||||
t1 = f + (rrot(c, 6) ^ rrot(c, 11) ^ rrot(c, 25)) + (e ^ (c & (d ^ e))) + 0x84c87814U + w[58];
|
||||
b += t1;
|
||||
f = t1 + (rrot(g, 2) ^ rrot(g, 13) ^ rrot(g, 22)) + ((a & h) | (g & (a | h)));
|
||||
//
|
||||
t1 = e + (rrot(b, 6) ^ rrot(b, 11) ^ rrot(b, 25)) + (d ^ (b & (c ^ d))) + 0x8cc70208U + w[59];
|
||||
a += t1;
|
||||
e = t1 + (rrot(f, 2) ^ rrot(f, 13) ^ rrot(f, 22)) + ((h & g) | (f & (h | g)));
|
||||
//
|
||||
t1 = d + (rrot(a, 6) ^ rrot(a, 11) ^ rrot(a, 25)) + (c ^ (a & (b ^ c))) + 0x90befffaU + w[60];
|
||||
h += t1;
|
||||
d = t1 + (rrot(e, 2) ^ rrot(e, 13) ^ rrot(e, 22)) + ((g & f) | (e & (g | f)));
|
||||
//
|
||||
t1 = c + (rrot(h, 6) ^ rrot(h, 11) ^ rrot(h, 25)) + (b ^ (h & (a ^ b))) + 0xa4506cebU + w[61];
|
||||
g += t1;
|
||||
c = t1 + (rrot(d, 2) ^ rrot(d, 13) ^ rrot(d, 22)) + ((f & e) | (d & (f | e)));
|
||||
//
|
||||
t1 = b + (rrot(g, 6) ^ rrot(g, 11) ^ rrot(g, 25)) + (a ^ (g & (h ^ a))) + 0xbef9a3f7U + w[46] + w[55] + (rrot(w[47], 7) ^ rrot(w[47], 18) ^ (w[47] >> 3)) + (rrot(w[60], 17) ^ rrot(w[60], 19) ^ (w[60] >> 10));
|
||||
f += t1;
|
||||
b = t1 + (rrot(c, 2) ^ rrot(c, 13) ^ rrot(c, 22)) + ((e & d) | (c & (e | d)));
|
||||
//
|
||||
t1 = a + (rrot(f, 6) ^ rrot(f, 11) ^ rrot(f, 25)) + (h ^ (f & (g ^ h))) + 0xc67178f2U + w[47] + w[56] + (rrot(w[48], 7) ^ rrot(w[48], 18) ^ (w[48] >> 3)) + (rrot(w[61], 17) ^ rrot(w[61], 19) ^ (w[61] >> 10));
|
||||
e += t1;
|
||||
a = t1 + (rrot(b, 2) ^ rrot(b, 13) ^ rrot(b, 22)) + ((d & c) | (b & (d | c)));
|
||||
//
|
||||
w[0] = a + ms0; w[1] = b + ms1; w[2] = c + ms2; w[3] = d + ms3;
|
||||
w[4] = e + ms4; w[5] = f + ms5; w[6] = g + ms6; w[7] = h + ms7;
|
||||
// hash the hash ***************************************************************
|
||||
w[16] = w[0] + (rrot(w[1], 7) ^ rrot(w[1], 18) ^ (w[1] >> 3));
|
||||
w[17] = w[1] + (rrot(w[2], 7) ^ rrot(w[2], 18) ^ (w[2] >> 3)) + (rrot(0x100, 17) ^ rrot(0x100, 19) ^ (0x100 >> 10));
|
||||
w[18] = w[2] + (rrot(w[3], 7) ^ rrot(w[3], 18) ^ (w[3] >> 3)) + (rrot(w[16], 17) ^ rrot(w[16], 19) ^ (w[16] >> 10));
|
||||
w[19] = w[3] + (rrot(w[4], 7) ^ rrot(w[4], 18) ^ (w[4] >> 3)) + (rrot(w[17], 17) ^ rrot(w[17], 19) ^ (w[17] >> 10));
|
||||
w[20] = w[4] + (rrot(w[5], 7) ^ rrot(w[5], 18) ^ (w[5] >> 3)) + (rrot(w[18], 17) ^ rrot(w[18], 19) ^ (w[18] >> 10));
|
||||
w[21] = w[5] + (rrot(w[6], 7) ^ rrot(w[6], 18) ^ (w[6] >> 3)) + (rrot(w[19], 17) ^ rrot(w[19], 19) ^ (w[19] >> 10));
|
||||
w[22] = w[6] + 0x100 + (rrot(w[7], 7) ^ rrot(w[7], 18) ^ (w[7] >> 3)) + (rrot(w[20], 17) ^ rrot(w[20], 19) ^ (w[20] >> 10));
|
||||
w[23] = w[7] + w[16] + 0x11002000U + (rrot(w[21], 17) ^ rrot(w[21], 19) ^ (w[21] >> 10));
|
||||
w[24] = 0x80000000U + w[17] + (rrot(w[22], 17) ^ rrot(w[22], 19) ^ (w[22] >> 10));
|
||||
w[25] = w[18] + (rrot(w[23], 17) ^ rrot(w[23], 19) ^ (w[23] >> 10));
|
||||
w[26] = w[19] + (rrot(w[24], 17) ^ rrot(w[24], 19) ^ (w[24] >> 10));
|
||||
w[27] = w[20] + (rrot(w[25], 17) ^ rrot(w[25], 19) ^ (w[25] >> 10));
|
||||
w[28] = w[21] + (rrot(w[26], 17) ^ rrot(w[26], 19) ^ (w[26] >> 10));
|
||||
w[29] = w[22] + (rrot(w[27], 17) ^ rrot(w[27], 19) ^ (w[27] >> 10));
|
||||
w[30] = w[23] + (rrot(0x100, 7) ^ rrot(0x100, 18) ^ (0x100 >> 3)) + (rrot(w[28], 17) ^ rrot(w[28], 19) ^ (w[28] >> 10));
|
||||
w[31] = 0x100 + w[24] + (rrot(w[16], 7) ^ rrot(w[16], 18) ^ (w[16] >> 3)) + (rrot(w[29], 17) ^ rrot(w[29], 19) ^ (w[29] >> 10));
|
||||
#pragma unroll
|
||||
for (int i = 32; i < 59; i++)
|
||||
w[i] = w[i - 16] + w[i - 7] + (rrot(w[i - 15], 7) ^ rrot(w[i - 15], 18) ^ (w[i - 15] >> 3)) + (rrot(w[i - 2], 17) ^ rrot(w[i - 2], 19) ^ (w[i - 2] >> 10));
|
||||
|
||||
d = 0x98c7e2a2U + w[0];
|
||||
h = 0xfc08884dU + w[0];
|
||||
//
|
||||
t1 = (rrot(d, 6) ^ rrot(d, 11) ^ rrot(d, 25)) + (0x9b05688cU ^ (d & 0xca0b3af3)) + 0x90bb1e3cU + w[1];
|
||||
c = 0x3c6ef372U + t1;
|
||||
g = t1 + (rrot(h, 2) ^ rrot(h, 13) ^ rrot(h, 22)) + (0x2A01A605 | (h & 0xfb6feee7));
|
||||
//
|
||||
t1 = (rrot(c, 6) ^ rrot(c, 11) ^ rrot(c, 25)) + (0x510e527fU ^ (c & (d ^ 0x510e527fU))) + 0x50C6645BU + w[2];
|
||||
b = 0xbb67ae85U + t1;
|
||||
f = t1 + (rrot(g, 2) ^ rrot(g, 13) ^ rrot(g, 22)) + ((0x6a09e667U & h) | (g & (0x6a09e667U | h)));
|
||||
//
|
||||
t1 = (rrot(b, 6) ^ rrot(b, 11) ^ rrot(b, 25)) + (d ^ (b & (c ^ d))) + 0x3AC42E24U + w[3];
|
||||
a = 0x6a09e667U + t1;
|
||||
e = t1 + (rrot(f, 2) ^ rrot(f, 13) ^ rrot(f, 22)) + ((h & g) | (f & (h | g)));
|
||||
//
|
||||
t1 = d + (rrot(a, 6) ^ rrot(a, 11) ^ rrot(a, 25)) + (c ^ (a & (b ^ c))) + 0x3956c25bU + w[4];
|
||||
h += t1;
|
||||
d = t1 + (rrot(e, 2) ^ rrot(e, 13) ^ rrot(e, 22)) + ((g & f) | (e & (g | f)));
|
||||
//
|
||||
t1 = c + (rrot(h, 6) ^ rrot(h, 11) ^ rrot(h, 25)) + (b ^ (h & (a ^ b))) + 0x59f111f1U + w[5];
|
||||
g += t1;
|
||||
c = t1 + (rrot(d, 2) ^ rrot(d, 13) ^ rrot(d, 22)) + ((f & e) | (d & (f | e)));
|
||||
//
|
||||
t1 = b + (rrot(g, 6) ^ rrot(g, 11) ^ rrot(g, 25)) + (a ^ (g & (h ^ a))) + 0x923f82a4U + w[6];
|
||||
f += t1;
|
||||
b = t1 + (rrot(c, 2) ^ rrot(c, 13) ^ rrot(c, 22)) + ((e & d) | (c & (e | d)));
|
||||
//
|
||||
t1 = a + (rrot(f, 6) ^ rrot(f, 11) ^ rrot(f, 25)) + (h ^ (f & (g ^ h))) + 0xab1c5ed5U + w[7];
|
||||
e += t1;
|
||||
a = t1 + (rrot(b, 2) ^ rrot(b, 13) ^ rrot(b, 22)) + ((d & c) | (b & (d | c)));
|
||||
//
|
||||
t1 = h + (rrot(e, 6) ^ rrot(e, 11) ^ rrot(e, 25)) + (g ^ (e & (f ^ g))) + 0x5807aa98U;
|
||||
d += t1;
|
||||
h = t1 + (rrot(a, 2) ^ rrot(a, 13) ^ rrot(a, 22)) + ((c & b) | (a & (c | b)));
|
||||
//
|
||||
t1 = g + (rrot(d, 6) ^ rrot(d, 11) ^ rrot(d, 25)) + (f ^ (d & (e ^ f))) + 0x12835b01U;
|
||||
c += t1;
|
||||
g = t1 + (rrot(h, 2) ^ rrot(h, 13) ^ rrot(h, 22)) + ((b & a) | (h & (b | a)));
|
||||
//
|
||||
t1 = f + (rrot(c, 6) ^ rrot(c, 11) ^ rrot(c, 25)) + (e ^ (c & (d ^ e))) + 0x243185beU;
|
||||
b += t1;
|
||||
f = t1 + (rrot(g, 2) ^ rrot(g, 13) ^ rrot(g, 22)) + ((a & h) | (g & (a | h)));
|
||||
//
|
||||
t1 = e + (rrot(b, 6) ^ rrot(b, 11) ^ rrot(b, 25)) + (d ^ (b & (c ^ d))) + 0x550c7dc3U;
|
||||
a += t1;
|
||||
e = t1 + (rrot(f, 2) ^ rrot(f, 13) ^ rrot(f, 22)) + ((h & g) | (f & (h | g)));
|
||||
//
|
||||
t1 = d + (rrot(a, 6) ^ rrot(a, 11) ^ rrot(a, 25)) + (c ^ (a & (b ^ c))) + 0x72be5d74U;
|
||||
h += t1;
|
||||
d = t1 + (rrot(e, 2) ^ rrot(e, 13) ^ rrot(e, 22)) + ((g & f) | (e & (g | f)));
|
||||
//
|
||||
t1 = c + (rrot(h, 6) ^ rrot(h, 11) ^ rrot(h, 25)) + (b ^ (h & (a ^ b))) + 0x80deb1feU;
|
||||
g += t1;
|
||||
c = t1 + (rrot(d, 2) ^ rrot(d, 13) ^ rrot(d, 22)) + ((f & e) | (d & (f | e)));
|
||||
//
|
||||
t1 = b + (rrot(g, 6) ^ rrot(g, 11) ^ rrot(g, 25)) + (a ^ (g & (h ^ a))) + 0x9bdc06a7U;
|
||||
f += t1;
|
||||
b = t1 + (rrot(c, 2) ^ rrot(c, 13) ^ rrot(c, 22)) + ((e & d) | (c & (e | d)));
|
||||
//
|
||||
t1 = a + (rrot(f, 6) ^ rrot(f, 11) ^ rrot(f, 25)) + (h ^ (f & (g ^ h))) + 0xc19bf274U;
|
||||
e += t1;
|
||||
a = t1 + (rrot(b, 2) ^ rrot(b, 13) ^ rrot(b, 22)) + ((d & c) | (b & (d | c)));
|
||||
//
|
||||
t1 = h + (rrot(e, 6) ^ rrot(e, 11) ^ rrot(e, 25)) + (g ^ (e & (f ^ g))) + 0xe49b69c1U + w[16];
|
||||
d += t1;
|
||||
h = t1 + (rrot(a, 2) ^ rrot(a, 13) ^ rrot(a, 22)) + ((c & b) | (a & (c | b)));
|
||||
//
|
||||
t1 = g + (rrot(d, 6) ^ rrot(d, 11) ^ rrot(d, 25)) + (f ^ (d & (e ^ f))) + 0xefbe4786U + w[17];
|
||||
c += t1;
|
||||
g = t1 + (rrot(h, 2) ^ rrot(h, 13) ^ rrot(h, 22)) + ((b & a) | (h & (b | a)));
|
||||
//
|
||||
t1 = f + (rrot(c, 6) ^ rrot(c, 11) ^ rrot(c, 25)) + (e ^ (c & (d ^ e))) + 0x0fc19dc6U + w[18];
|
||||
b += t1;
|
||||
f = t1 + (rrot(g, 2) ^ rrot(g, 13) ^ rrot(g, 22)) + ((a & h) | (g & (a | h)));
|
||||
//
|
||||
t1 = e + (rrot(b, 6) ^ rrot(b, 11) ^ rrot(b, 25)) + (d ^ (b & (c ^ d))) + 0x240ca1ccU + w[19];
|
||||
a += t1;
|
||||
e = t1 + (rrot(f, 2) ^ rrot(f, 13) ^ rrot(f, 22)) + ((h & g) | (f & (h | g)));
|
||||
//
|
||||
t1 = d + (rrot(a, 6) ^ rrot(a, 11) ^ rrot(a, 25)) + (c ^ (a & (b ^ c))) + 0x2de92c6fU + w[20];
|
||||
h += t1;
|
||||
d = t1 + (rrot(e, 2) ^ rrot(e, 13) ^ rrot(e, 22)) + ((g & f) | (e & (g | f)));
|
||||
//
|
||||
t1 = c + (rrot(h, 6) ^ rrot(h, 11) ^ rrot(h, 25)) + (b ^ (h & (a ^ b))) + 0x4a7484aaU + w[21];
|
||||
g += t1;
|
||||
c = t1 + (rrot(d, 2) ^ rrot(d, 13) ^ rrot(d, 22)) + ((f & e) | (d & (f | e)));
|
||||
//
|
||||
t1 = b + (rrot(g, 6) ^ rrot(g, 11) ^ rrot(g, 25)) + (a ^ (g & (h ^ a))) + 0x5cb0a9dcU + w[22];
|
||||
f += t1;
|
||||
b = t1 + (rrot(c, 2) ^ rrot(c, 13) ^ rrot(c, 22)) + ((e & d) | (c & (e | d)));
|
||||
//
|
||||
t1 = a + (rrot(f, 6) ^ rrot(f, 11) ^ rrot(f, 25)) + (h ^ (f & (g ^ h))) + 0x76f988daU + w[23];
|
||||
e += t1;
|
||||
a = t1 + (rrot(b, 2) ^ rrot(b, 13) ^ rrot(b, 22)) + ((d & c) | (b & (d | c)));
|
||||
//
|
||||
t1 = h + (rrot(e, 6) ^ rrot(e, 11) ^ rrot(e, 25)) + (g ^ (e & (f ^ g))) + 0x983e5152U + w[24];
|
||||
d += t1;
|
||||
h = t1 + (rrot(a, 2) ^ rrot(a, 13) ^ rrot(a, 22)) + ((c & b) | (a & (c | b)));
|
||||
//
|
||||
t1 = g + (rrot(d, 6) ^ rrot(d, 11) ^ rrot(d, 25)) + (f ^ (d & (e ^ f))) + 0xa831c66dU + w[25];
|
||||
c += t1;
|
||||
g = t1 + (rrot(h, 2) ^ rrot(h, 13) ^ rrot(h, 22)) + ((b & a) | (h & (b | a)));
|
||||
//
|
||||
t1 = f + (rrot(c, 6) ^ rrot(c, 11) ^ rrot(c, 25)) + (e ^ (c & (d ^ e))) + 0xb00327c8U + w[26];
|
||||
b += t1;
|
||||
f = t1 + (rrot(g, 2) ^ rrot(g, 13) ^ rrot(g, 22)) + ((a & h) | (g & (a | h)));
|
||||
//
|
||||
t1 = e + (rrot(b, 6) ^ rrot(b, 11) ^ rrot(b, 25)) + (d ^ (b & (c ^ d))) + 0xbf597fc7U + w[27];
|
||||
a += t1;
|
||||
e = t1 + (rrot(f, 2) ^ rrot(f, 13) ^ rrot(f, 22)) + ((h & g) | (f & (h | g)));
|
||||
//
|
||||
t1 = d + (rrot(a, 6) ^ rrot(a, 11) ^ rrot(a, 25)) + (c ^ (a & (b ^ c))) + 0xc6e00bf3U + w[28];
|
||||
h += t1;
|
||||
d = t1 + (rrot(e, 2) ^ rrot(e, 13) ^ rrot(e, 22)) + ((g & f) | (e & (g | f)));
|
||||
//
|
||||
t1 = c + (rrot(h, 6) ^ rrot(h, 11) ^ rrot(h, 25)) + (b ^ (h & (a ^ b))) + 0xd5a79147U + w[29];
|
||||
g += t1;
|
||||
c = t1 + (rrot(d, 2) ^ rrot(d, 13) ^ rrot(d, 22)) + ((f & e) | (d & (f | e)));
|
||||
//
|
||||
t1 = b + (rrot(g, 6) ^ rrot(g, 11) ^ rrot(g, 25)) + (a ^ (g & (h ^ a))) + 0x06ca6351U + w[30];
|
||||
f += t1;
|
||||
b = t1 + (rrot(c, 2) ^ rrot(c, 13) ^ rrot(c, 22)) + ((e & d) | (c & (e | d)));
|
||||
//
|
||||
t1 = a + (rrot(f, 6) ^ rrot(f, 11) ^ rrot(f, 25)) + (h ^ (f & (g ^ h))) + 0x14292967U + w[31];
|
||||
e += t1;
|
||||
a = t1 + (rrot(b, 2) ^ rrot(b, 13) ^ rrot(b, 22)) + ((d & c) | (b & (d | c)));
|
||||
//
|
||||
t1 = h + (rrot(e, 6) ^ rrot(e, 11) ^ rrot(e, 25)) + (g ^ (e & (f ^ g))) + 0x27b70a85U + w[32];
|
||||
d += t1;
|
||||
h = t1 + (rrot(a, 2) ^ rrot(a, 13) ^ rrot(a, 22)) + ((c & b) | (a & (c | b)));
|
||||
//
|
||||
t1 = g + (rrot(d, 6) ^ rrot(d, 11) ^ rrot(d, 25)) + (f ^ (d & (e ^ f))) + 0x2e1b2138U + w[33];
|
||||
c += t1;
|
||||
g = t1 + (rrot(h, 2) ^ rrot(h, 13) ^ rrot(h, 22)) + ((b & a) | (h & (b | a)));
|
||||
//
|
||||
t1 = f + (rrot(c, 6) ^ rrot(c, 11) ^ rrot(c, 25)) + (e ^ (c & (d ^ e))) + 0x4d2c6dfcU + w[34];
|
||||
b += t1;
|
||||
f = t1 + (rrot(g, 2) ^ rrot(g, 13) ^ rrot(g, 22)) + ((a & h) | (g & (a | h)));
|
||||
//
|
||||
t1 = e + (rrot(b, 6) ^ rrot(b, 11) ^ rrot(b, 25)) + (d ^ (b & (c ^ d))) + 0x53380d13U + w[35];
|
||||
a += t1;
|
||||
e = t1 + (rrot(f, 2) ^ rrot(f, 13) ^ rrot(f, 22)) + ((h & g) | (f & (h | g)));
|
||||
//
|
||||
t1 = d + (rrot(a, 6) ^ rrot(a, 11) ^ rrot(a, 25)) + (c ^ (a & (b ^ c))) + 0x650a7354U + w[36];
|
||||
h += t1;
|
||||
d = t1 + (rrot(e, 2) ^ rrot(e, 13) ^ rrot(e, 22)) + ((g & f) | (e & (g | f)));
|
||||
//
|
||||
t1 = c + (rrot(h, 6) ^ rrot(h, 11) ^ rrot(h, 25)) + (b ^ (h & (a ^ b))) + 0x766a0abbU + w[37];
|
||||
g += t1;
|
||||
c = t1 + (rrot(d, 2) ^ rrot(d, 13) ^ rrot(d, 22)) + ((f & e) | (d & (f | e)));
|
||||
//
|
||||
t1 = b + (rrot(g, 6) ^ rrot(g, 11) ^ rrot(g, 25)) + (a ^ (g & (h ^ a))) + 0x81c2c92eU + w[38];
|
||||
f += t1;
|
||||
b = t1 + (rrot(c, 2) ^ rrot(c, 13) ^ rrot(c, 22)) + ((e & d) | (c & (e | d)));
|
||||
//
|
||||
t1 = a + (rrot(f, 6) ^ rrot(f, 11) ^ rrot(f, 25)) + (h ^ (f & (g ^ h))) + 0x92722c85U + w[39];
|
||||
e += t1;
|
||||
a = t1 + (rrot(b, 2) ^ rrot(b, 13) ^ rrot(b, 22)) + ((d & c) | (b & (d | c)));
|
||||
//
|
||||
t1 = h + (rrot(e, 6) ^ rrot(e, 11) ^ rrot(e, 25)) + (g ^ (e & (f ^ g))) + 0xa2bfe8a1U + w[40];
|
||||
d += t1;
|
||||
h = t1 + (rrot(a, 2) ^ rrot(a, 13) ^ rrot(a, 22)) + ((c & b) | (a & (c | b)));
|
||||
//
|
||||
t1 = g + (rrot(d, 6) ^ rrot(d, 11) ^ rrot(d, 25)) + (f ^ (d & (e ^ f))) + 0xa81a664bU + w[41];
|
||||
c += t1;
|
||||
g = t1 + (rrot(h, 2) ^ rrot(h, 13) ^ rrot(h, 22)) + ((b & a) | (h & (b | a)));
|
||||
//
|
||||
t1 = f + (rrot(c, 6) ^ rrot(c, 11) ^ rrot(c, 25)) + (e ^ (c & (d ^ e))) + 0xc24b8b70U + w[42];
|
||||
b += t1;
|
||||
f = t1 + (rrot(g, 2) ^ rrot(g, 13) ^ rrot(g, 22)) + ((a & h) | (g & (a | h)));
|
||||
//
|
||||
t1 = e + (rrot(b, 6) ^ rrot(b, 11) ^ rrot(b, 25)) + (d ^ (b & (c ^ d))) + 0xc76c51a3U + w[43];
|
||||
a += t1;
|
||||
e = t1 + (rrot(f, 2) ^ rrot(f, 13) ^ rrot(f, 22)) + ((h & g) | (f & (h | g)));
|
||||
//
|
||||
t1 = d + (rrot(a, 6) ^ rrot(a, 11) ^ rrot(a, 25)) + (c ^ (a & (b ^ c))) + 0xd192e819U + w[44];
|
||||
h += t1;
|
||||
d = t1 + (rrot(e, 2) ^ rrot(e, 13) ^ rrot(e, 22)) + ((g & f) | (e & (g | f)));
|
||||
//
|
||||
t1 = c + (rrot(h, 6) ^ rrot(h, 11) ^ rrot(h, 25)) + (b ^ (h & (a ^ b))) + 0xd6990624U + w[45];
|
||||
g += t1;
|
||||
c = t1 + (rrot(d, 2) ^ rrot(d, 13) ^ rrot(d, 22)) + ((f & e) | (d & (f | e)));
|
||||
//
|
||||
t1 = b + (rrot(g, 6) ^ rrot(g, 11) ^ rrot(g, 25)) + (a ^ (g & (h ^ a))) + 0xf40e3585U + w[46];
|
||||
f += t1;
|
||||
b = t1 + (rrot(c, 2) ^ rrot(c, 13) ^ rrot(c, 22)) + ((e & d) | (c & (e | d)));
|
||||
//
|
||||
t1 = a + (rrot(f, 6) ^ rrot(f, 11) ^ rrot(f, 25)) + (h ^ (f & (g ^ h))) + 0x106aa070U + w[47];
|
||||
e += t1;
|
||||
a = t1 + (rrot(b, 2) ^ rrot(b, 13) ^ rrot(b, 22)) + ((d & c) | (b & (d | c)));
|
||||
//
|
||||
t1 = h + (rrot(e, 6) ^ rrot(e, 11) ^ rrot(e, 25)) + (g ^ (e & (f ^ g))) + 0x19a4c116U + w[48];
|
||||
d += t1;
|
||||
h = t1 + (rrot(a, 2) ^ rrot(a, 13) ^ rrot(a, 22)) + ((c & b) | (a & (c | b)));
|
||||
//
|
||||
t1 = g + (rrot(d, 6) ^ rrot(d, 11) ^ rrot(d, 25)) + (f ^ (d & (e ^ f))) + 0x1e376c08U + w[49];
|
||||
c += t1;
|
||||
g = t1 + (rrot(h, 2) ^ rrot(h, 13) ^ rrot(h, 22)) + ((b & a) | (h & (b | a)));
|
||||
//
|
||||
t1 = f + (rrot(c, 6) ^ rrot(c, 11) ^ rrot(c, 25)) + (e ^ (c & (d ^ e))) + 0x2748774cU + w[50];
|
||||
b += t1;
|
||||
f = t1 + (rrot(g, 2) ^ rrot(g, 13) ^ rrot(g, 22)) + ((a & h) | (g & (a | h)));
|
||||
//
|
||||
t1 = e + (rrot(b, 6) ^ rrot(b, 11) ^ rrot(b, 25)) + (d ^ (b & (c ^ d))) + 0x34b0bcb5U + w[51];
|
||||
a += t1;
|
||||
e = t1 + (rrot(f, 2) ^ rrot(f, 13) ^ rrot(f, 22)) + ((h & g) | (f & (h | g)));
|
||||
//
|
||||
t1 = d + (rrot(a, 6) ^ rrot(a, 11) ^ rrot(a, 25)) + (c ^ (a & (b ^ c))) + 0x391c0cb3U + w[52];
|
||||
h += t1;
|
||||
d = t1 + (rrot(e, 2) ^ rrot(e, 13) ^ rrot(e, 22)) + ((g & f) | (e & (g | f)));
|
||||
//
|
||||
t1 = c + (rrot(h, 6) ^ rrot(h, 11) ^ rrot(h, 25)) + (b ^ (h & (a ^ b))) + 0x4ed8aa4aU + w[53];
|
||||
g += t1;
|
||||
c = t1 + (rrot(d, 2) ^ rrot(d, 13) ^ rrot(d, 22)) + ((f & e) | (d & (f | e)));
|
||||
//
|
||||
t1 = b + (rrot(g, 6) ^ rrot(g, 11) ^ rrot(g, 25)) + (a ^ (g & (h ^ a))) + 0x5b9cca4fU + w[54];
|
||||
f += t1;
|
||||
b = t1 + (rrot(c, 2) ^ rrot(c, 13) ^ rrot(c, 22)) + ((e & d) | (c & (e | d)));
|
||||
//
|
||||
t1 = a + (rrot(f, 6) ^ rrot(f, 11) ^ rrot(f, 25)) + (h ^ (f & (g ^ h))) + 0x682e6ff3U + w[55];
|
||||
e += t1;
|
||||
a = t1 + (rrot(b, 2) ^ rrot(b, 13) ^ rrot(b, 22)) + ((d & c) | (b & (d | c)));
|
||||
//
|
||||
t1 = h + (rrot(e, 6) ^ rrot(e, 11) ^ rrot(e, 25)) + (g ^ (e & (f ^ g))) + 0x748f82eeU + w[56];
|
||||
d += t1;
|
||||
h = t1 + (rrot(a, 2) ^ rrot(a, 13) ^ rrot(a, 22)) + ((c & b) | (a & (c | b)));
|
||||
//
|
||||
c += g + (rrot(d, 6) ^ rrot(d, 11) ^ rrot(d, 25)) + (f ^ (d & (e ^ f))) + 0x78a5636fU + w[57];
|
||||
//
|
||||
b += f + (rrot(c, 6) ^ rrot(c, 11) ^ rrot(c, 25)) + (e ^ (c & (d ^ e))) + 0x84c87814U + w[58];
|
||||
//
|
||||
a += e + (rrot(b, 6) ^ rrot(b, 11) ^ rrot(b, 25)) + (d ^ (b & (c ^ d))) + 0x8cc70208U + w[43] + w[52] + (rrot(w[44], 7) ^ rrot(w[44], 18) ^ (w[44] >> 3)) + (rrot(w[57], 17) ^ rrot(w[57], 19) ^ (w[57] >> 10));
|
||||
//
|
||||
h += d + (rrot(a, 6) ^ rrot(a, 11) ^ rrot(a, 25)) + (c ^ (a & (b ^ c))) + 0x90befffaU + w[44] + w[53] + (rrot(w[45], 7) ^ rrot(w[45], 18) ^ (w[45] >> 3)) + (rrot(w[58], 17) ^ rrot(w[58], 19) ^ (w[58] >> 10));
|
||||
//
|
||||
if (h == 0xa41f32e7)
|
||||
{
|
||||
uint32_t tmp = atomicCAS(result, 0xffffffff, nonce);
|
||||
if (tmp != 0xffffffff)
|
||||
result[1] = nonce;
|
||||
}
|
||||
} // nonce loop
|
||||
} // if thread<threads
|
||||
}
|
||||
|
||||
__host__
|
||||
void bitcoin_midstate(const uint32_t *data, uint32_t *midstate)
|
||||
{
|
||||
int i;
|
||||
uint32_t s0, s1, t1, t2, maj, ch, a, b, c, d, e, f, g, h;
|
||||
uint32_t w[64];
|
||||
|
||||
const uint32_t k[64] = {
|
||||
0x428a2f98U, 0x71374491U, 0xb5c0fbcfU, 0xe9b5dba5U, 0x3956c25bU, 0x59f111f1U, 0x923f82a4U, 0xab1c5ed5U,
|
||||
0xd807aa98U, 0x12835b01U, 0x243185beU, 0x550c7dc3U, 0x72be5d74U, 0x80deb1feU, 0x9bdc06a7U, 0xc19bf174U,
|
||||
0xe49b69c1U, 0xefbe4786U, 0x0fc19dc6U, 0x240ca1ccU, 0x2de92c6fU, 0x4a7484aaU, 0x5cb0a9dcU, 0x76f988daU,
|
||||
0x983e5152U, 0xa831c66dU, 0xb00327c8U, 0xbf597fc7U, 0xc6e00bf3U, 0xd5a79147U, 0x06ca6351U, 0x14292967U,
|
||||
0x27b70a85U, 0x2e1b2138U, 0x4d2c6dfcU, 0x53380d13U, 0x650a7354U, 0x766a0abbU, 0x81c2c92eU, 0x92722c85U,
|
||||
0xa2bfe8a1U, 0xa81a664bU, 0xc24b8b70U, 0xc76c51a3U, 0xd192e819U, 0xd6990624U, 0xf40e3585U, 0x106aa070U,
|
||||
0x19a4c116U, 0x1e376c08U, 0x2748774cU, 0x34b0bcb5U, 0x391c0cb3U, 0x4ed8aa4aU, 0x5b9cca4fU, 0x682e6ff3U,
|
||||
0x748f82eeU, 0x78a5636fU, 0x84c87814U, 0x8cc70208U, 0x90befffaU, 0xa4506cebU, 0xbef9a3f7U, 0xc67178f2U
|
||||
};
|
||||
const uint32_t hc[8] = {
|
||||
0x6a09e667U, 0xbb67ae85U, 0x3c6ef372U, 0xa54ff53aU,
|
||||
0x510e527fU, 0x9b05688cU, 0x1f83d9abU, 0x5be0cd19U
|
||||
};
|
||||
|
||||
for (i = 0; i <= 15; i++)
|
||||
{
|
||||
w[i] = data[i];
|
||||
}
|
||||
for (i = 16; i <= 63; i++)
|
||||
{
|
||||
s0 = rrot(w[i - 15], 7) ^ rrot(w[i - 15], 18) ^ (w[i - 15] >> 3);
|
||||
s1 = rrot(w[i - 2], 17) ^ rrot(w[i - 2], 19) ^ (w[i - 2] >> 10);
|
||||
w[i] = w[i - 16] + s0 + w[i - 7] + s1;
|
||||
}
|
||||
a = hc[0];
|
||||
b = hc[1];
|
||||
c = hc[2];
|
||||
d = hc[3];
|
||||
e = hc[4];
|
||||
f = hc[5];
|
||||
g = hc[6];
|
||||
h = hc[7];
|
||||
for (i = 0; i <= 63; i++)
|
||||
{
|
||||
s0 = rrot(a, 2) ^ rrot(a, 13) ^ rrot(a, 22);
|
||||
maj = (a & b) ^ (a & c) ^ (b & c);
|
||||
t2 = s0 + maj;
|
||||
s1 = rrot(e, 6) ^ rrot(e, 11) ^ rrot(e, 25);
|
||||
ch = (e & f) ^ ((~e) & g);
|
||||
t1 = h + s1 + ch + k[i] + w[i];
|
||||
h = g;
|
||||
g = f;
|
||||
f = e;
|
||||
e = d + t1;
|
||||
d = c;
|
||||
c = b;
|
||||
b = a;
|
||||
a = t1 + t2;
|
||||
}
|
||||
midstate[0] = a + hc[0];
|
||||
midstate[1] = b + hc[1];
|
||||
midstate[2] = c + hc[2];
|
||||
midstate[3] = d + hc[3];
|
||||
midstate[4] = e + hc[4];
|
||||
midstate[5] = f + hc[5];
|
||||
midstate[6] = g + hc[6];
|
||||
midstate[7] = h + hc[7];
|
||||
}
|
||||
|
||||
__host__
|
||||
void bitcoin_cpu_hash(int thr_id, uint32_t threads, uint32_t startNounce, const uint32_t *const ms, uint32_t merkle, uint32_t time, uint32_t compacttarget, uint32_t *const h_nounce)
|
||||
{
|
||||
uint32_t b2, c2, d2, f2, g2, h2, t1, w16, w17, t1c, t2c, w16rot, w17rot;
|
||||
|
||||
cudaMemsetAsync(d_result[thr_id], 0xff, 2 * sizeof(uint32_t), gpustream[thr_id]);
|
||||
|
||||
t1 = ms[7] + (rrot(ms[4], 6) ^ rrot(ms[4], 11) ^ rrot(ms[4], 25)) + (ms[6] ^ (ms[4] & (ms[5] ^ ms[6]))) + 0x428a2f98U + merkle;
|
||||
d2 = ms[3] + t1;
|
||||
h2 = t1 + (rrot(ms[0], 2) ^ rrot(ms[0], 13) ^ rrot(ms[0], 22)) + ((ms[2] & ms[1]) | (ms[0] & (ms[2] | ms[1])));
|
||||
//
|
||||
t1 = ms[6] + (rrot(d2, 6) ^ rrot(d2, 11) ^ rrot(d2, 25)) + (ms[5] ^ (d2 & (ms[4] ^ ms[5]))) + 0x71374491U + time;
|
||||
c2 = ms[2] + t1;
|
||||
g2 = t1 + (rrot(h2, 2) ^ rrot(h2, 13) ^ rrot(h2, 22)) + ((ms[1] & ms[0]) | (h2 & (ms[1] | ms[0])));
|
||||
//
|
||||
t1 = ms[5] + (rrot(c2, 6) ^ rrot(c2, 11) ^ rrot(c2, 25)) + (ms[4] ^ (c2 & (d2 ^ ms[4]))) + 0xb5c0fbcfU + compacttarget;
|
||||
b2 = ms[1] + t1;
|
||||
f2 = t1 + (rrot(g2, 2) ^ rrot(g2, 13) ^ rrot(g2, 22)) + ((ms[0] & h2) | (g2 & (ms[0] | h2)));
|
||||
|
||||
w16 = merkle + (rrot(time, 7) ^ rrot(time, 18) ^ (time >> 3));
|
||||
w16rot = (rrot(w16, 17) ^ rrot(w16, 19) ^ (w16 >> 10)) + compacttarget;
|
||||
w17 = time + (rrot(compacttarget, 7) ^ rrot(compacttarget, 18) ^ (compacttarget >> 3)) + 0x01100000U;
|
||||
w17rot = (rrot(w17, 17) ^ rrot(w17, 19) ^ (w17 >> 10)) + 0x11002000U;
|
||||
t2c = (rrot(f2, 2) ^ rrot(f2, 13) ^ rrot(f2, 22)) + ((h2 & g2) | (f2 & (h2 | g2)));
|
||||
t1c = ms[4] + (rrot(b2, 6) ^ rrot(b2, 11) ^ rrot(b2, 25)) + (d2 ^ (b2 & (c2 ^ d2))) + 0xe9b5dba5U;
|
||||
|
||||
dim3 grid((threads + TPB*NONCES_PER_THREAD - 1) / TPB / NONCES_PER_THREAD);
|
||||
dim3 block(TPB);
|
||||
bitcoin_gpu_hash << <grid, block, 0, gpustream[thr_id]>>> (threads, startNounce, d_result[thr_id], t1c, t2c, w16, w16rot, w17, w17rot, b2, c2, d2, f2, g2, h2, ms[0], ms[1], ms[2], ms[3], ms[4], ms[5], ms[6], ms[7], compacttarget);
|
||||
CUDA_SAFE_CALL(cudaMemcpyAsync(h_nounce, d_result[thr_id], 2 * sizeof(uint32_t), cudaMemcpyDeviceToHost, gpustream[thr_id])); cudaStreamSynchronize(gpustream[thr_id]);
|
||||
}
|
||||
|
||||
__host__
|
||||
void bitcoin_cpu_init(int thr_id)
|
||||
{
|
||||
CUDA_SAFE_CALL(cudaMalloc(&d_result[thr_id], 4 * sizeof(uint32_t)));
|
||||
}
|
||||
@@ -1,262 +0,0 @@
|
||||
/* CreditsCoin [CRD] djm34 implementation - 2015 */
|
||||
|
||||
/*
|
||||
#include <cuda.h>
|
||||
#include "cuda_runtime.h"
|
||||
#include "device_launch_parameters.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <memory.h>
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <memory.h>
|
||||
|
||||
#include "cuda_vector.h"
|
||||
|
||||
// extern cudaError_t MyStreamSynchronize(cudaStream_t stream, int situation, int thr_id);
|
||||
|
||||
// __device__ uint4 * S;
|
||||
__device__ uint8 *TheHash;
|
||||
uint32_t *d_BitNonce[MAX_GPUS];
|
||||
__constant__ uint32_t pTarget[8];
|
||||
__constant__ uint8 midstate;
|
||||
__constant__ uint32_t c_data[48];
|
||||
__constant__ uint16 shapad;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////// sha256 Transform function /////////////////////////
|
||||
|
||||
static __constant__ uint8 pad4 = {
|
||||
0x80000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000100
|
||||
};
|
||||
|
||||
static __constant__ uint8 H256 = {
|
||||
0x6A09E667, 0xBB67AE85, 0x3C6EF372,
|
||||
0xA54FF53A, 0x510E527F, 0x9B05688C,
|
||||
0x1F83D9AB, 0x5BE0CD19
|
||||
};
|
||||
|
||||
static __constant__ uint32_t Ksha[64] = {
|
||||
0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5,
|
||||
0x3956C25B, 0x59F111F1, 0x923F82A4, 0xAB1C5ED5,
|
||||
0xD807AA98, 0x12835B01, 0x243185BE, 0x550C7DC3,
|
||||
0x72BE5D74, 0x80DEB1FE, 0x9BDC06A7, 0xC19BF174,
|
||||
0xE49B69C1, 0xEFBE4786, 0x0FC19DC6, 0x240CA1CC,
|
||||
0x2DE92C6F, 0x4A7484AA, 0x5CB0A9DC, 0x76F988DA,
|
||||
0x983E5152, 0xA831C66D, 0xB00327C8, 0xBF597FC7,
|
||||
0xC6E00BF3, 0xD5A79147, 0x06CA6351, 0x14292967,
|
||||
0x27B70A85, 0x2E1B2138, 0x4D2C6DFC, 0x53380D13,
|
||||
0x650A7354, 0x766A0ABB, 0x81C2C92E, 0x92722C85,
|
||||
0xA2BFE8A1, 0xA81A664B, 0xC24B8B70, 0xC76C51A3,
|
||||
0xD192E819, 0xD6990624, 0xF40E3585, 0x106AA070,
|
||||
0x19A4C116, 0x1E376C08, 0x2748774C, 0x34B0BCB5,
|
||||
0x391C0CB3, 0x4ED8AA4A, 0x5B9CCA4F, 0x682E6FF3,
|
||||
0x748F82EE, 0x78A5636F, 0x84C87814, 0x8CC70208,
|
||||
0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2
|
||||
};
|
||||
|
||||
static __device__ __forceinline__
|
||||
uint32_t bsg2_0(const uint32_t x)
|
||||
{
|
||||
uint32_t r1 = ROTR32(x, 2);
|
||||
uint32_t r2 = ROTR32(x, 13);
|
||||
uint32_t r3 = ROTR32(x, 22);
|
||||
return xor3b(r1, r2, r3);
|
||||
}
|
||||
|
||||
static __device__ __forceinline__
|
||||
uint32_t bsg2_1(const uint32_t x)
|
||||
{
|
||||
uint32_t r1 = ROTR32(x, 6);
|
||||
uint32_t r2 = ROTR32(x, 11);
|
||||
uint32_t r3 = ROTR32(x, 25);
|
||||
return xor3b(r1, r2, r3);
|
||||
}
|
||||
|
||||
static __device__ __forceinline__
|
||||
uint32_t ssg2_0(const uint32_t x)
|
||||
{
|
||||
uint32_t r1 = ROTR32(x, 7);
|
||||
uint32_t r2 = ROTR32(x, 18);
|
||||
uint32_t r3 = shr_t32(x, 3);
|
||||
return xor3b(r1, r2, r3);
|
||||
}
|
||||
|
||||
static __device__ __forceinline__
|
||||
uint32_t ssg2_1(const uint32_t x)
|
||||
{
|
||||
uint32_t r1 = ROTR32(x, 17);
|
||||
uint32_t r2 = ROTR32(x, 19);
|
||||
uint32_t r3 = shr_t32(x, 10);
|
||||
return xor3b(r1, r2, r3);
|
||||
}
|
||||
|
||||
static __device__ __forceinline__
|
||||
void sha2_step1(const uint32_t a, const uint32_t b, const uint32_t c, uint32_t &d, const uint32_t e,
|
||||
const uint32_t f, const uint32_t g, uint32_t &h, const uint32_t in, const uint32_t Kshared)
|
||||
{
|
||||
uint32_t t1, t2;
|
||||
uint32_t vxandx = xandx(e, f, g);
|
||||
uint32_t bsg21 = bsg2_1(e);
|
||||
uint32_t bsg20 = bsg2_0(a);
|
||||
uint32_t andorv = andor32(a, b, c);
|
||||
|
||||
t1 = h + bsg21 + vxandx + Kshared + in;
|
||||
t2 = bsg20 + andorv;
|
||||
d = d + t1;
|
||||
h = t1 + t2;
|
||||
}
|
||||
|
||||
static __device__ __forceinline__
|
||||
void sha2_step2(const uint32_t a, const uint32_t b, const uint32_t c, uint32_t &d, const uint32_t e,
|
||||
const uint32_t f, const uint32_t g, uint32_t &h, uint32_t* in, const uint32_t pc, const uint32_t Kshared)
|
||||
{
|
||||
uint32_t t1, t2;
|
||||
|
||||
int pcidx1 = (pc - 2) & 0xF;
|
||||
int pcidx2 = (pc - 7) & 0xF;
|
||||
int pcidx3 = (pc - 15) & 0xF;
|
||||
uint32_t inx0 = in[pc];
|
||||
uint32_t inx1 = in[pcidx1];
|
||||
uint32_t inx2 = in[pcidx2];
|
||||
uint32_t inx3 = in[pcidx3];
|
||||
|
||||
uint32_t ssg21 = ssg2_1(inx1);
|
||||
uint32_t ssg20 = ssg2_0(inx3);
|
||||
uint32_t vxandx = xandx(e, f, g);
|
||||
uint32_t bsg21 = bsg2_1(e);
|
||||
uint32_t bsg20 = bsg2_0(a);
|
||||
uint32_t andorv = andor32(a, b, c);
|
||||
|
||||
in[pc] = ssg21 + inx2 + ssg20 + inx0;
|
||||
|
||||
t1 = h + bsg21 + vxandx + Kshared + in[pc];
|
||||
t2 = bsg20 + andorv;
|
||||
d = d + t1;
|
||||
h = t1 + t2;
|
||||
}
|
||||
|
||||
static __device__ __forceinline__
|
||||
uint8 sha256_Transform2(uint16 in[1], const uint8 &r) // also known as sha2_round_body
|
||||
{
|
||||
uint8 tmp = r;
|
||||
#define a tmp.s0
|
||||
#define b tmp.s1
|
||||
#define c tmp.s2
|
||||
#define d tmp.s3
|
||||
#define e tmp.s4
|
||||
#define f tmp.s5
|
||||
#define g tmp.s6
|
||||
#define h tmp.s7
|
||||
|
||||
sha2_step1(a, b, c, d, e, f, g, h, in[0].s0, Ksha[0]);
|
||||
sha2_step1(h, a, b, c, d, e, f, g, in[0].s1, Ksha[1]);
|
||||
sha2_step1(g, h, a, b, c, d, e, f, in[0].s2, Ksha[2]);
|
||||
sha2_step1(f, g, h, a, b, c, d, e, in[0].s3, Ksha[3]);
|
||||
sha2_step1(e, f, g, h, a, b, c, d, in[0].s4, Ksha[4]);
|
||||
sha2_step1(d, e, f, g, h, a, b, c, in[0].s5, Ksha[5]);
|
||||
sha2_step1(c, d, e, f, g, h, a, b, in[0].s6, Ksha[6]);
|
||||
sha2_step1(b, c, d, e, f, g, h, a, in[0].s7, Ksha[7]);
|
||||
sha2_step1(a, b, c, d, e, f, g, h, in[0].s8, Ksha[8]);
|
||||
sha2_step1(h, a, b, c, d, e, f, g, in[0].s9, Ksha[9]);
|
||||
sha2_step1(g, h, a, b, c, d, e, f, in[0].sa, Ksha[10]);
|
||||
sha2_step1(f, g, h, a, b, c, d, e, in[0].sb, Ksha[11]);
|
||||
sha2_step1(e, f, g, h, a, b, c, d, in[0].sc, Ksha[12]);
|
||||
sha2_step1(d, e, f, g, h, a, b, c, in[0].sd, Ksha[13]);
|
||||
sha2_step1(c, d, e, f, g, h, a, b, in[0].se, Ksha[14]);
|
||||
sha2_step1(b, c, d, e, f, g, h, a, in[0].sf, Ksha[15]);
|
||||
|
||||
#pragma unroll
|
||||
for (int i = 0; i<3; i++) {
|
||||
|
||||
sha2_step2(a, b, c, d, e, f, g, h, (uint32_t*)in, 0, Ksha[16 + 16 * i]);
|
||||
sha2_step2(h, a, b, c, d, e, f, g, (uint32_t*)in, 1, Ksha[17 + 16 * i]);
|
||||
sha2_step2(g, h, a, b, c, d, e, f, (uint32_t*)in, 2, Ksha[18 + 16 * i]);
|
||||
sha2_step2(f, g, h, a, b, c, d, e, (uint32_t*)in, 3, Ksha[19 + 16 * i]);
|
||||
sha2_step2(e, f, g, h, a, b, c, d, (uint32_t*)in, 4, Ksha[20 + 16 * i]);
|
||||
sha2_step2(d, e, f, g, h, a, b, c, (uint32_t*)in, 5, Ksha[21 + 16 * i]);
|
||||
sha2_step2(c, d, e, f, g, h, a, b, (uint32_t*)in, 6, Ksha[22 + 16 * i]);
|
||||
sha2_step2(b, c, d, e, f, g, h, a, (uint32_t*)in, 7, Ksha[23 + 16 * i]);
|
||||
sha2_step2(a, b, c, d, e, f, g, h, (uint32_t*)in, 8, Ksha[24 + 16 * i]);
|
||||
sha2_step2(h, a, b, c, d, e, f, g, (uint32_t*)in, 9, Ksha[25 + 16 * i]);
|
||||
sha2_step2(g, h, a, b, c, d, e, f, (uint32_t*)in, 10, Ksha[26 + 16 * i]);
|
||||
sha2_step2(f, g, h, a, b, c, d, e, (uint32_t*)in, 11, Ksha[27 + 16 * i]);
|
||||
sha2_step2(e, f, g, h, a, b, c, d, (uint32_t*)in, 12, Ksha[28 + 16 * i]);
|
||||
sha2_step2(d, e, f, g, h, a, b, c, (uint32_t*)in, 13, Ksha[29 + 16 * i]);
|
||||
sha2_step2(c, d, e, f, g, h, a, b, (uint32_t*)in, 14, Ksha[30 + 16 * i]);
|
||||
sha2_step2(b, c, d, e, f, g, h, a, (uint32_t*)in, 15, Ksha[31 + 16 * i]);
|
||||
}
|
||||
|
||||
#undef a
|
||||
#undef b
|
||||
#undef c
|
||||
#undef d
|
||||
#undef e
|
||||
#undef f
|
||||
return (r + tmp);
|
||||
}
|
||||
|
||||
|
||||
__global__ __launch_bounds__(256, 3)
|
||||
void bitcredit_gpu_hash(int threads, uint32_t startNonce,uint32_t* NonceVector)
|
||||
{
|
||||
uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x);
|
||||
uint32_t nonce = startNonce + thread;
|
||||
|
||||
uint16 data[1];
|
||||
uint8 state,state2;
|
||||
|
||||
data[0] = ((uint16*)c_data)[2];
|
||||
data[0].s3 = nonce;
|
||||
state = sha256_Transform2(data, midstate);
|
||||
|
||||
data[0].lo=state;
|
||||
data[0].hi=pad4;
|
||||
state2 = sha256_Transform2(data, H256);
|
||||
|
||||
if (MAKE_ULONGLONG(cuda_swab32(state2.s6), cuda_swab32(state2.s7)) <= ((uint64_t*)pTarget)[3])
|
||||
NonceVector[0] = nonce;
|
||||
}
|
||||
|
||||
__host__
|
||||
void bitcredit_cpu_init(uint32_t thr_id, int threads, uint32_t *hash)
|
||||
{
|
||||
cudaMemcpyToSymbol(TheHash, &hash, sizeof(hash), 0, cudaMemcpyHostToDevice);
|
||||
cudaMalloc(&d_BitNonce[thr_id], sizeof(uint32_t));
|
||||
}
|
||||
|
||||
__host__
|
||||
void bitcredit_setBlockTarget(uint32_t* pdata, const uint32_t* zmidstate,const void *target)
|
||||
{
|
||||
unsigned char PaddedMessage[192]; //bring balance to the force
|
||||
|
||||
memcpy(PaddedMessage, pdata, 168);
|
||||
memset(PaddedMessage+168, 0, 24);
|
||||
((uint32_t*)PaddedMessage)[42] = 0x80000000;
|
||||
((uint32_t*)PaddedMessage)[47] = 0x00000540;
|
||||
|
||||
CUDA_SAFE_CALL(cudaMemcpyToSymbol(midstate, zmidstate, 32, 0, cudaMemcpyHostToDevice));
|
||||
CUDA_SAFE_CALL(cudaMemcpyToSymbol(pTarget, target, 32, 0, cudaMemcpyHostToDevice));
|
||||
CUDA_SAFE_CALL(cudaMemcpyToSymbol(c_data, PaddedMessage, 48 * sizeof(uint32_t), 0, cudaMemcpyHostToDevice));
|
||||
}
|
||||
|
||||
__host__
|
||||
uint32_t bitcredit_cpu_hash(uint32_t thr_id, int threads, uint32_t startNounce, int order)
|
||||
{
|
||||
uint32_t result[MAX_GPUS];
|
||||
const int threadsperblock = 256;
|
||||
|
||||
memset(result, 0xff, sizeof(result));
|
||||
cudaMemset(d_BitNonce[thr_id], 0xff, sizeof(uint32_t));
|
||||
|
||||
dim3 grid((threads + threadsperblock - 1) / threadsperblock);
|
||||
dim3 block(threadsperblock);
|
||||
|
||||
bitcredit_gpu_hash << <grid, block >> >(threads, startNounce, d_BitNonce[thr_id]);
|
||||
|
||||
cudaMemcpy(&result[thr_id], d_BitNonce[thr_id], sizeof(uint32_t), cudaMemcpyDeviceToHost);
|
||||
|
||||
return result[thr_id];
|
||||
}
|
||||
+601
-664
File diff suppressed because it is too large.
Load diff
-630
@@ -1,630 +0,0 @@
|
||||
/*
|
||||
* Copyright 2011 ArtForz
|
||||
* Copyright 2011-2013 pooler
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation; either version 2 of the License, or (at your option)
|
||||
* any later version. See COPYING for more details.
|
||||
*/
|
||||
|
||||
#include "cpuminer-config.h"
|
||||
#include "miner.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#if defined(__arm__) && defined(__APCS_32__)
|
||||
#define EXTERN_SHA256
|
||||
#endif
|
||||
|
||||
static const uint32_t sha256_h[8] = {
|
||||
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
|
||||
0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
|
||||
};
|
||||
|
||||
static const uint32_t sha256_k[64] = {
|
||||
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
|
||||
0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
|
||||
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
|
||||
0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
|
||||
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
|
||||
0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
|
||||
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
|
||||
0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
|
||||
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
|
||||
0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
|
||||
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
|
||||
0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
|
||||
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
|
||||
0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
|
||||
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
|
||||
0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
|
||||
};
|
||||
|
||||
void sha256_init(uint32_t *state)
|
||||
{
|
||||
memcpy(state, sha256_h, 32);
|
||||
}
|
||||
|
||||
/* Elementary functions used by SHA256 */
|
||||
#define Ch(x, y, z) ((x & (y ^ z)) ^ z)
|
||||
#define Maj(x, y, z) ((x & (y | z)) | (y & z))
|
||||
#define ROTR(x, n) ((x >> n) | (x << (32 - n)))
|
||||
#define S0(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
|
||||
#define S1(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
|
||||
#define s0(x) (ROTR(x, 7) ^ ROTR(x, 18) ^ (x >> 3))
|
||||
#define s1(x) (ROTR(x, 17) ^ ROTR(x, 19) ^ (x >> 10))
|
||||
|
||||
/* SHA256 round function */
|
||||
#define RND(a, b, c, d, e, f, g, h, k) \
|
||||
do { \
|
||||
t0 = h + S1(e) + Ch(e, f, g) + k; \
|
||||
t1 = S0(a) + Maj(a, b, c); \
|
||||
d += t0; \
|
||||
h = t0 + t1; \
|
||||
} while (0)
|
||||
|
||||
/* Adjusted round function for rotating state */
|
||||
#define RNDr(S, W, i) \
|
||||
RND(S[(64 - i) % 8], S[(65 - i) % 8], \
|
||||
S[(66 - i) % 8], S[(67 - i) % 8], \
|
||||
S[(68 - i) % 8], S[(69 - i) % 8], \
|
||||
S[(70 - i) % 8], S[(71 - i) % 8], \
|
||||
W[i] + sha256_k[i])
|
||||
|
||||
#ifndef EXTERN_SHA256
|
||||
|
||||
/*
|
||||
* SHA256 block compression function. The 256-bit state is transformed via
|
||||
* the 512-bit input block to produce a new state.
|
||||
*/
|
||||
void sha256_transform(uint32_t *state, const uint32_t *block, int swap)
|
||||
{
|
||||
uint32_t W[64];
|
||||
uint32_t S[8];
|
||||
uint32_t t0, t1;
|
||||
int i;
|
||||
|
||||
/* 1. Prepare message schedule W. */
|
||||
if (swap) {
|
||||
for (i = 0; i < 16; i++)
|
||||
W[i] = swab32(block[i]);
|
||||
} else
|
||||
memcpy(W, block, 64);
|
||||
for (i = 16; i < 64; i += 2) {
|
||||
W[i] = s1(W[i - 2]) + W[i - 7] + s0(W[i - 15]) + W[i - 16];
|
||||
W[i+1] = s1(W[i - 1]) + W[i - 6] + s0(W[i - 14]) + W[i - 15];
|
||||
}
|
||||
|
||||
/* 2. Initialize working variables. */
|
||||
memcpy(S, state, 32);
|
||||
|
||||
/* 3. Mix. */
|
||||
RNDr(S, W, 0);
|
||||
RNDr(S, W, 1);
|
||||
RNDr(S, W, 2);
|
||||
RNDr(S, W, 3);
|
||||
RNDr(S, W, 4);
|
||||
RNDr(S, W, 5);
|
||||
RNDr(S, W, 6);
|
||||
RNDr(S, W, 7);
|
||||
RNDr(S, W, 8);
|
||||
RNDr(S, W, 9);
|
||||
RNDr(S, W, 10);
|
||||
RNDr(S, W, 11);
|
||||
RNDr(S, W, 12);
|
||||
RNDr(S, W, 13);
|
||||
RNDr(S, W, 14);
|
||||
RNDr(S, W, 15);
|
||||
RNDr(S, W, 16);
|
||||
RNDr(S, W, 17);
|
||||
RNDr(S, W, 18);
|
||||
RNDr(S, W, 19);
|
||||
RNDr(S, W, 20);
|
||||
RNDr(S, W, 21);
|
||||
RNDr(S, W, 22);
|
||||
RNDr(S, W, 23);
|
||||
RNDr(S, W, 24);
|
||||
RNDr(S, W, 25);
|
||||
RNDr(S, W, 26);
|
||||
RNDr(S, W, 27);
|
||||
RNDr(S, W, 28);
|
||||
RNDr(S, W, 29);
|
||||
RNDr(S, W, 30);
|
||||
RNDr(S, W, 31);
|
||||
RNDr(S, W, 32);
|
||||
RNDr(S, W, 33);
|
||||
RNDr(S, W, 34);
|
||||
RNDr(S, W, 35);
|
||||
RNDr(S, W, 36);
|
||||
RNDr(S, W, 37);
|
||||
RNDr(S, W, 38);
|
||||
RNDr(S, W, 39);
|
||||
RNDr(S, W, 40);
|
||||
RNDr(S, W, 41);
|
||||
RNDr(S, W, 42);
|
||||
RNDr(S, W, 43);
|
||||
RNDr(S, W, 44);
|
||||
RNDr(S, W, 45);
|
||||
RNDr(S, W, 46);
|
||||
RNDr(S, W, 47);
|
||||
RNDr(S, W, 48);
|
||||
RNDr(S, W, 49);
|
||||
RNDr(S, W, 50);
|
||||
RNDr(S, W, 51);
|
||||
RNDr(S, W, 52);
|
||||
RNDr(S, W, 53);
|
||||
RNDr(S, W, 54);
|
||||
RNDr(S, W, 55);
|
||||
RNDr(S, W, 56);
|
||||
RNDr(S, W, 57);
|
||||
RNDr(S, W, 58);
|
||||
RNDr(S, W, 59);
|
||||
RNDr(S, W, 60);
|
||||
RNDr(S, W, 61);
|
||||
RNDr(S, W, 62);
|
||||
RNDr(S, W, 63);
|
||||
|
||||
/* 4. Mix local working variables into global state */
|
||||
for (i = 0; i < 8; i++)
|
||||
state[i] += S[i];
|
||||
}
|
||||
|
||||
#endif /* EXTERN_SHA256 */
|
||||
|
||||
|
||||
static const uint32_t sha256d_hash1[16] = {
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x80000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000100
|
||||
};
|
||||
|
||||
static void sha256d_80_swap(uint32_t *hash, const uint32_t *data)
|
||||
{
|
||||
uint32_t S[16];
|
||||
int i;
|
||||
|
||||
sha256_init(S);
|
||||
sha256_transform(S, data, 0);
|
||||
sha256_transform(S, data + 16, 0);
|
||||
memcpy(S + 8, sha256d_hash1 + 8, 32);
|
||||
sha256_init(hash);
|
||||
sha256_transform(hash, S, 0);
|
||||
for (i = 0; i < 8; i++)
|
||||
hash[i] = swab32(hash[i]);
|
||||
}
|
||||
|
||||
void sha256d(unsigned char *hash, const unsigned char *data, int len)
|
||||
{
|
||||
uint32_t S[16], T[16];
|
||||
int i, r;
|
||||
|
||||
sha256_init(S);
|
||||
for (r = len; r > -9; r -= 64) {
|
||||
if (r < 64)
|
||||
memset(T, 0, 64);
|
||||
memcpy(T, data + len - r, r > 64 ? 64 : (r < 0 ? 0 : r));
|
||||
if (r >= 0 && r < 64)
|
||||
((unsigned char *)T)[r] = 0x80;
|
||||
for (i = 0; i < 16; i++)
|
||||
T[i] = be32dec(T + i);
|
||||
if (r < 56)
|
||||
T[15] = 8 * len;
|
||||
sha256_transform(S, T, 0);
|
||||
}
|
||||
memcpy(S + 8, sha256d_hash1 + 8, 32);
|
||||
sha256_init(T);
|
||||
sha256_transform(T, S, 0);
|
||||
for (i = 0; i < 8; i++)
|
||||
be32enc((uint32_t *)hash + i, T[i]);
|
||||
}
|
||||
|
||||
static inline void sha256d_preextend(uint32_t *W)
|
||||
{
|
||||
W[16] = s1(W[14]) + W[ 9] + s0(W[ 1]) + W[ 0];
|
||||
W[17] = s1(W[15]) + W[10] + s0(W[ 2]) + W[ 1];
|
||||
W[18] = s1(W[16]) + W[11] + W[ 2];
|
||||
W[19] = s1(W[17]) + W[12] + s0(W[ 4]);
|
||||
W[20] = W[13] + s0(W[ 5]) + W[ 4];
|
||||
W[21] = W[14] + s0(W[ 6]) + W[ 5];
|
||||
W[22] = W[15] + s0(W[ 7]) + W[ 6];
|
||||
W[23] = W[16] + s0(W[ 8]) + W[ 7];
|
||||
W[24] = W[17] + s0(W[ 9]) + W[ 8];
|
||||
W[25] = s0(W[10]) + W[ 9];
|
||||
W[26] = s0(W[11]) + W[10];
|
||||
W[27] = s0(W[12]) + W[11];
|
||||
W[28] = s0(W[13]) + W[12];
|
||||
W[29] = s0(W[14]) + W[13];
|
||||
W[30] = s0(W[15]) + W[14];
|
||||
W[31] = s0(W[16]) + W[15];
|
||||
}
|
||||
|
||||
static inline void sha256d_prehash(uint32_t *S, const uint32_t *W)
|
||||
{
|
||||
uint32_t t0, t1;
|
||||
RNDr(S, W, 0);
|
||||
RNDr(S, W, 1);
|
||||
RNDr(S, W, 2);
|
||||
}
|
||||
|
||||
#ifdef EXTERN_SHA256
|
||||
|
||||
void sha256d_ms(uint32_t *hash, uint32_t *W,
|
||||
const uint32_t *midstate, const uint32_t *prehash);
|
||||
|
||||
#else
|
||||
|
||||
static inline void sha256d_ms(uint32_t *hash, uint32_t *W,
|
||||
const uint32_t *midstate, const uint32_t *prehash)
|
||||
{
|
||||
uint32_t S[64];
|
||||
uint32_t t0, t1;
|
||||
int i;
|
||||
|
||||
S[18] = W[18];
|
||||
S[19] = W[19];
|
||||
S[20] = W[20];
|
||||
S[22] = W[22];
|
||||
S[23] = W[23];
|
||||
S[24] = W[24];
|
||||
S[30] = W[30];
|
||||
S[31] = W[31];
|
||||
|
||||
W[18] += s0(W[3]);
|
||||
W[19] += W[3];
|
||||
W[20] += s1(W[18]);
|
||||
W[21] = s1(W[19]);
|
||||
W[22] += s1(W[20]);
|
||||
W[23] += s1(W[21]);
|
||||
W[24] += s1(W[22]);
|
||||
W[25] = s1(W[23]) + W[18];
|
||||
W[26] = s1(W[24]) + W[19];
|
||||
W[27] = s1(W[25]) + W[20];
|
||||
W[28] = s1(W[26]) + W[21];
|
||||
W[29] = s1(W[27]) + W[22];
|
||||
W[30] += s1(W[28]) + W[23];
|
||||
W[31] += s1(W[29]) + W[24];
|
||||
for (i = 32; i < 64; i += 2) {
|
||||
W[i] = s1(W[i - 2]) + W[i - 7] + s0(W[i - 15]) + W[i - 16];
|
||||
W[i+1] = s1(W[i - 1]) + W[i - 6] + s0(W[i - 14]) + W[i - 15];
|
||||
}
|
||||
|
||||
memcpy(S, prehash, 32);
|
||||
|
||||
RNDr(S, W, 3);
|
||||
RNDr(S, W, 4);
|
||||
RNDr(S, W, 5);
|
||||
RNDr(S, W, 6);
|
||||
RNDr(S, W, 7);
|
||||
RNDr(S, W, 8);
|
||||
RNDr(S, W, 9);
|
||||
RNDr(S, W, 10);
|
||||
RNDr(S, W, 11);
|
||||
RNDr(S, W, 12);
|
||||
RNDr(S, W, 13);
|
||||
RNDr(S, W, 14);
|
||||
RNDr(S, W, 15);
|
||||
RNDr(S, W, 16);
|
||||
RNDr(S, W, 17);
|
||||
RNDr(S, W, 18);
|
||||
RNDr(S, W, 19);
|
||||
RNDr(S, W, 20);
|
||||
RNDr(S, W, 21);
|
||||
RNDr(S, W, 22);
|
||||
RNDr(S, W, 23);
|
||||
RNDr(S, W, 24);
|
||||
RNDr(S, W, 25);
|
||||
RNDr(S, W, 26);
|
||||
RNDr(S, W, 27);
|
||||
RNDr(S, W, 28);
|
||||
RNDr(S, W, 29);
|
||||
RNDr(S, W, 30);
|
||||
RNDr(S, W, 31);
|
||||
RNDr(S, W, 32);
|
||||
RNDr(S, W, 33);
|
||||
RNDr(S, W, 34);
|
||||
RNDr(S, W, 35);
|
||||
RNDr(S, W, 36);
|
||||
RNDr(S, W, 37);
|
||||
RNDr(S, W, 38);
|
||||
RNDr(S, W, 39);
|
||||
RNDr(S, W, 40);
|
||||
RNDr(S, W, 41);
|
||||
RNDr(S, W, 42);
|
||||
RNDr(S, W, 43);
|
||||
RNDr(S, W, 44);
|
||||
RNDr(S, W, 45);
|
||||
RNDr(S, W, 46);
|
||||
RNDr(S, W, 47);
|
||||
RNDr(S, W, 48);
|
||||
RNDr(S, W, 49);
|
||||
RNDr(S, W, 50);
|
||||
RNDr(S, W, 51);
|
||||
RNDr(S, W, 52);
|
||||
RNDr(S, W, 53);
|
||||
RNDr(S, W, 54);
|
||||
RNDr(S, W, 55);
|
||||
RNDr(S, W, 56);
|
||||
RNDr(S, W, 57);
|
||||
RNDr(S, W, 58);
|
||||
RNDr(S, W, 59);
|
||||
RNDr(S, W, 60);
|
||||
RNDr(S, W, 61);
|
||||
RNDr(S, W, 62);
|
||||
RNDr(S, W, 63);
|
||||
|
||||
for (i = 0; i < 8; i++)
|
||||
S[i] += midstate[i];
|
||||
|
||||
W[18] = S[18];
|
||||
W[19] = S[19];
|
||||
W[20] = S[20];
|
||||
W[22] = S[22];
|
||||
W[23] = S[23];
|
||||
W[24] = S[24];
|
||||
W[30] = S[30];
|
||||
W[31] = S[31];
|
||||
|
||||
memcpy(S + 8, sha256d_hash1 + 8, 32);
|
||||
S[16] = s1(sha256d_hash1[14]) + sha256d_hash1[ 9] + s0(S[ 1]) + S[ 0];
|
||||
S[17] = s1(sha256d_hash1[15]) + sha256d_hash1[10] + s0(S[ 2]) + S[ 1];
|
||||
S[18] = s1(S[16]) + sha256d_hash1[11] + s0(S[ 3]) + S[ 2];
|
||||
S[19] = s1(S[17]) + sha256d_hash1[12] + s0(S[ 4]) + S[ 3];
|
||||
S[20] = s1(S[18]) + sha256d_hash1[13] + s0(S[ 5]) + S[ 4];
|
||||
S[21] = s1(S[19]) + sha256d_hash1[14] + s0(S[ 6]) + S[ 5];
|
||||
S[22] = s1(S[20]) + sha256d_hash1[15] + s0(S[ 7]) + S[ 6];
|
||||
S[23] = s1(S[21]) + S[16] + s0(sha256d_hash1[ 8]) + S[ 7];
|
||||
S[24] = s1(S[22]) + S[17] + s0(sha256d_hash1[ 9]) + sha256d_hash1[ 8];
|
||||
S[25] = s1(S[23]) + S[18] + s0(sha256d_hash1[10]) + sha256d_hash1[ 9];
|
||||
S[26] = s1(S[24]) + S[19] + s0(sha256d_hash1[11]) + sha256d_hash1[10];
|
||||
S[27] = s1(S[25]) + S[20] + s0(sha256d_hash1[12]) + sha256d_hash1[11];
|
||||
S[28] = s1(S[26]) + S[21] + s0(sha256d_hash1[13]) + sha256d_hash1[12];
|
||||
S[29] = s1(S[27]) + S[22] + s0(sha256d_hash1[14]) + sha256d_hash1[13];
|
||||
S[30] = s1(S[28]) + S[23] + s0(sha256d_hash1[15]) + sha256d_hash1[14];
|
||||
S[31] = s1(S[29]) + S[24] + s0(S[16]) + sha256d_hash1[15];
|
||||
for (i = 32; i < 60; i += 2) {
|
||||
S[i] = s1(S[i - 2]) + S[i - 7] + s0(S[i - 15]) + S[i - 16];
|
||||
S[i+1] = s1(S[i - 1]) + S[i - 6] + s0(S[i - 14]) + S[i - 15];
|
||||
}
|
||||
S[60] = s1(S[58]) + S[53] + s0(S[45]) + S[44];
|
||||
|
||||
sha256_init(hash);
|
||||
|
||||
RNDr(hash, S, 0);
|
||||
RNDr(hash, S, 1);
|
||||
RNDr(hash, S, 2);
|
||||
RNDr(hash, S, 3);
|
||||
RNDr(hash, S, 4);
|
||||
RNDr(hash, S, 5);
|
||||
RNDr(hash, S, 6);
|
||||
RNDr(hash, S, 7);
|
||||
RNDr(hash, S, 8);
|
||||
RNDr(hash, S, 9);
|
||||
RNDr(hash, S, 10);
|
||||
RNDr(hash, S, 11);
|
||||
RNDr(hash, S, 12);
|
||||
RNDr(hash, S, 13);
|
||||
RNDr(hash, S, 14);
|
||||
RNDr(hash, S, 15);
|
||||
RNDr(hash, S, 16);
|
||||
RNDr(hash, S, 17);
|
||||
RNDr(hash, S, 18);
|
||||
RNDr(hash, S, 19);
|
||||
RNDr(hash, S, 20);
|
||||
RNDr(hash, S, 21);
|
||||
RNDr(hash, S, 22);
|
||||
RNDr(hash, S, 23);
|
||||
RNDr(hash, S, 24);
|
||||
RNDr(hash, S, 25);
|
||||
RNDr(hash, S, 26);
|
||||
RNDr(hash, S, 27);
|
||||
RNDr(hash, S, 28);
|
||||
RNDr(hash, S, 29);
|
||||
RNDr(hash, S, 30);
|
||||
RNDr(hash, S, 31);
|
||||
RNDr(hash, S, 32);
|
||||
RNDr(hash, S, 33);
|
||||
RNDr(hash, S, 34);
|
||||
RNDr(hash, S, 35);
|
||||
RNDr(hash, S, 36);
|
||||
RNDr(hash, S, 37);
|
||||
RNDr(hash, S, 38);
|
||||
RNDr(hash, S, 39);
|
||||
RNDr(hash, S, 40);
|
||||
RNDr(hash, S, 41);
|
||||
RNDr(hash, S, 42);
|
||||
RNDr(hash, S, 43);
|
||||
RNDr(hash, S, 44);
|
||||
RNDr(hash, S, 45);
|
||||
RNDr(hash, S, 46);
|
||||
RNDr(hash, S, 47);
|
||||
RNDr(hash, S, 48);
|
||||
RNDr(hash, S, 49);
|
||||
RNDr(hash, S, 50);
|
||||
RNDr(hash, S, 51);
|
||||
RNDr(hash, S, 52);
|
||||
RNDr(hash, S, 53);
|
||||
RNDr(hash, S, 54);
|
||||
RNDr(hash, S, 55);
|
||||
RNDr(hash, S, 56);
|
||||
|
||||
hash[2] += hash[6] + S1(hash[3]) + Ch(hash[3], hash[4], hash[5])
|
||||
+ S[57] + sha256_k[57];
|
||||
hash[1] += hash[5] + S1(hash[2]) + Ch(hash[2], hash[3], hash[4])
|
||||
+ S[58] + sha256_k[58];
|
||||
hash[0] += hash[4] + S1(hash[1]) + Ch(hash[1], hash[2], hash[3])
|
||||
+ S[59] + sha256_k[59];
|
||||
hash[7] += hash[3] + S1(hash[0]) + Ch(hash[0], hash[1], hash[2])
|
||||
+ S[60] + sha256_k[60]
|
||||
+ sha256_h[7];
|
||||
}
|
||||
|
||||
#endif /* EXTERN_SHA256 */
|
||||
|
||||
#if HAVE_SHA256_4WAY
|
||||
|
||||
void sha256d_ms_4way(uint32_t *hash, uint32_t *data,
|
||||
const uint32_t *midstate, const uint32_t *prehash);
|
||||
|
||||
static inline int scanhash_sha256d_4way(int thr_id, uint32_t *pdata,
|
||||
const uint32_t *ptarget, uint32_t max_nonce, unsigned long *hashes_done)
|
||||
{
|
||||
uint32_t data[4 * 64] __attribute__((aligned(128)));
|
||||
uint32_t hash[4 * 8] __attribute__((aligned(32)));
|
||||
uint32_t midstate[4 * 8] __attribute__((aligned(32)));
|
||||
uint32_t prehash[4 * 8] __attribute__((aligned(32)));
|
||||
uint32_t n = pdata[19] - 1;
|
||||
const uint32_t first_nonce = pdata[19];
|
||||
const uint32_t Htarg = ptarget[7];
|
||||
int i, j;
|
||||
|
||||
memcpy(data, pdata + 16, 64);
|
||||
sha256d_preextend(data);
|
||||
for (i = 31; i >= 0; i--)
|
||||
for (j = 0; j < 4; j++)
|
||||
data[i * 4 + j] = data[i];
|
||||
|
||||
sha256_init(midstate);
|
||||
sha256_transform(midstate, pdata, 0);
|
||||
memcpy(prehash, midstate, 32);
|
||||
sha256d_prehash(prehash, pdata + 16);
|
||||
for (i = 7; i >= 0; i--) {
|
||||
for (j = 0; j < 4; j++) {
|
||||
midstate[i * 4 + j] = midstate[i];
|
||||
prehash[i * 4 + j] = prehash[i];
|
||||
}
|
||||
}
|
||||
|
||||
do {
|
||||
for (i = 0; i < 4; i++)
|
||||
data[4 * 3 + i] = ++n;
|
||||
|
||||
sha256d_ms_4way(hash, data, midstate, prehash);
|
||||
|
||||
for (i = 0; i < 4; i++) {
|
||||
if (swab32(hash[4 * 7 + i]) <= Htarg) {
|
||||
pdata[19] = data[4 * 3 + i];
|
||||
sha256d_80_swap(hash, pdata);
|
||||
if (fulltest(hash, ptarget)) {
|
||||
*hashes_done = n - first_nonce + 1;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
} while (n < max_nonce && !work_restart[thr_id].restart);
|
||||
|
||||
*hashes_done = n - first_nonce + 1;
|
||||
pdata[19] = n;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* HAVE_SHA256_4WAY */
|
||||
|
||||
#if HAVE_SHA256_8WAY
|
||||
|
||||
void sha256d_ms_8way(uint32_t *hash, uint32_t *data,
|
||||
const uint32_t *midstate, const uint32_t *prehash);
|
||||
|
||||
static inline int scanhash_sha256d_8way(int thr_id, uint32_t *pdata,
|
||||
const uint32_t *ptarget, uint32_t max_nonce, unsigned long *hashes_done)
|
||||
{
|
||||
uint32_t data[8 * 64] __attribute__((aligned(128)));
|
||||
uint32_t hash[8 * 8] __attribute__((aligned(32)));
|
||||
uint32_t midstate[8 * 8] __attribute__((aligned(32)));
|
||||
uint32_t prehash[8 * 8] __attribute__((aligned(32)));
|
||||
uint32_t n = pdata[19] - 1;
|
||||
const uint32_t first_nonce = pdata[19];
|
||||
const uint32_t Htarg = ptarget[7];
|
||||
int i, j;
|
||||
|
||||
memcpy(data, pdata + 16, 64);
|
||||
sha256d_preextend(data);
|
||||
for (i = 31; i >= 0; i--)
|
||||
for (j = 0; j < 8; j++)
|
||||
data[i * 8 + j] = data[i];
|
||||
|
||||
sha256_init(midstate);
|
||||
sha256_transform(midstate, pdata, 0);
|
||||
memcpy(prehash, midstate, 32);
|
||||
sha256d_prehash(prehash, pdata + 16);
|
||||
for (i = 7; i >= 0; i--) {
|
||||
for (j = 0; j < 8; j++) {
|
||||
midstate[i * 8 + j] = midstate[i];
|
||||
prehash[i * 8 + j] = prehash[i];
|
||||
}
|
||||
}
|
||||
|
||||
do {
|
||||
for (i = 0; i < 8; i++)
|
||||
data[8 * 3 + i] = ++n;
|
||||
|
||||
sha256d_ms_8way(hash, data, midstate, prehash);
|
||||
|
||||
for (i = 0; i < 8; i++) {
|
||||
if (swab32(hash[8 * 7 + i]) <= Htarg) {
|
||||
pdata[19] = data[8 * 3 + i];
|
||||
sha256d_80_swap(hash, pdata);
|
||||
if (fulltest(hash, ptarget)) {
|
||||
*hashes_done = n - first_nonce + 1;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
} while (n < max_nonce && !work_restart[thr_id].restart);
|
||||
|
||||
*hashes_done = n - first_nonce + 1;
|
||||
pdata[19] = n;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* HAVE_SHA256_8WAY */
|
||||
|
||||
int scanhash_sha256d(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
|
||||
uint32_t max_nonce, unsigned long *hashes_done)
|
||||
{
|
||||
uint32_t data[64] /* __attribute__((aligned(128))) */;
|
||||
uint32_t hash[8] /* __attribute__((aligned(32))) */;
|
||||
uint32_t midstate[8] /* __attribute__((aligned(32))) */;
|
||||
uint32_t prehash[8] /* __attribute__((aligned(32))) */;
|
||||
uint32_t n = pdata[19] - 1;
|
||||
const uint32_t first_nonce = pdata[19];
|
||||
const uint32_t Htarg = ptarget[7];
|
||||
|
||||
#if HAVE_SHA256_8WAY
|
||||
if (sha256_use_8way())
|
||||
return scanhash_sha256d_8way(thr_id, pdata, ptarget,
|
||||
max_nonce, hashes_done);
|
||||
#endif
|
||||
#if HAVE_SHA256_4WAY
|
||||
if (sha256_use_4way())
|
||||
return scanhash_sha256d_4way(thr_id, pdata, ptarget,
|
||||
max_nonce, hashes_done);
|
||||
#endif
|
||||
|
||||
memcpy(data, pdata + 16, 64);
|
||||
sha256d_preextend(data);
|
||||
|
||||
sha256_init(midstate);
|
||||
sha256_transform(midstate, pdata, 0);
|
||||
memcpy(prehash, midstate, 32);
|
||||
sha256d_prehash(prehash, pdata + 16);
|
||||
|
||||
do {
|
||||
data[3] = ++n;
|
||||
sha256d_ms(hash, data, midstate, prehash);
|
||||
if (swab32(hash[7]) <= Htarg) {
|
||||
pdata[19] = data[3];
|
||||
sha256d_80_swap(hash, pdata);
|
||||
if (fulltest(hash, ptarget)) {
|
||||
*hashes_done = n - first_nonce + 1;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
} while (n < max_nonce && !work_restart[thr_id].restart);
|
||||
|
||||
*hashes_done = n - first_nonce + 1;
|
||||
pdata[19] = n;
|
||||
return 0;
|
||||
}
|
||||
@@ -1795,7 +1795,7 @@ void print_hash_tests(void)
|
||||
uchar *scratchbuf = NULL;
|
||||
char s[128] = {'\0'};
|
||||
uchar hash[128];
|
||||
uchar buf[168];
|
||||
uchar buf[128];
|
||||
|
||||
// work space for scratchpad based algos
|
||||
scratchbuf = (uchar*)calloc(128, 1024);
|
||||
@@ -1814,8 +1814,8 @@ void print_hash_tests(void)
|
||||
blake256hash(&hash[0], &buf[0], 14);
|
||||
printpfx("blake", hash);
|
||||
|
||||
creditshash(&hash[0], &buf[0]);
|
||||
printpfx("credits", hash);
|
||||
c11hash(&hash[0], &buf[0]);
|
||||
printpfx("c11", hash);
|
||||
|
||||
deephash(&hash[0], &buf[0]);
|
||||
printpfx("deep", hash);
|
||||
@@ -1856,9 +1856,6 @@ void print_hash_tests(void)
|
||||
pentablakehash(&hash[0], &buf[0]);
|
||||
printpfx("pentablake", hash);
|
||||
|
||||
pluckhash((uint32_t*)&hash[0], (uint32_t*)&buf[0], scratchbuf, 128);
|
||||
printpfx("pluck", hash);
|
||||
|
||||
quarkhash(&hash[0], &buf[0]);
|
||||
printpfx("quark", hash);
|
||||
|
||||
@@ -1880,6 +1877,9 @@ void print_hash_tests(void)
|
||||
s3hash(&hash[0], &buf[0]);
|
||||
printpfx("S3", hash);
|
||||
|
||||
whirlxHash(&hash[0], &buf[0]);
|
||||
printpfx("whirlpoolx", hash);
|
||||
|
||||
x11hash(&hash[0], &buf[0]);
|
||||
printpfx("X11", hash);
|
||||
|
||||
|
||||
+242
@@ -0,0 +1,242 @@
|
||||
extern "C"
|
||||
{
|
||||
#include "sph/sph_blake.h"
|
||||
#include "sph/sph_bmw.h"
|
||||
#include "sph/sph_groestl.h"
|
||||
#include "sph/sph_skein.h"
|
||||
#include "sph/sph_jh.h"
|
||||
#include "sph/sph_keccak.h"
|
||||
|
||||
#include "sph/sph_luffa.h"
|
||||
#include "sph/sph_cubehash.h"
|
||||
#include "sph/sph_shavite.h"
|
||||
#include "sph/sph_simd.h"
|
||||
#include "sph/sph_echo.h"
|
||||
}
|
||||
|
||||
#include "miner.h"
|
||||
#include "cuda_helper.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <memory.h>
|
||||
|
||||
static uint32_t *d_hash[MAX_GPUS];
|
||||
|
||||
extern void quark_blake512_cpu_init(int thr_id, uint32_t threads);
|
||||
extern void quark_blake512_cpu_setBlock_80(int thr_id, uint32_t *pdata);
|
||||
extern void quark_blake512_cpu_hash_80(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_hash);
|
||||
|
||||
extern void quark_bmw512_cpu_init(int thr_id, uint32_t threads);
|
||||
extern void quark_bmw512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_nonceVector, uint32_t *d_hash, int order);
|
||||
|
||||
extern void quark_groestl512_cpu_init(int thr_id, uint32_t threads);
|
||||
extern void quark_groestl512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_nonceVector, uint32_t *d_hash, int order);
|
||||
extern void quark_doublegroestl512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_nonceVector, uint32_t *d_hash, int order);
|
||||
|
||||
extern void quark_skein512_cpu_init(int thr_id, uint32_t threads);
|
||||
extern void quark_skein512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_nonceVector, uint32_t *d_hash, int order);
|
||||
|
||||
extern void quark_keccak512_cpu_init(int thr_id, uint32_t threads);
|
||||
extern void quark_keccak512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_nonceVector, uint32_t *d_hash, int order);
|
||||
|
||||
extern void quark_jh512_cpu_init(int thr_id, uint32_t threads);
|
||||
extern void quark_jh512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_nonceVector, uint32_t *d_hash, int order);
|
||||
|
||||
extern void x11_luffaCubehash512_cpu_init(int thr_id, uint32_t threads);
|
||||
extern void x11_luffaCubehash512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t *d_hash, int order);
|
||||
|
||||
extern void x11_shavite512_cpu_init(int thr_id, uint32_t threads);
|
||||
extern void x11_shavite512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_nonceVector, uint32_t *d_hash, int order);
|
||||
|
||||
extern int x11_simd512_cpu_init(int thr_id, uint32_t threads);
|
||||
extern void x11_simd512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_nonceVector, uint32_t *d_hash, int order);
|
||||
|
||||
extern void x11_echo512_cpu_init(int thr_id, uint32_t threads);
|
||||
extern void x11_echo512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_nonceVector, uint32_t *d_hash, int order);
|
||||
|
||||
extern void quark_compactTest_cpu_init(int thr_id, uint32_t threads);
|
||||
extern void quark_compactTest_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *inpHashes,
|
||||
uint32_t *d_noncesTrue, size_t *nrmTrue, uint32_t *d_noncesFalse, size_t *nrmFalse, int order);
|
||||
|
||||
// Flax/C11 CPU Hash
|
||||
extern "C" void c11hash(void *output, const void *input)
|
||||
{
|
||||
// blake1-bmw2-grs3-skein4-jh5-keccak6-luffa7-cubehash8-shavite9-simd10-echo11
|
||||
|
||||
sph_blake512_context ctx_blake;
|
||||
sph_bmw512_context ctx_bmw;
|
||||
sph_groestl512_context ctx_groestl;
|
||||
sph_jh512_context ctx_jh;
|
||||
sph_keccak512_context ctx_keccak;
|
||||
sph_skein512_context ctx_skein;
|
||||
sph_luffa512_context ctx_luffa;
|
||||
sph_cubehash512_context ctx_cubehash;
|
||||
sph_shavite512_context ctx_shavite;
|
||||
sph_simd512_context ctx_simd;
|
||||
sph_echo512_context ctx_echo;
|
||||
|
||||
unsigned char hash[128];
|
||||
memset(hash, 0, sizeof hash);
|
||||
|
||||
sph_blake512_init(&ctx_blake);
|
||||
sph_blake512 (&ctx_blake, input, 80);
|
||||
sph_blake512_close(&ctx_blake, (void*) hash);
|
||||
|
||||
sph_bmw512_init(&ctx_bmw);
|
||||
sph_bmw512 (&ctx_bmw, (const void*) hash, 64);
|
||||
sph_bmw512_close(&ctx_bmw, (void*) hash);
|
||||
|
||||
sph_groestl512_init(&ctx_groestl);
|
||||
sph_groestl512 (&ctx_groestl, (const void*) hash, 64);
|
||||
sph_groestl512_close(&ctx_groestl, (void*) hash);
|
||||
|
||||
sph_jh512_init(&ctx_jh);
|
||||
sph_jh512 (&ctx_jh, (const void*) hash, 64);
|
||||
sph_jh512_close(&ctx_jh, (void*) hash);
|
||||
|
||||
sph_keccak512_init(&ctx_keccak);
|
||||
sph_keccak512 (&ctx_keccak, (const void*) hash, 64);
|
||||
sph_keccak512_close(&ctx_keccak, (void*) hash);
|
||||
|
||||
sph_skein512_init(&ctx_skein);
|
||||
sph_skein512 (&ctx_skein, (const void*) hash, 64);
|
||||
sph_skein512_close(&ctx_skein, (void*) hash);
|
||||
|
||||
sph_luffa512_init(&ctx_luffa);
|
||||
sph_luffa512 (&ctx_luffa, (const void*) hash, 64);
|
||||
sph_luffa512_close (&ctx_luffa, (void*) hash);
|
||||
|
||||
sph_cubehash512_init(&ctx_cubehash);
|
||||
sph_cubehash512 (&ctx_cubehash, (const void*) hash, 64);
|
||||
sph_cubehash512_close(&ctx_cubehash, (void*) hash);
|
||||
|
||||
sph_shavite512_init(&ctx_shavite);
|
||||
sph_shavite512 (&ctx_shavite, (const void*) hash, 64);
|
||||
sph_shavite512_close(&ctx_shavite, (void*) hash);
|
||||
|
||||
sph_simd512_init(&ctx_simd);
|
||||
sph_simd512 (&ctx_simd, (const void*) hash, 64);
|
||||
sph_simd512_close(&ctx_simd, (void*) hash);
|
||||
|
||||
sph_echo512_init(&ctx_echo);
|
||||
sph_echo512 (&ctx_echo, (const void*) hash, 64);
|
||||
sph_echo512_close(&ctx_echo, (void*) hash);
|
||||
|
||||
memcpy(output, hash, 32);
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define TRACE(algo) { \
|
||||
if (max_nonce == 1 && pdata[19] <= 1) { \
|
||||
uint32_t* debugbuf = NULL; \
|
||||
cudaMallocHost(&debugbuf, 8*sizeof(uint32_t)); \
|
||||
cudaMemcpy(debugbuf, d_hash[thr_id], 8*sizeof(uint32_t), cudaMemcpyDeviceToHost); \
|
||||
printf("X11 %s %08x %08x %08x %08x...\n", algo, swab32(debugbuf[0]), swab32(debugbuf[1]), \
|
||||
swab32(debugbuf[2]), swab32(debugbuf[3])); \
|
||||
cudaFreeHost(debugbuf); \
|
||||
} \
|
||||
}
|
||||
#else
|
||||
#define TRACE(algo) {}
|
||||
#endif
|
||||
|
||||
static bool init[MAX_GPUS] = { 0 };
|
||||
|
||||
extern "C" int scanhash_c11(int thr_id, uint32_t *pdata, const uint32_t *ptarget, uint32_t max_nonce, unsigned long *hashes_done)
|
||||
{
|
||||
const uint32_t first_nonce = pdata[19];
|
||||
int intensity = (device_sm[device_map[thr_id]] >= 500 && !is_windows()) ? 20 : 19;
|
||||
uint32_t throughput = device_intensity(thr_id, __func__, 1U << intensity); // 19=256*256*8;
|
||||
throughput = min(throughput, max_nonce - first_nonce);
|
||||
|
||||
if (opt_benchmark)
|
||||
((uint32_t*)ptarget)[7] = 0x5;
|
||||
|
||||
if (!init[thr_id])
|
||||
{
|
||||
cudaSetDevice(device_map[thr_id]);
|
||||
|
||||
quark_blake512_cpu_init(thr_id, throughput);
|
||||
quark_bmw512_cpu_init(thr_id, throughput);
|
||||
quark_groestl512_cpu_init(thr_id, throughput);
|
||||
quark_skein512_cpu_init(thr_id, throughput);
|
||||
quark_keccak512_cpu_init(thr_id, throughput);
|
||||
quark_jh512_cpu_init(thr_id, throughput);
|
||||
x11_luffaCubehash512_cpu_init(thr_id, throughput);
|
||||
x11_shavite512_cpu_init(thr_id, throughput);
|
||||
x11_echo512_cpu_init(thr_id, throughput);
|
||||
if (x11_simd512_cpu_init(thr_id, throughput) != 0) {
|
||||
return 0;
|
||||
}
|
||||
CUDA_CALL_OR_RET_X(cudaMalloc(&d_hash[thr_id], 64 * throughput), 0); // why 64 ?
|
||||
|
||||
cuda_check_cpu_init(thr_id, throughput);
|
||||
|
||||
init[thr_id] = true;
|
||||
}
|
||||
|
||||
uint32_t endiandata[20];
|
||||
for (int k=0; k < 20; k++)
|
||||
be32enc(&endiandata[k], pdata[k]);
|
||||
|
||||
quark_blake512_cpu_setBlock_80(thr_id, endiandata);
|
||||
cuda_check_cpu_setTarget(ptarget);
|
||||
|
||||
do {
|
||||
int order = 0;
|
||||
uint32_t foundNonce;
|
||||
|
||||
// Hash with CUDA
|
||||
quark_blake512_cpu_hash_80(thr_id, throughput, pdata[19], d_hash[thr_id]); order++;
|
||||
TRACE("blake :");
|
||||
quark_bmw512_cpu_hash_64(thr_id, throughput, pdata[19], NULL, d_hash[thr_id], order++);
|
||||
TRACE("bmw :");
|
||||
quark_groestl512_cpu_hash_64(thr_id, throughput, pdata[19], NULL, d_hash[thr_id], order++);
|
||||
TRACE("groestl:");
|
||||
quark_jh512_cpu_hash_64(thr_id, throughput, pdata[19], NULL, d_hash[thr_id], order++);
|
||||
TRACE("jh512 :");
|
||||
quark_keccak512_cpu_hash_64(thr_id, throughput, pdata[19], NULL, d_hash[thr_id], order++);
|
||||
TRACE("keccak :");
|
||||
quark_skein512_cpu_hash_64(thr_id, throughput, pdata[19], NULL, d_hash[thr_id], order++);
|
||||
TRACE("skein :");
|
||||
x11_luffaCubehash512_cpu_hash_64(thr_id, throughput, d_hash[thr_id], order++);
|
||||
TRACE("luffa+c:");
|
||||
x11_shavite512_cpu_hash_64(thr_id, throughput, pdata[19], NULL, d_hash[thr_id], order++);
|
||||
TRACE("shavite:");
|
||||
x11_simd512_cpu_hash_64(thr_id, throughput, pdata[19], NULL, d_hash[thr_id], order++);
|
||||
TRACE("simd :");
|
||||
x11_echo512_cpu_hash_64(thr_id, throughput, pdata[19], NULL, d_hash[thr_id], order++);
|
||||
TRACE("echo => ");
|
||||
|
||||
foundNonce = cuda_check_hash(thr_id, throughput, pdata[19], d_hash[thr_id]);
|
||||
if (foundNonce != UINT32_MAX)
|
||||
{
|
||||
const uint32_t Htarg = ptarget[7];
|
||||
uint32_t vhash64[8];
|
||||
be32enc(&endiandata[19], foundNonce);
|
||||
c11hash(vhash64, endiandata);
|
||||
|
||||
if (vhash64[7] <= Htarg && fulltest(vhash64, ptarget)) {
|
||||
int res = 1;
|
||||
// check if there was some other ones...
|
||||
uint32_t secNonce = cuda_check_hash_suppl(thr_id, throughput, pdata[19], d_hash[thr_id], 1);
|
||||
*hashes_done = pdata[19] - first_nonce + throughput;
|
||||
if (secNonce != 0) {
|
||||
pdata[21] = secNonce;
|
||||
res++;
|
||||
}
|
||||
pdata[19] = foundNonce;
|
||||
return res;
|
||||
} else {
|
||||
applog(LOG_WARNING, "GPU #%d: result for %08x does not validate on CPU!", device_map[thr_id], foundNonce);
|
||||
pdata[19] = foundNonce + 1;
|
||||
}
|
||||
}
|
||||
|
||||
pdata[19] += throughput;
|
||||
|
||||
} while (pdata[19] < max_nonce && !work_restart[thr_id].restart);
|
||||
|
||||
*hashes_done = pdata[19] - first_nonce + 1;
|
||||
return 0;
|
||||
}
|
||||
@@ -231,6 +231,7 @@ extern "C" int scanhash_x11(int thr_id, uint32_t *pdata,
|
||||
return res;
|
||||
} else {
|
||||
applog(LOG_WARNING, "GPU #%d: result for %08x does not validate on CPU!", device_map[thr_id], foundNonce);
|
||||
pdata[19] = foundNonce + 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,585 @@
|
||||
/*
|
||||
* Built on cbuchner1's implementation, actual hashing code
|
||||
* based on sphlib 3.0
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <memory.h>
|
||||
|
||||
#define threadsPerBlock 1024
|
||||
|
||||
#include "cuda_helper.h"
|
||||
|
||||
__constant__ uint64_t c_PaddedMessage80[16]; // padded message (80 bytes + padding)
|
||||
__constant__ uint64_t c_xtra[8];
|
||||
__constant__ uint64_t c_tmp[72];
|
||||
__constant__ uint64_t pTarget[4];
|
||||
|
||||
static uint32_t *h_wxnounce[MAX_GPUS] = { 0 };
|
||||
static uint32_t *d_WXNonce[MAX_GPUS] = { 0 };
|
||||
|
||||
/**
|
||||
* Whirlpool CUDA kernel implementation.
|
||||
*
|
||||
* ==========================(LICENSE BEGIN)============================
|
||||
*
|
||||
* Copyright (c) 2014 djm34 & tpruvot & SP & Provos Alexis
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* ===========================(LICENSE END)=============================
|
||||
* @author djm34
|
||||
* @author tpruvot
|
||||
* @author SP
|
||||
* @author Provos Alexis
|
||||
*/
|
||||
|
||||
__constant__ __align__(64) uint64_t mixTob0Tox[256];
|
||||
|
||||
const uint64_t plain_T0[256]= {
|
||||
0xD83078C018601818,0x2646AF05238C2323,0xB891F97EC63FC6C6,0xFBCD6F13E887E8E8,0xCB13A14C87268787,0x116D62A9B8DAB8B8,0x0902050801040101,0x0D9E6E424F214F4F,0x9B6CEEAD36D83636,
|
||||
0xFF510459A6A2A6A6,0x0CB9BDDED26FD2D2,0x0EF706FBF5F3F5F5,0x96F280EF79F97979,0x30DECE5F6FA16F6F,0x6D3FEFFC917E9191,0xF8A407AA52555252,0x47C0FD27609D6060,0x35657689BCCABCBC,
|
||||
0x372BCDAC9B569B9B,0x8A018C048E028E8E,0xD25B1571A3B6A3A3,0x6C183C600C300C0C,0x84F68AFF7BF17B7B,0x806AE1B535D43535,0xF53A69E81D741D1D,0xB3DD4753E0A7E0E0,0x21B3ACF6D77BD7D7,
|
||||
0x9C99ED5EC22FC2C2,0x435C966D2EB82E2E,0x29967A624B314B4B,0x5DE121A3FEDFFEFE,0xD5AE168257415757,0xBD2A41A815541515,0xE8EEB69F77C17777,0x926EEBA537DC3737,0x9ED7567BE5B3E5E5,
|
||||
0x1323D98C9F469F9F,0x23FD17D3F0E7F0F0,0x20947F6A4A354A4A,0x44A9959EDA4FDADA,0xA2B025FA587D5858,0xCF8FCA06C903C9C9,0x7C528D5529A42929,0x5A1422500A280A0A,0x507F4FE1B1FEB1B1,
|
||||
0xC95D1A69A0BAA0A0,0x14D6DA7F6BB16B6B,0xD917AB5C852E8585,0x3C677381BDCEBDBD,0x8FBA34D25D695D5D,0x9020508010401010,0x07F503F3F4F7F4F4,0xDD8BC016CB0BCBCB,0xD37CC6ED3EF83E3E,
|
||||
0x2D0A112805140505,0x78CEE61F67816767,0x97D55373E4B7E4E4,0x024EBB25279C2727,0x7382583241194141,0xA70B9D2C8B168B8B,0xF6530151A7A6A7A7,0xB2FA94CF7DE97D7D,0x4937FBDC956E9595,
|
||||
0x56AD9F8ED847D8D8,0x70EB308BFBCBFBFB,0xCDC17123EE9FEEEE,0xBBF891C77CED7C7C,0x71CCE31766856666,0x7BA78EA6DD53DDDD,0xAF2E4BB8175C1717,0x458E460247014747,0x1A21DC849E429E9E,
|
||||
0xD489C51ECA0FCACA,0x585A99752DB42D2D,0x2E637991BFC6BFBF,0x3F0E1B38071C0707,0xAC472301AD8EADAD,0xB0B42FEA5A755A5A,0xEF1BB56C83368383,0xB666FF8533CC3333,0x5CC6F23F63916363,
|
||||
0x12040A1002080202,0x93493839AA92AAAA,0xDEE2A8AF71D97171,0xC68DCF0EC807C8C8,0xD1327DC819641919,0x3B92707249394949,0x5FAF9A86D943D9D9,0x31F91DC3F2EFF2F2,0xA8DB484BE3ABE3E3,
|
||||
0xB9B62AE25B715B5B,0xBC0D9234881A8888,0x3E29C8A49A529A9A,0x0B4CBE2D26982626,0xBF64FA8D32C83232,0x597D4AE9B0FAB0B0,0xF2CF6A1BE983E9E9,0x771E33780F3C0F0F,0x33B7A6E6D573D5D5,
|
||||
0xF41DBA74803A8080,0x27617C99BEC2BEBE,0xEB87DE26CD13CDCD,0x8968E4BD34D03434,0x3290757A483D4848,0x54E324ABFFDBFFFF,0x8DF48FF77AF57A7A,0x643DEAF4907A9090,0x9DBE3EC25F615F5F,
|
||||
0x3D40A01D20802020,0x0FD0D56768BD6868,0xCA3472D01A681A1A,0xB7412C19AE82AEAE,0x7D755EC9B4EAB4B4,0xCEA8199A544D5454,0x7F3BE5EC93769393,0x2F44AA0D22882222,0x63C8E907648D6464,
|
||||
0x2AFF12DBF1E3F1F1,0xCCE6A2BF73D17373,0x82245A9012481212,0x7A805D3A401D4040,0x4810284008200808,0x959BE856C32BC3C3,0xDFC57B33EC97ECEC,0x4DAB9096DB4BDBDB,0xC05F1F61A1BEA1A1,
|
||||
0x9107831C8D0E8D8D,0xC87AC9F53DF43D3D,0x5B33F1CC97669797,0x0000000000000000,0xF983D436CF1BCFCF,0x6E5687452BAC2B2B,0xE1ECB39776C57676,0xE619B06482328282,0x28B1A9FED67FD6D6,
|
||||
0xC33677D81B6C1B1B,0x74775BC1B5EEB5B5,0xBE432911AF86AFAF,0x1DD4DF776AB56A6A,0xEAA00DBA505D5050,0x578A4C1245094545,0x38FB18CBF3EBF3F3,0xAD60F09D30C03030,0xC4C3742BEF9BEFEF,
|
||||
0xDA7EC3E53FFC3F3F,0xC7AA1C9255495555,0xDB591079A2B2A2A2,0xE9C96503EA8FEAEA,0x6ACAEC0F65896565,0x036968B9BAD2BABA,0x4A5E93652FBC2F2F,0x8E9DE74EC027C0C0,0x60A181BEDE5FDEDE,
|
||||
0xFC386CE01C701C1C,0x46E72EBBFDD3FDFD,0x1F9A64524D294D4D,0x7639E0E492729292,0xFAEABC8F75C97575,0x360C1E3006180606,0xAE0998248A128A8A,0x4B7940F9B2F2B2B2,0x85D15963E6BFE6E6,
|
||||
0x7E1C36700E380E0E,0xE73E63F81F7C1F1F,0x55C4F73762956262,0x3AB5A3EED477D4D4,0x814D3229A89AA8A8,0x5231F4C496629696,0x62EF3A9BF9C3F9F9,0xA397F666C533C5C5,0x104AB13525942525,
|
||||
0xABB220F259795959,0xD015AE54842A8484,0xC5E4A7B772D57272,0xEC72DDD539E43939,0x1698615A4C2D4C4C,0x94BC3BCA5E655E5E,0x9FF085E778FD7878,0xE570D8DD38E03838,0x980586148C0A8C8C,
|
||||
0x17BFB2C6D163D1D1,0xE4570B41A5AEA5A5,0xA1D94D43E2AFE2E2,0x4EC2F82F61996161,0x427B45F1B3F6B3B3,0x3442A51521842121,0x0825D6949C4A9C9C,0xEE3C66F01E781E1E,0x6186522243114343,
|
||||
0xB193FC76C73BC7C7,0x4FE52BB3FCD7FCFC,0x2408142004100404,0xE3A208B251595151,0x252FC7BC995E9999,0x22DAC44F6DA96D6D,0x651A39680D340D0D,0x79E93583FACFFAFA,0x69A384B6DF5BDFDF,
|
||||
0xA9FC9BD77EE57E7E,0x1948B43D24902424,0xFE76D7C53BEC3B3B,0x9A4B3D31AB96ABAB,0xF081D13ECE1FCECE,0x9922558811441111,0x8303890C8F068F8F,0x049C6B4A4E254E4E,0x667351D1B7E6B7B7,
|
||||
0xE0CB600BEB8BEBEB,0xC178CCFD3CF03C3C,0xFD1FBF7C813E8181,0x4035FED4946A9494,0x1CF30CEBF7FBF7F7,0x186F67A1B9DEB9B9,0x8B265F98134C1313,0x51589C7D2CB02C2C,0x05BBB8D6D36BD3D3,
|
||||
0x8CD35C6BE7BBE7E7,0x39DCCB576EA56E6E,0xAA95F36EC437C4C4,0x1B060F18030C0303,0xDCAC138A56455656,0x5E88491A440D4444,0xA0FE9EDF7FE17F7F,0x884F3721A99EA9A9,0x6754824D2AA82A2A,
|
||||
0x0A6B6DB1BBD6BBBB,0x879FE246C123C1C1,0xF1A602A253515353,0x72A58BAEDC57DCDC,0x531627580B2C0B0B,0x0127D39C9D4E9D9D,0x2BD8C1476CAD6C6C,0xA462F59531C43131,0xF3E8B98774CD7474,
|
||||
0x15F109E3F6FFF6F6,0x4C8C430A46054646,0xA5452609AC8AACAC,0xB50F973C891E8989,0xB42844A014501414,0xBADF425BE1A3E1E1,0xA62C4EB016581616,0xF774D2CD3AE83A3A,0x06D2D06F69B96969,
|
||||
0x41122D4809240909,0xD7E0ADA770DD7070,0x6F7154D9B6E2B6B6,0x1EBDB7CED067D0D0,0xD6C77E3BED93EDED,0xE285DB2ECC17CCCC,0x6884572A42154242,0x2C2DC2B4985A9898,0xED550E49A4AAA4A4,
|
||||
0x7550885D28A02828,0x86B831DA5C6D5C5C,0x6BED3F93F8C7F8F8,0xC211A44486228686
|
||||
};
|
||||
|
||||
/**
|
||||
* Round constants.
|
||||
*/
|
||||
__constant__ uint64_t InitVector_RC[10];
|
||||
|
||||
const uint64_t plain_RC[10] = {
|
||||
0x4F01B887E8C62318,0x52916F79F5D2A636,0x357B0CA38E9BBC60,0x57FE4B2EC2D7E01D,0xDA4AF09FE5377715,
|
||||
0x856BA0B10A29C958,0x67053ECBF4105DBD,0xD8957DA78B4127E4,0x9E4717DD667CEEFB,0x33835AAD07BF2DCA
|
||||
};
|
||||
|
||||
/* ====================================================================== */
|
||||
|
||||
__device__ __forceinline__
|
||||
static uint64_t ROUND_ELT(const uint64_t* sharedMemory, const uint64_t* __restrict__ in, const int i0, const int i1, const int i2, const int i3, const int i4, const int i5, const int i6, const int i7)
|
||||
{
|
||||
uint32_t* in32 = (uint32_t*)in;
|
||||
return xor8( sharedMemory[__byte_perm(in32[(i0 << 1)], 0, 0x4440)],
|
||||
sharedMemory[__byte_perm(in32[(i1 << 1)], 0, 0x4441) + 256],
|
||||
sharedMemory[__byte_perm(in32[(i2 << 1)], 0, 0x4442) + 512],
|
||||
sharedMemory[__byte_perm(in32[(i3 << 1)], 0, 0x4443) + 768],
|
||||
sharedMemory[__byte_perm(in32[(i4 << 1) + 1], 0, 0x4440) + 1024],
|
||||
sharedMemory[__byte_perm(in32[(i5 << 1) + 1], 0, 0x4441) + 1280],
|
||||
sharedMemory[__byte_perm(in32[(i6 << 1) + 1], 0, 0x4442) + 1536],
|
||||
sharedMemory[__byte_perm(in32[(i7 << 1) + 1], 0, 0x4443) + 1792]);
|
||||
}
|
||||
|
||||
#define TRANSFER(dst, src) { \
|
||||
dst[0] = src ## 0; \
|
||||
dst[1] = src ## 1; \
|
||||
dst[2] = src ## 2; \
|
||||
dst[3] = src ## 3; \
|
||||
dst[4] = src ## 4; \
|
||||
dst[5] = src ## 5; \
|
||||
dst[6] = src ## 6; \
|
||||
dst[7] = src ## 7; \
|
||||
}
|
||||
|
||||
#define ROUND(table, in, out, c0, c1, c2, c3, c4, c5, c6, c7) { \
|
||||
out ## 0 = xor1(ROUND_ELT(table, in, 0, 7, 6, 5, 4, 3, 2, 1), c0); \
|
||||
out ## 1 = xor1(ROUND_ELT(table, in, 1, 0, 7, 6, 5, 4, 3, 2), c1); \
|
||||
out ## 2 = xor1(ROUND_ELT(table, in, 2, 1, 0, 7, 6, 5, 4, 3), c2); \
|
||||
out ## 3 = xor1(ROUND_ELT(table, in, 3, 2, 1, 0, 7, 6, 5, 4), c3); \
|
||||
out ## 4 = xor1(ROUND_ELT(table, in, 4, 3, 2, 1, 0, 7, 6, 5), c4); \
|
||||
out ## 5 = xor1(ROUND_ELT(table, in, 5, 4, 3, 2, 1, 0, 7, 6), c5); \
|
||||
out ## 6 = xor1(ROUND_ELT(table, in, 6, 5, 4, 3, 2, 1, 0, 7), c6); \
|
||||
out ## 7 = xor1(ROUND_ELT(table, in, 7, 6, 5, 4, 3, 2, 1, 0), c7); \
|
||||
}
|
||||
|
||||
#define ROUND1(table, in, out, c) { \
|
||||
out ## 0 = xor1(ROUND_ELT(table, in, 0, 7, 6, 5, 4, 3, 2, 1), c); \
|
||||
out ## 1 = ROUND_ELT(table, in, 1, 0, 7, 6, 5, 4, 3, 2); \
|
||||
out ## 2 = ROUND_ELT(table, in, 2, 1, 0, 7, 6, 5, 4, 3); \
|
||||
out ## 3 = ROUND_ELT(table, in, 3, 2, 1, 0, 7, 6, 5, 4); \
|
||||
out ## 4 = ROUND_ELT(table, in, 4, 3, 2, 1, 0, 7, 6, 5); \
|
||||
out ## 5 = ROUND_ELT(table, in, 5, 4, 3, 2, 1, 0, 7, 6); \
|
||||
out ## 6 = ROUND_ELT(table, in, 6, 5, 4, 3, 2, 1, 0, 7); \
|
||||
out ## 7 = ROUND_ELT(table, in, 7, 6, 5, 4, 3, 2, 1, 0); \
|
||||
}
|
||||
|
||||
#define ROUND_KSCHED(table, in, out, c) \
|
||||
ROUND1(table, in, out, c) \
|
||||
TRANSFER(in, out)
|
||||
|
||||
#define ROUND_WENC(table, in, key, out) \
|
||||
ROUND(table, in, out, key[0], key[1], key[2],key[3], key[4], key[5], key[6], key[7]) \
|
||||
TRANSFER(in, out)
|
||||
|
||||
static uint64_t* d_xtra[MAX_GPUS] = { 0 };
|
||||
static uint64_t* d_tmp[MAX_GPUS] = { 0 };
|
||||
|
||||
__device__ __forceinline__
|
||||
static void whirlpoolx_getShared(uint64_t* sharedMemory)
|
||||
{
|
||||
if (threadIdx.x < 256) {
|
||||
sharedMemory[threadIdx.x] = mixTob0Tox[threadIdx.x];
|
||||
sharedMemory[threadIdx.x+256] = ROTL64(sharedMemory[threadIdx.x], 8);
|
||||
sharedMemory[threadIdx.x+512] = ROTL64(sharedMemory[threadIdx.x],16);
|
||||
sharedMemory[threadIdx.x+768] = ROTL64(sharedMemory[threadIdx.x],24);
|
||||
sharedMemory[threadIdx.x+1024] = ROTL64(sharedMemory[threadIdx.x],32);
|
||||
sharedMemory[threadIdx.x+1280] = ROTR64(sharedMemory[threadIdx.x],24);
|
||||
sharedMemory[threadIdx.x+1536] = ROTR64(sharedMemory[threadIdx.x],16);
|
||||
sharedMemory[threadIdx.x+1792] = ROTR64(sharedMemory[threadIdx.x], 8);
|
||||
}
|
||||
__syncthreads();
|
||||
}
|
||||
|
||||
|
||||
__global__
|
||||
void whirlpoolx_gpu_precompute(uint32_t threads, uint64_t* d_xtra, uint64_t* d_tmp)
|
||||
{
|
||||
__shared__ uint64_t sharedMemory[2048];
|
||||
|
||||
whirlpoolx_getShared(sharedMemory);
|
||||
uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x);
|
||||
if (thread < threads)
|
||||
{
|
||||
uint64_t n[8];
|
||||
uint64_t h[8] = { 0 };
|
||||
|
||||
#pragma unroll 8
|
||||
for (int i=0; i<8; i++) {
|
||||
n[i] = c_PaddedMessage80[i]; // read data
|
||||
}
|
||||
//#pragma unroll 10
|
||||
for (unsigned int r=0; r < 10; r++) {
|
||||
uint64_t tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
|
||||
ROUND_KSCHED(sharedMemory, h, tmp, InitVector_RC[r]);
|
||||
ROUND_WENC(sharedMemory, n, h, tmp);
|
||||
}
|
||||
#pragma unroll 8
|
||||
for (int i=0; i < 8; i++) {
|
||||
h[i] = xor1(n[i],c_PaddedMessage80[i]);
|
||||
}
|
||||
|
||||
if(threadIdx.x==0)d_xtra[threadIdx.x]=h[1];
|
||||
uint64_t atLastCalc=xor1(h[3],h[5]);
|
||||
|
||||
//////////////////////////////////
|
||||
n[0] = c_PaddedMessage80[8]; //read data
|
||||
n[1] = c_PaddedMessage80[9]; //whirlpool
|
||||
n[2] = 0x0000000000000080; //whirlpool
|
||||
n[3] = 0;
|
||||
n[4] = 0;
|
||||
n[5] = 0;
|
||||
n[6] = 0;
|
||||
n[7] = 0x8002000000000000;
|
||||
|
||||
n[0] = xor1(n[0],h[0]);
|
||||
n[2] = xor1(n[2],h[2]); n[3] = h[3];
|
||||
n[4] = h[4]; n[5] = h[5];
|
||||
n[6] = h[6]; n[7] = xor1(n[7],h[7]);
|
||||
uint64_t tmp[8];
|
||||
tmp[0] = xor1(ROUND_ELT(sharedMemory, h, 0, 7, 6, 5, 4, 3, 2, 1),InitVector_RC[0]);
|
||||
tmp[1] = ROUND_ELT(sharedMemory, h, 1, 0, 7, 6, 5, 4, 3, 2);
|
||||
tmp[2] = ROUND_ELT(sharedMemory, h, 2, 1, 0, 7, 6, 5, 4, 3);
|
||||
tmp[3] = ROUND_ELT(sharedMemory, h, 3, 2, 1, 0, 7, 6, 5, 4);
|
||||
tmp[4] = ROUND_ELT(sharedMemory, h, 4, 3, 2, 1, 0, 7, 6, 5);
|
||||
tmp[5] = ROUND_ELT(sharedMemory, h, 5, 4, 3, 2, 1, 0, 7, 6);
|
||||
tmp[6] = ROUND_ELT(sharedMemory, h, 6, 5, 4, 3, 2, 1, 0, 7);
|
||||
tmp[7] = ROUND_ELT(sharedMemory, h, 7, 6, 5, 4, 3, 2, 1, 0);
|
||||
|
||||
uint64_t tmp2[8];
|
||||
uint32_t* n32 = (uint32_t*)n;
|
||||
tmp2[0]=xor8( sharedMemory[__byte_perm(n32[ 0], 0, 0x4440)] ,sharedMemory[__byte_perm(n32[14], 0, 0x4441) + 256],
|
||||
sharedMemory[__byte_perm(n32[12], 0, 0x4442) + 512] ,sharedMemory[__byte_perm(n32[10], 0, 0x4443) + 768],
|
||||
sharedMemory[__byte_perm(n32[ 9], 0, 0x4440) + 1024] ,sharedMemory[__byte_perm(n32[ 7], 0, 0x4441) + 1280],
|
||||
sharedMemory[__byte_perm(n32[ 5], 0, 0x4442) + 1536] ,tmp[0]);
|
||||
|
||||
tmp2[1]=xor8( tmp[1] ,sharedMemory[__byte_perm(n32[ 0], 0, 0x4441) + 256],
|
||||
sharedMemory[__byte_perm(n32[14], 0, 0x4442) + 512] ,sharedMemory[__byte_perm(n32[12], 0, 0x4443) + 768],
|
||||
sharedMemory[__byte_perm(n32[11], 0, 0x4440) + 1024] ,sharedMemory[__byte_perm(n32[ 9], 0, 0x4441) + 1280],
|
||||
sharedMemory[__byte_perm(n32[ 7], 0, 0x4442) + 1536] ,sharedMemory[__byte_perm(n32[ 5], 0, 0x4443) + 1792]);
|
||||
|
||||
tmp2[2]=xor8( sharedMemory[__byte_perm(n32[ 4], 0, 0x4440)] ,tmp[2] ,
|
||||
sharedMemory[__byte_perm(n32[ 0], 0, 0x4442) + 512] ,sharedMemory[__byte_perm(n32[14], 0, 0x4443) + 768],
|
||||
sharedMemory[__byte_perm(n32[13], 0, 0x4440) + 1024] ,sharedMemory[__byte_perm(n32[11], 0, 0x4441) + 1280],
|
||||
sharedMemory[__byte_perm(n32[ 9], 0, 0x4442) + 1536] ,sharedMemory[__byte_perm(n32[ 7], 0, 0x4443) + 1792]);
|
||||
|
||||
tmp2[3]=xor8( sharedMemory[__byte_perm(n32[ 6], 0, 0x4440)] ,sharedMemory[__byte_perm(n32[ 4], 0, 0x4441) + 256],
|
||||
tmp[3] ,sharedMemory[__byte_perm(n32[ 0], 0, 0x4443) + 768],
|
||||
sharedMemory[__byte_perm(n32[15], 0, 0x4440) + 1024] ,sharedMemory[__byte_perm(n32[13], 0, 0x4441) + 1280],
|
||||
sharedMemory[__byte_perm(n32[11], 0, 0x4442) + 1536] ,sharedMemory[__byte_perm(n32[ 9], 0, 0x4443) + 1792]);
|
||||
|
||||
tmp2[4]=xor8( sharedMemory[__byte_perm(n32[ 8], 0, 0x4440)] ,sharedMemory[__byte_perm(n32[ 6], 0, 0x4441) + 256] ,
|
||||
sharedMemory[__byte_perm(n32[ 4], 0, 0x4442) + 512] ,tmp[4] ,
|
||||
sharedMemory[__byte_perm(n32[ 1], 0, 0x4440) + 1024] ,sharedMemory[__byte_perm(n32[15], 0, 0x4441) + 1280] ,
|
||||
sharedMemory[__byte_perm(n32[13], 0, 0x4442) + 1536] ,sharedMemory[__byte_perm(n32[11], 0, 0x4443) + 1792]);
|
||||
|
||||
tmp2[5]=xor8( sharedMemory[__byte_perm(n32[10], 0, 0x4440)] ,sharedMemory[__byte_perm(n32[ 8], 0, 0x4441) + 256],
|
||||
sharedMemory[__byte_perm(n32[ 6], 0, 0x4442) + 512] ,sharedMemory[__byte_perm(n32[ 4], 0, 0x4443) + 768],
|
||||
tmp[5] ,sharedMemory[__byte_perm(n32[ 1], 0, 0x4441) + 1280],
|
||||
sharedMemory[__byte_perm(n32[15], 0, 0x4442) + 1536] ,sharedMemory[__byte_perm(n32[13], 0, 0x4443) + 1792]);
|
||||
|
||||
tmp2[6]=xor8( sharedMemory[__byte_perm(n32[12], 0, 0x4440)] ,sharedMemory[__byte_perm(n32[10], 0, 0x4441) + 256],
|
||||
sharedMemory[__byte_perm(n32[ 8], 0, 0x4442) + 512] ,sharedMemory[__byte_perm(n32[ 6], 0, 0x4443) + 768],
|
||||
sharedMemory[__byte_perm(n32[ 5], 0, 0x4440) + 1024] ,tmp[6],
|
||||
sharedMemory[__byte_perm(n32[ 1], 0, 0x4442) + 1536] ,sharedMemory[__byte_perm(n32[15], 0, 0x4443) + 1792]);
|
||||
|
||||
tmp2[7]=xor8( sharedMemory[__byte_perm(n32[14], 0, 0x4440)] ,sharedMemory[__byte_perm(n32[12], 0, 0x4441) + 256],
|
||||
sharedMemory[__byte_perm(n32[10], 0, 0x4442) + 512] ,sharedMemory[__byte_perm(n32[ 8], 0, 0x4443) + 768],
|
||||
sharedMemory[__byte_perm(n32[ 7], 0, 0x4440) + 1024] ,sharedMemory[__byte_perm(n32[ 5], 0, 0x4441) + 1280],
|
||||
tmp[7] ,sharedMemory[__byte_perm(n32[ 1], 0, 0x4443) + 1792]);
|
||||
|
||||
n[1] ^= h[1];
|
||||
tmp2[1]^=sharedMemory[__byte_perm(n32[2], 0, 0x4440)];
|
||||
tmp2[2]^=sharedMemory[__byte_perm(n32[2], 0, 0x4441) + 256];
|
||||
tmp2[3]^=sharedMemory[__byte_perm(n32[2], 0, 0x4442) + 512];
|
||||
tmp2[4]^=sharedMemory[__byte_perm(n32[2], 0, 0x4443) + 768];
|
||||
|
||||
d_tmp[threadIdx.x]=tmp2[threadIdx.x];
|
||||
|
||||
uint64_t tmp3[8];
|
||||
tmp3[0] = xor1(ROUND_ELT(sharedMemory, tmp, 0, 7, 6, 5, 4, 3, 2, 1), InitVector_RC[1]);
|
||||
tmp3[1] = ROUND_ELT(sharedMemory, tmp, 1, 0, 7, 6, 5, 4, 3, 2);
|
||||
tmp3[2] = ROUND_ELT(sharedMemory, tmp, 2, 1, 0, 7, 6, 5, 4, 3);
|
||||
tmp3[3] = ROUND_ELT(sharedMemory, tmp, 3, 2, 1, 0, 7, 6, 5, 4);
|
||||
tmp3[4] = ROUND_ELT(sharedMemory, tmp, 4, 3, 2, 1, 0, 7, 6, 5);
|
||||
tmp3[5] = ROUND_ELT(sharedMemory, tmp, 5, 4, 3, 2, 1, 0, 7, 6);
|
||||
tmp3[6] = ROUND_ELT(sharedMemory, tmp, 6, 5, 4, 3, 2, 1, 0, 7);
|
||||
tmp3[7] = ROUND_ELT(sharedMemory, tmp, 7, 6, 5, 4, 3, 2, 1, 0);
|
||||
|
||||
n32 = (uint32_t*)tmp2;
|
||||
uint64_t tmp4[8];
|
||||
tmp4[0]=( sharedMemory[__byte_perm(n32[ 9], 0, 0x4440) + 1024] ^sharedMemory[__byte_perm(n32[ 7], 0, 0x4441) + 1280]^
|
||||
sharedMemory[__byte_perm(n32[ 5], 0, 0x4442) + 1536] ^sharedMemory[__byte_perm(n32[ 3], 0, 0x4443) + 1792]) ^tmp3[0];
|
||||
|
||||
tmp4[1]=(sharedMemory[__byte_perm(n32[ 2], 0, 0x4440)] ^sharedMemory[__byte_perm(n32[ 9], 0, 0x4441) + 1280]^
|
||||
sharedMemory[__byte_perm(n32[ 7], 0, 0x4442) + 1536] ^sharedMemory[__byte_perm(n32[ 5], 0, 0x4443) + 1792]) ^tmp3[1];
|
||||
|
||||
tmp4[2]=(sharedMemory[__byte_perm(n32[ 4], 0, 0x4440)] ^sharedMemory[__byte_perm(n32[ 2], 0, 0x4441) + 256]^
|
||||
sharedMemory[__byte_perm(n32[ 9], 0, 0x4442) + 1536] ^sharedMemory[__byte_perm(n32[ 7], 0, 0x4443) + 1792]) ^tmp3[2];
|
||||
|
||||
tmp4[3]=(sharedMemory[__byte_perm(n32[ 6], 0, 0x4440)] ^sharedMemory[__byte_perm(n32[ 4], 0, 0x4441) + 256]^
|
||||
sharedMemory[__byte_perm(n32[ 2], 0, 0x4442) + 512] ^sharedMemory[__byte_perm(n32[ 9], 0, 0x4443) + 1792]) ^tmp3[3];
|
||||
|
||||
tmp4[4]=(sharedMemory[__byte_perm(n32[ 8], 0, 0x4440)] ^sharedMemory[__byte_perm(n32[ 6], 0, 0x4441) + 256]^
|
||||
sharedMemory[__byte_perm(n32[ 4], 0, 0x4442) + 512] ^sharedMemory[__byte_perm(n32[ 2], 0, 0x4443) + 768]) ^tmp3[4];
|
||||
|
||||
tmp4[5]=(sharedMemory[__byte_perm(n32[ 8], 0, 0x4441) + 256] ^sharedMemory[__byte_perm(n32[ 6], 0, 0x4442) + 512]^
|
||||
sharedMemory[__byte_perm(n32[ 4], 0, 0x4443) + 768] ^sharedMemory[__byte_perm(n32[ 3], 0, 0x4440) + 1024]) ^tmp3[5];
|
||||
|
||||
tmp4[6]=(sharedMemory[__byte_perm(n32[ 8], 0, 0x4442) + 512] ^sharedMemory[__byte_perm(n32[ 6], 0, 0x4443) + 768]^
|
||||
sharedMemory[__byte_perm(n32[ 5], 0, 0x4440) + 1024] ^sharedMemory[__byte_perm(n32[ 3], 0, 0x4441) + 1280]) ^tmp3[6];
|
||||
|
||||
tmp4[7]=(sharedMemory[__byte_perm(n32[ 8], 0, 0x4443) + 768] ^sharedMemory[__byte_perm(n32[ 7], 0, 0x4440) + 1024]^
|
||||
sharedMemory[__byte_perm(n32[ 5], 0, 0x4441) + 1280] ^sharedMemory[__byte_perm(n32[ 3], 0, 0x4442) + 1536]) ^tmp3[7];
|
||||
|
||||
d_tmp[threadIdx.x+16]=tmp4[threadIdx.x];
|
||||
|
||||
uint64_t tmp5[8];
|
||||
tmp5[0] = xor1(ROUND_ELT(sharedMemory, tmp3, 0, 7, 6, 5, 4, 3, 2, 1), InitVector_RC[2]);
|
||||
tmp5[1] = ROUND_ELT(sharedMemory, tmp3, 1, 0, 7, 6, 5, 4, 3, 2);
|
||||
tmp5[2] = ROUND_ELT(sharedMemory, tmp3, 2, 1, 0, 7, 6, 5, 4, 3);
|
||||
tmp5[3] = ROUND_ELT(sharedMemory, tmp3, 3, 2, 1, 0, 7, 6, 5, 4);
|
||||
tmp5[4] = ROUND_ELT(sharedMemory, tmp3, 4, 3, 2, 1, 0, 7, 6, 5);
|
||||
tmp5[5] = ROUND_ELT(sharedMemory, tmp3, 5, 4, 3, 2, 1, 0, 7, 6);
|
||||
tmp5[6] = ROUND_ELT(sharedMemory, tmp3, 6, 5, 4, 3, 2, 1, 0, 7);
|
||||
tmp5[7] = ROUND_ELT(sharedMemory, tmp3, 7, 6, 5, 4, 3, 2, 1, 0);
|
||||
|
||||
d_tmp[threadIdx.x+8]=tmp5[threadIdx.x];
|
||||
|
||||
uint64_t tmp6[8];
|
||||
tmp6[0] = xor1(ROUND_ELT(sharedMemory, tmp5, 0, 7, 6, 5, 4, 3, 2, 1), InitVector_RC[3]);
|
||||
tmp6[1] = ROUND_ELT(sharedMemory, tmp5, 1, 0, 7, 6, 5, 4, 3, 2);
|
||||
tmp6[2] = ROUND_ELT(sharedMemory, tmp5, 2, 1, 0, 7, 6, 5, 4, 3);
|
||||
tmp6[3] = ROUND_ELT(sharedMemory, tmp5, 3, 2, 1, 0, 7, 6, 5, 4);
|
||||
tmp6[4] = ROUND_ELT(sharedMemory, tmp5, 4, 3, 2, 1, 0, 7, 6, 5);
|
||||
tmp6[5] = ROUND_ELT(sharedMemory, tmp5, 5, 4, 3, 2, 1, 0, 7, 6);
|
||||
tmp6[6] = ROUND_ELT(sharedMemory, tmp5, 6, 5, 4, 3, 2, 1, 0, 7);
|
||||
tmp6[7] = ROUND_ELT(sharedMemory, tmp5, 7, 6, 5, 4, 3, 2, 1, 0);
|
||||
|
||||
d_tmp[threadIdx.x+24]=tmp6[threadIdx.x];
|
||||
|
||||
uint64_t tmp7[8];
|
||||
tmp7[0] = xor1(ROUND_ELT(sharedMemory, tmp6, 0, 7, 6, 5, 4, 3, 2, 1), InitVector_RC[4]);
|
||||
tmp7[1] = ROUND_ELT(sharedMemory, tmp6, 1, 0, 7, 6, 5, 4, 3, 2);
|
||||
tmp7[2] = ROUND_ELT(sharedMemory, tmp6, 2, 1, 0, 7, 6, 5, 4, 3);
|
||||
tmp7[3] = ROUND_ELT(sharedMemory, tmp6, 3, 2, 1, 0, 7, 6, 5, 4);
|
||||
tmp7[4] = ROUND_ELT(sharedMemory, tmp6, 4, 3, 2, 1, 0, 7, 6, 5);
|
||||
tmp7[5] = ROUND_ELT(sharedMemory, tmp6, 5, 4, 3, 2, 1, 0, 7, 6);
|
||||
tmp7[6] = ROUND_ELT(sharedMemory, tmp6, 6, 5, 4, 3, 2, 1, 0, 7);
|
||||
tmp7[7] = ROUND_ELT(sharedMemory, tmp6, 7, 6, 5, 4, 3, 2, 1, 0);
|
||||
|
||||
d_tmp[threadIdx.x+32]=tmp7[threadIdx.x];
|
||||
|
||||
uint64_t tmp8[8];
|
||||
tmp8[0] = xor1(ROUND_ELT(sharedMemory, tmp7, 0, 7, 6, 5, 4, 3, 2, 1), InitVector_RC[5]);
|
||||
tmp8[1] = ROUND_ELT(sharedMemory, tmp7, 1, 0, 7, 6, 5, 4, 3, 2);
|
||||
tmp8[2] = ROUND_ELT(sharedMemory, tmp7, 2, 1, 0, 7, 6, 5, 4, 3);
|
||||
tmp8[3] = ROUND_ELT(sharedMemory, tmp7, 3, 2, 1, 0, 7, 6, 5, 4);
|
||||
tmp8[4] = ROUND_ELT(sharedMemory, tmp7, 4, 3, 2, 1, 0, 7, 6, 5);
|
||||
tmp8[5] = ROUND_ELT(sharedMemory, tmp7, 5, 4, 3, 2, 1, 0, 7, 6);
|
||||
tmp8[6] = ROUND_ELT(sharedMemory, tmp7, 6, 5, 4, 3, 2, 1, 0, 7);
|
||||
tmp8[7] = ROUND_ELT(sharedMemory, tmp7, 7, 6, 5, 4, 3, 2, 1, 0);
|
||||
|
||||
d_tmp[threadIdx.x+40]=tmp8[threadIdx.x];
|
||||
|
||||
uint64_t tmp9[8];
|
||||
tmp9[0] = xor1(ROUND_ELT(sharedMemory, tmp8, 0, 7, 6, 5, 4, 3, 2, 1), InitVector_RC[6]);
|
||||
tmp9[1] = ROUND_ELT(sharedMemory, tmp8, 1, 0, 7, 6, 5, 4, 3, 2);
|
||||
tmp9[2] = ROUND_ELT(sharedMemory, tmp8, 2, 1, 0, 7, 6, 5, 4, 3);
|
||||
tmp9[3] = ROUND_ELT(sharedMemory, tmp8, 3, 2, 1, 0, 7, 6, 5, 4);
|
||||
tmp9[4] = ROUND_ELT(sharedMemory, tmp8, 4, 3, 2, 1, 0, 7, 6, 5);
|
||||
tmp9[5] = ROUND_ELT(sharedMemory, tmp8, 5, 4, 3, 2, 1, 0, 7, 6);
|
||||
tmp9[6] = ROUND_ELT(sharedMemory, tmp8, 6, 5, 4, 3, 2, 1, 0, 7);
|
||||
tmp9[7] = ROUND_ELT(sharedMemory, tmp8, 7, 6, 5, 4, 3, 2, 1, 0);
|
||||
|
||||
d_tmp[threadIdx.x+48]=tmp9[threadIdx.x];
|
||||
|
||||
uint64_t tmp10[8];
|
||||
tmp10[0] = xor1(ROUND_ELT(sharedMemory, tmp9, 0, 7, 6, 5, 4, 3, 2, 1), InitVector_RC[7]);
|
||||
tmp10[1] = ROUND_ELT(sharedMemory, tmp9, 1, 0, 7, 6, 5, 4, 3, 2);
|
||||
tmp10[2] = ROUND_ELT(sharedMemory, tmp9, 2, 1, 0, 7, 6, 5, 4, 3);
|
||||
tmp10[3] = ROUND_ELT(sharedMemory, tmp9, 3, 2, 1, 0, 7, 6, 5, 4);
|
||||
tmp10[4] = ROUND_ELT(sharedMemory, tmp9, 4, 3, 2, 1, 0, 7, 6, 5);
|
||||
tmp10[5] = ROUND_ELT(sharedMemory, tmp9, 5, 4, 3, 2, 1, 0, 7, 6);
|
||||
tmp10[6] = ROUND_ELT(sharedMemory, tmp9, 6, 5, 4, 3, 2, 1, 0, 7);
|
||||
tmp10[7] = ROUND_ELT(sharedMemory, tmp9, 7, 6, 5, 4, 3, 2, 1, 0);
|
||||
|
||||
|
||||
d_tmp[threadIdx.x+56]=tmp10[threadIdx.x];
|
||||
|
||||
uint64_t tmp11[8];
|
||||
tmp11[0] = xor1(ROUND_ELT(sharedMemory, tmp10, 0, 7, 6, 5, 4, 3, 2, 1), InitVector_RC[8]);
|
||||
tmp11[1] = ROUND_ELT(sharedMemory, tmp10, 1, 0, 7, 6, 5, 4, 3, 2);
|
||||
tmp11[2] = ROUND_ELT(sharedMemory, tmp10, 2, 1, 0, 7, 6, 5, 4, 3);
|
||||
tmp11[3] = ROUND_ELT(sharedMemory, tmp10, 3, 2, 1, 0, 7, 6, 5, 4);
|
||||
tmp11[4] = ROUND_ELT(sharedMemory, tmp10, 4, 3, 2, 1, 0, 7, 6, 5);
|
||||
tmp11[5] = ROUND_ELT(sharedMemory, tmp10, 5, 4, 3, 2, 1, 0, 7, 6);
|
||||
tmp11[6] = ROUND_ELT(sharedMemory, tmp10, 6, 5, 4, 3, 2, 1, 0, 7);
|
||||
tmp11[7] = ROUND_ELT(sharedMemory, tmp10, 7, 6, 5, 4, 3, 2, 1, 0);
|
||||
|
||||
d_tmp[threadIdx.x+64]=tmp11[threadIdx.x];
|
||||
|
||||
if(threadIdx.x==1){
|
||||
tmp[0]=ROUND_ELT(sharedMemory,tmp11, 3, 2, 1, 0, 7, 6, 5, 4);
|
||||
tmp[1]=ROUND_ELT(sharedMemory,tmp11, 5, 4, 3, 2, 1, 0, 7, 6);
|
||||
tmp[4] = xor3(tmp[0],tmp[1],atLastCalc);
|
||||
d_xtra[threadIdx.x]=tmp[4];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
__global__ __launch_bounds__(threadsPerBlock,2)
|
||||
void whirlpoolx_gpu_hash(uint32_t threads, uint32_t startNounce, uint32_t *resNounce)
|
||||
{
|
||||
__shared__ uint64_t sharedMemory[2048];
|
||||
|
||||
whirlpoolx_getShared(sharedMemory);
|
||||
|
||||
uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x);
|
||||
if (thread < threads)
|
||||
{
|
||||
uint64_t n[8];
|
||||
uint64_t tmp[8];
|
||||
uint32_t nounce = startNounce + thread;
|
||||
|
||||
n[1] = xor1(REPLACE_HIDWORD(c_PaddedMessage80[9], cuda_swab32(nounce)),c_xtra[0]);
|
||||
|
||||
uint32_t* n32 = (uint32_t*)&n[0];
|
||||
n[0]=sharedMemory[__byte_perm(n32[3], 0, 0x4443) + 1792];
|
||||
n[5]=sharedMemory[__byte_perm(n32[3], 0, 0x4440) + 1024];
|
||||
n[6]=sharedMemory[__byte_perm(n32[3], 0, 0x4441) + 1280];
|
||||
n[7]=sharedMemory[__byte_perm(n32[3], 0, 0x4442) + 1536];
|
||||
n[0]=xor1(c_tmp[0],n[0]);
|
||||
n[1]=c_tmp[1];
|
||||
n[2]=c_tmp[2];
|
||||
n[3]=c_tmp[3];
|
||||
n[4]=c_tmp[4];
|
||||
n[5]=xor1(c_tmp[5],n[5]);
|
||||
n[6]=xor1(c_tmp[6],n[6]);
|
||||
n[7]=xor1(c_tmp[7],n[7]);
|
||||
|
||||
tmp[0]=xor3(sharedMemory[__byte_perm(n32[10],0,0x4443)+768],sharedMemory[__byte_perm(n32[12],0,0x4442)+512],sharedMemory[__byte_perm(n32[14],0,0x4441)+256]);
|
||||
tmp[1]=xor3(sharedMemory[__byte_perm(n32[11],0,0x4440)+1024],sharedMemory[__byte_perm(n32[12],0,0x4443)+768],sharedMemory[__byte_perm(n32[14],0,0x4442)+512]);
|
||||
tmp[2]=xor3(sharedMemory[__byte_perm(n32[11],0,0x4441)+1280],sharedMemory[__byte_perm(n32[13],0,0x4440)+1024],sharedMemory[__byte_perm(n32[14],0,0x4443)+768]);
|
||||
tmp[3]=xor3(sharedMemory[__byte_perm(n32[11],0,0x4442)+1536],sharedMemory[__byte_perm(n32[13],0,0x4441)+1280],sharedMemory[__byte_perm(n32[15],0,0x4440)+1024]);
|
||||
tmp[4]=xor3(sharedMemory[__byte_perm(n32[11],0,0x4443)+1792],sharedMemory[__byte_perm(n32[13],0,0x4442)+1536],sharedMemory[__byte_perm(n32[15],0,0x4441)+1280]);
|
||||
tmp[5]=xor3(sharedMemory[__byte_perm(n32[10],0,0x4440)],sharedMemory[__byte_perm(n32[13],0,0x4443)+1792],sharedMemory[__byte_perm(n32[15],0,0x4442)+1536]);
|
||||
tmp[6]=xor3(sharedMemory[__byte_perm(n32[12],0,0x4440)],sharedMemory[__byte_perm(n32[10],0,0x4441)+256],sharedMemory[__byte_perm(n32[15],0,0x4443)+1792]);
|
||||
tmp[7]=xor3(sharedMemory[__byte_perm(n32[14],0,0x4440)],sharedMemory[__byte_perm(n32[12],0,0x4441)+256],sharedMemory[__byte_perm(n32[10],0,0x4442)+ 512]);
|
||||
|
||||
tmp[0]=xor3(sharedMemory[__byte_perm(n32[ 0], 0, 0x4440)],tmp[0],c_tmp[0+16]);
|
||||
tmp[1]=xor3(sharedMemory[__byte_perm(n32[ 0], 0, 0x4441) + 256],tmp[1],c_tmp[1+16]);
|
||||
tmp[2]=xor3(sharedMemory[__byte_perm(n32[ 0], 0, 0x4442) + 512],tmp[2],c_tmp[2+16]);
|
||||
tmp[3]=xor3(sharedMemory[__byte_perm(n32[ 0], 0, 0x4443) + 768],tmp[3],c_tmp[3+16]);
|
||||
tmp[4]=xor3(sharedMemory[__byte_perm(n32[ 1], 0, 0x4440) + 1024],tmp[4],c_tmp[4+16]);
|
||||
tmp[5]=xor3(sharedMemory[__byte_perm(n32[ 1], 0, 0x4441) + 1280],tmp[5],c_tmp[5+16]);
|
||||
tmp[6]=xor3(sharedMemory[__byte_perm(n32[ 1], 0, 0x4442) + 1536],tmp[6],c_tmp[6+16]);
|
||||
tmp[7]=xor3(sharedMemory[__byte_perm(n32[ 1], 0, 0x4443) + 1792],tmp[7],c_tmp[7+16]);
|
||||
|
||||
n[0]=tmp[0];
|
||||
n[1]=tmp[1];
|
||||
n[2]=tmp[2];
|
||||
n[3]=tmp[3];
|
||||
n[4]=tmp[4];
|
||||
n[5]=tmp[5];
|
||||
n[6]=tmp[6];
|
||||
n[7]=tmp[7];
|
||||
|
||||
tmp[0] = xor1(ROUND_ELT(sharedMemory, n, 0, 7, 6, 5, 4, 3, 2, 1), c_tmp[0+8]);
|
||||
tmp[1] = xor1(ROUND_ELT(sharedMemory, n, 1, 0, 7, 6, 5, 4, 3, 2), c_tmp[1+8]);
|
||||
tmp[2] = xor1(ROUND_ELT(sharedMemory, n, 2, 1, 0, 7, 6, 5, 4, 3), c_tmp[2+8]);
|
||||
tmp[3] = xor1(ROUND_ELT(sharedMemory, n, 3, 2, 1, 0, 7, 6, 5, 4), c_tmp[3+8]);
|
||||
tmp[4] = xor1(ROUND_ELT(sharedMemory, n, 4, 3, 2, 1, 0, 7, 6, 5), c_tmp[4+8]);
|
||||
tmp[5] = xor1(ROUND_ELT(sharedMemory, n, 5, 4, 3, 2, 1, 0, 7, 6), c_tmp[5+8]);
|
||||
tmp[6] = xor1(ROUND_ELT(sharedMemory, n, 6, 5, 4, 3, 2, 1, 0, 7), c_tmp[6+8]);
|
||||
tmp[7] = xor1(ROUND_ELT(sharedMemory, n, 7, 6, 5, 4, 3, 2, 1, 0), c_tmp[7+8]);
|
||||
|
||||
n[0] = xor1(ROUND_ELT(sharedMemory, tmp, 0, 7, 6, 5, 4, 3, 2, 1), c_tmp[0+24]);
|
||||
n[1] = xor1(ROUND_ELT(sharedMemory, tmp, 1, 0, 7, 6, 5, 4, 3, 2), c_tmp[1+24]);
|
||||
n[2] = xor1(ROUND_ELT(sharedMemory, tmp, 2, 1, 0, 7, 6, 5, 4, 3), c_tmp[2+24]);
|
||||
n[3] = xor1(ROUND_ELT(sharedMemory, tmp, 3, 2, 1, 0, 7, 6, 5, 4), c_tmp[3+24]);
|
||||
n[4] = xor1(ROUND_ELT(sharedMemory, tmp, 4, 3, 2, 1, 0, 7, 6, 5), c_tmp[4+24]);
|
||||
n[5] = xor1(ROUND_ELT(sharedMemory, tmp, 5, 4, 3, 2, 1, 0, 7, 6), c_tmp[5+24]);
|
||||
n[6] = xor1(ROUND_ELT(sharedMemory, tmp, 6, 5, 4, 3, 2, 1, 0, 7), c_tmp[6+24]);
|
||||
n[7] = xor1(ROUND_ELT(sharedMemory, tmp, 7, 6, 5, 4, 3, 2, 1, 0), c_tmp[7+24]);
|
||||
|
||||
tmp[0] = xor1(ROUND_ELT(sharedMemory, n, 0, 7, 6, 5, 4, 3, 2, 1), c_tmp[0+32]);
|
||||
tmp[1] = xor1(ROUND_ELT(sharedMemory, n, 1, 0, 7, 6, 5, 4, 3, 2), c_tmp[1+32]);
|
||||
tmp[2] = xor1(ROUND_ELT(sharedMemory, n, 2, 1, 0, 7, 6, 5, 4, 3), c_tmp[2+32]);
|
||||
tmp[3] = xor1(ROUND_ELT(sharedMemory, n, 3, 2, 1, 0, 7, 6, 5, 4), c_tmp[3+32]);
|
||||
tmp[4] = xor1(ROUND_ELT(sharedMemory, n, 4, 3, 2, 1, 0, 7, 6, 5), c_tmp[4+32]);
|
||||
tmp[5] = xor1(ROUND_ELT(sharedMemory, n, 5, 4, 3, 2, 1, 0, 7, 6), c_tmp[5+32]);
|
||||
tmp[6] = xor1(ROUND_ELT(sharedMemory, n, 6, 5, 4, 3, 2, 1, 0, 7), c_tmp[6+32]);
|
||||
tmp[7] = xor1(ROUND_ELT(sharedMemory, n, 7, 6, 5, 4, 3, 2, 1, 0), c_tmp[7+32]);
|
||||
|
||||
n[0] = xor1(ROUND_ELT(sharedMemory, tmp, 0, 7, 6, 5, 4, 3, 2, 1), c_tmp[0+40]);
|
||||
n[1] = xor1(ROUND_ELT(sharedMemory, tmp, 1, 0, 7, 6, 5, 4, 3, 2), c_tmp[1+40]);
|
||||
n[2] = xor1(ROUND_ELT(sharedMemory, tmp, 2, 1, 0, 7, 6, 5, 4, 3), c_tmp[2+40]);
|
||||
n[3] = xor1(ROUND_ELT(sharedMemory, tmp, 3, 2, 1, 0, 7, 6, 5, 4), c_tmp[3+40]);
|
||||
n[4] = xor1(ROUND_ELT(sharedMemory, tmp, 4, 3, 2, 1, 0, 7, 6, 5), c_tmp[4+40]);
|
||||
n[5] = xor1(ROUND_ELT(sharedMemory, tmp, 5, 4, 3, 2, 1, 0, 7, 6), c_tmp[5+40]);
|
||||
n[6] = xor1(ROUND_ELT(sharedMemory, tmp, 6, 5, 4, 3, 2, 1, 0, 7), c_tmp[6+40]);
|
||||
n[7] = xor1(ROUND_ELT(sharedMemory, tmp, 7, 6, 5, 4, 3, 2, 1, 0), c_tmp[7+40]);
|
||||
|
||||
tmp[0] = xor1(ROUND_ELT(sharedMemory, n, 0, 7, 6, 5, 4, 3, 2, 1), c_tmp[0+48]);
|
||||
tmp[1] = xor1(ROUND_ELT(sharedMemory, n, 1, 0, 7, 6, 5, 4, 3, 2), c_tmp[1+48]);
|
||||
tmp[2] = xor1(ROUND_ELT(sharedMemory, n, 2, 1, 0, 7, 6, 5, 4, 3), c_tmp[2+48]);
|
||||
tmp[3] = xor1(ROUND_ELT(sharedMemory, n, 3, 2, 1, 0, 7, 6, 5, 4), c_tmp[3+48]);
|
||||
tmp[4] = xor1(ROUND_ELT(sharedMemory, n, 4, 3, 2, 1, 0, 7, 6, 5), c_tmp[4+48]);
|
||||
tmp[5] = xor1(ROUND_ELT(sharedMemory, n, 5, 4, 3, 2, 1, 0, 7, 6), c_tmp[5+48]);
|
||||
tmp[6] = xor1(ROUND_ELT(sharedMemory, n, 6, 5, 4, 3, 2, 1, 0, 7), c_tmp[6+48]);
|
||||
tmp[7] = xor1(ROUND_ELT(sharedMemory, n, 7, 6, 5, 4, 3, 2, 1, 0), c_tmp[7+48]);
|
||||
|
||||
n[0] = xor1(ROUND_ELT(sharedMemory, tmp, 0, 7, 6, 5, 4, 3, 2, 1), c_tmp[0+56]);
|
||||
n[1] = xor1(ROUND_ELT(sharedMemory, tmp, 1, 0, 7, 6, 5, 4, 3, 2), c_tmp[1+56]);
|
||||
n[2] = xor1(ROUND_ELT(sharedMemory, tmp, 2, 1, 0, 7, 6, 5, 4, 3), c_tmp[2+56]);
|
||||
n[3] = xor1(ROUND_ELT(sharedMemory, tmp, 3, 2, 1, 0, 7, 6, 5, 4), c_tmp[3+56]);
|
||||
n[4] = xor1(ROUND_ELT(sharedMemory, tmp, 4, 3, 2, 1, 0, 7, 6, 5), c_tmp[4+56]);
|
||||
n[5] = xor1(ROUND_ELT(sharedMemory, tmp, 5, 4, 3, 2, 1, 0, 7, 6), c_tmp[5+56]);
|
||||
n[6] = xor1(ROUND_ELT(sharedMemory, tmp, 6, 5, 4, 3, 2, 1, 0, 7), c_tmp[6+56]);
|
||||
n[7] = xor1(ROUND_ELT(sharedMemory, tmp, 7, 6, 5, 4, 3, 2, 1, 0), c_tmp[7+56]);
|
||||
|
||||
tmp[0] = xor1(ROUND_ELT(sharedMemory, n, 0, 7, 6, 5, 4, 3, 2, 1), c_tmp[0+64]);
|
||||
tmp[1] = xor1(ROUND_ELT(sharedMemory, n, 1, 0, 7, 6, 5, 4, 3, 2), c_tmp[1+64]);
|
||||
tmp[2] = xor1(ROUND_ELT(sharedMemory, n, 2, 1, 0, 7, 6, 5, 4, 3), c_tmp[2+64]);
|
||||
tmp[3] = xor1(ROUND_ELT(sharedMemory, n, 3, 2, 1, 0, 7, 6, 5, 4), c_tmp[3+64]);
|
||||
tmp[4] = xor1(ROUND_ELT(sharedMemory, n, 4, 3, 2, 1, 0, 7, 6, 5), c_tmp[4+64]);
|
||||
tmp[5] = xor1(ROUND_ELT(sharedMemory, n, 5, 4, 3, 2, 1, 0, 7, 6), c_tmp[5+64]);
|
||||
tmp[6] = xor1(ROUND_ELT(sharedMemory, n, 6, 5, 4, 3, 2, 1, 0, 7), c_tmp[6+64]);
|
||||
tmp[7] = xor1(ROUND_ELT(sharedMemory, n, 7, 6, 5, 4, 3, 2, 1, 0), c_tmp[7+64]);
|
||||
|
||||
if (xor3(c_xtra[1], ROUND_ELT(sharedMemory, tmp, 3, 2, 1, 0, 7, 6, 5, 4), ROUND_ELT(sharedMemory, tmp, 5, 4, 3, 2, 1, 0, 7, 6)) <= pTarget[3]) {
|
||||
atomicMin(&resNounce[0], nounce);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
__host__
|
||||
extern void whirlpoolx_cpu_init(int thr_id, uint32_t threads)
|
||||
{
|
||||
cudaMemcpyToSymbol(InitVector_RC, plain_RC, sizeof(plain_RC), 0, cudaMemcpyHostToDevice);
|
||||
cudaMemcpyToSymbol(mixTob0Tox, plain_T0, sizeof(plain_T0), 0, cudaMemcpyHostToDevice);
|
||||
cudaMalloc(&d_WXNonce[thr_id], sizeof(uint32_t));
|
||||
cudaMallocHost(&h_wxnounce[thr_id], sizeof(uint32_t));
|
||||
cudaMalloc(&d_xtra[thr_id], 8 * sizeof(uint64_t));
|
||||
CUDA_SAFE_CALL(cudaMalloc(&d_tmp[thr_id], 8 * 9 * sizeof(uint64_t))); // d_tmp[threadIdx.x+64] (7+64)
|
||||
}
|
||||
|
||||
__host__
|
||||
void whirlpoolx_setBlock_80(void *pdata, const void *ptarget)
|
||||
{
|
||||
uint64_t PaddedMessage[16];
|
||||
memcpy(PaddedMessage, pdata, 80);
|
||||
memset((uint8_t*)&PaddedMessage+80, 0, 48);
|
||||
((uint8_t*)PaddedMessage)[80] = 0x80; /* ending */
|
||||
cudaMemcpyToSymbol(pTarget, ptarget, 4*sizeof(uint64_t), 0, cudaMemcpyHostToDevice);
|
||||
CUDA_SAFE_CALL(cudaMemcpyToSymbol(c_PaddedMessage80, PaddedMessage, 16 * sizeof(uint64_t), 0, cudaMemcpyHostToDevice));
|
||||
}
|
||||
|
||||
__host__
|
||||
void whirlpoolx_precompute(int thr_id)
|
||||
{
|
||||
dim3 grid(1);
|
||||
dim3 block(256);
|
||||
|
||||
whirlpoolx_gpu_precompute <<<grid, block>>>(8, d_xtra[thr_id], d_tmp[thr_id]);
|
||||
cudaThreadSynchronize();
|
||||
|
||||
cudaMemcpyToSymbol(c_xtra, d_xtra[thr_id], 8 * sizeof(uint64_t), 0, cudaMemcpyDeviceToDevice);
|
||||
CUDA_SAFE_CALL(cudaMemcpyToSymbol(c_tmp, d_tmp[thr_id], 8 * 9 * sizeof(uint64_t), 0, cudaMemcpyDeviceToDevice));
|
||||
}
|
||||
|
||||
__host__
|
||||
uint32_t whirlpoolx_cpu_hash(int thr_id, uint32_t threads, uint32_t startNounce)
|
||||
{
|
||||
dim3 grid((threads + threadsPerBlock-1) / threadsPerBlock);
|
||||
dim3 block(threadsPerBlock);
|
||||
|
||||
cudaMemset(d_WXNonce[thr_id], 0xff, sizeof(uint32_t));
|
||||
|
||||
whirlpoolx_gpu_hash<<<grid, block>>>(threads, startNounce, d_WXNonce[thr_id]);
|
||||
cudaThreadSynchronize();
|
||||
|
||||
cudaMemcpy(h_wxnounce[thr_id], d_WXNonce[thr_id], sizeof(uint32_t), cudaMemcpyDeviceToHost);
|
||||
|
||||
return *(h_wxnounce[thr_id]);
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* whirlpool routine (djm)
|
||||
* whirlpoolx routine (provos alexis, tpruvot)
|
||||
*/
|
||||
extern "C" {
|
||||
#include "sph/sph_whirlpool.h"
|
||||
}
|
||||
|
||||
#include "miner.h"
|
||||
#include "cuda_helper.h"
|
||||
|
||||
static uint32_t *d_hash[MAX_GPUS];
|
||||
|
||||
extern void whirlpoolx_cpu_init(int thr_id, uint32_t threads);
|
||||
extern void whirlpoolx_setBlock_80(void *pdata, const void *ptarget);
|
||||
extern uint32_t whirlpoolx_cpu_hash(int thr_id, uint32_t threads, uint32_t startNounce);
|
||||
extern void whirlpoolx_precompute(int thr_id);
|
||||
|
||||
// CPU Hash function
|
||||
extern "C" void whirlxHash(void *state, const void *input)
|
||||
{
|
||||
sph_whirlpool_context ctx_whirlpool;
|
||||
|
||||
unsigned char hash[64];
|
||||
unsigned char hash_xored[32];
|
||||
|
||||
sph_whirlpool_init(&ctx_whirlpool);
|
||||
sph_whirlpool(&ctx_whirlpool, input, 80);
|
||||
sph_whirlpool_close(&ctx_whirlpool, hash);
|
||||
|
||||
// compress the 48 first bytes of the hash to 32
|
||||
for (int i = 0; i < 32; i++) {
|
||||
hash_xored[i] = hash[i] ^ hash[i + 16];
|
||||
}
|
||||
memcpy(state, hash_xored, 32);
|
||||
}
|
||||
|
||||
static bool init[MAX_GPUS] = { 0 };
|
||||
|
||||
extern "C" int scanhash_whirlpoolx(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
|
||||
uint32_t max_nonce, unsigned long *hashes_done)
|
||||
{
|
||||
const uint32_t first_nonce = pdata[19];
|
||||
uint32_t endiandata[20];
|
||||
int intensity = is_windows() ? 20 : 22;
|
||||
uint32_t throughput = device_intensity(thr_id, __func__, 1U << intensity);
|
||||
throughput = min(throughput, max_nonce - first_nonce);
|
||||
|
||||
if (opt_benchmark)
|
||||
((uint32_t*)ptarget)[7] = 0x0000ff;
|
||||
|
||||
if (!init[thr_id]) {
|
||||
cudaSetDevice(device_map[thr_id]);
|
||||
|
||||
CUDA_CALL_OR_RET_X(cudaMalloc(&d_hash[thr_id], 64 * throughput), 0);
|
||||
|
||||
whirlpoolx_cpu_init(thr_id, throughput);
|
||||
|
||||
init[thr_id] = true;
|
||||
}
|
||||
|
||||
for (int k=0; k < 20; k++) {
|
||||
be32enc(&endiandata[k], pdata[k]);
|
||||
}
|
||||
|
||||
whirlpoolx_setBlock_80((void*)endiandata, ptarget);
|
||||
whirlpoolx_precompute(thr_id);
|
||||
do {
|
||||
uint32_t foundNonce = whirlpoolx_cpu_hash(thr_id, throughput, pdata[19]);
|
||||
if (foundNonce != UINT32_MAX)
|
||||
{
|
||||
const uint32_t Htarg = ptarget[7];
|
||||
uint32_t vhash64[8];
|
||||
be32enc(&endiandata[19], foundNonce);
|
||||
whirlxHash(vhash64, endiandata);
|
||||
|
||||
if (vhash64[7] <= Htarg && fulltest(vhash64, ptarget)) {
|
||||
*hashes_done = pdata[19] - first_nonce + throughput;
|
||||
pdata[19] = foundNonce;
|
||||
return 1;
|
||||
} else {
|
||||
applog(LOG_WARNING, "GPU #%d: result for %08x does not validate on CPU!", device_map[thr_id], foundNonce);
|
||||
}
|
||||
}
|
||||
|
||||
pdata[19] += throughput;
|
||||
|
||||
if (((uint64_t)pdata[19]+throughput) >= max_nonce) {
|
||||
break;
|
||||
}
|
||||
|
||||
} while (!work_restart[thr_id].restart);
|
||||
|
||||
*(hashes_done) = pdata[19] - first_nonce + 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user