Skip to content

Commit c120eca

Browse files
committed
handle the new tribus algo
Signed-off-by: Tanguy Pruvot <[email protected]>
1 parent 1473a8f commit c120eca

10 files changed

+188
-1
lines changed

Diff for: Makefile.am

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ ccminer_SOURCES = elist.h miner.h compat.h \
6565
sph/ripemd.c sph/sph_sha2.c \
6666
lbry/lbry.cu lbry/cuda_sha256_lbry.cu lbry/cuda_sha512_lbry.cu lbry/cuda_lbry_merged.cu \
6767
qubit/qubit.cu qubit/qubit_luffa512.cu qubit/deep.cu qubit/luffa.cu \
68+
tribus.cu \
6869
x11/x11.cu x11/fresh.cu x11/cuda_x11_luffa512.cu x11/cuda_x11_cubehash512.cu \
6970
x11/cuda_x11_shavite512.cu x11/cuda_x11_simd512.cu x11/cuda_x11_echo.cu \
7071
x11/cuda_x11_luffa512_Cubehash.cu x11/x11evo.cu x11/timetravel.cu x11/bitcore.cu \

Diff for: README.txt

+2
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ its command line interface and options.
117117
skein use to mine Skeincoin
118118
skein2 use to mine Woodcoin
119119
timetravel use to mine MachineCoin
120+
tribus use to mine Denarius
120121
x11evo use to mine Revolver
121122
x11 use to mine DarkCoin
122123
x14 use to mine X14Coin
@@ -282,6 +283,7 @@ features.
282283
v2.1 (unfinished)
283284
Interface equihash algo with djeZo solver (from nheqminer 0.5c)
284285
New api parameters (and multicast announces for local networks)
286+
New tribus algo
285287

286288
May. 14th 2017 v2.0
287289
Handle cryptonight, wildkeccak and cryptonight-lite

Diff for: algos.h

+2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ enum sha_algos {
4747
ALGO_SKEIN2,
4848
ALGO_S3,
4949
ALGO_TIMETRAVEL,
50+
ALGO_TRIBUS,
5051
ALGO_BITCORE,
5152
ALGO_X11EVO,
5253
ALGO_X11,
@@ -110,6 +111,7 @@ static const char *algo_names[] = {
110111
"skein2",
111112
"s3",
112113
"timetravel",
114+
"tribus",
113115
"bitcore",
114116
"x11evo",
115117
"x11",

Diff for: bench.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ void algo_free_all(int thr_id)
100100
free_scrypt(thr_id);
101101
free_scrypt_jane(thr_id);
102102
free_timetravel(thr_id);
103+
free_tribus(thr_id);
103104
free_bitcore(thr_id);
104105
}
105106

Diff for: ccminer.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ Options:\n\
277277
skein2 Double Skein (Woodcoin)\n\
278278
s3 S3 (1Coin)\n\
279279
timetravel Machinecoin permuted x8\n\
280+
tribus Denerius\n\
280281
vanilla Blake256-8 (VNL)\n\
281282
veltor Thorsriddle streebog\n\
282283
whirlcoin Old Whirlcoin (Whirlpool algo)\n\
@@ -2197,6 +2198,7 @@ static void *miner_thread(void *userdata)
21972198
case ALGO_SIA:
21982199
case ALGO_SKEIN:
21992200
case ALGO_SKEIN2:
2201+
case ALGO_TRIBUS:
22002202
minmax = 0x1000000;
22012203
break;
22022204
case ALGO_C11:
@@ -2433,6 +2435,9 @@ static void *miner_thread(void *userdata)
24332435
case ALGO_TIMETRAVEL:
24342436
rc = scanhash_timetravel(thr_id, &work, max_nonce, &hashes_done);
24352437
break;
2438+
case ALGO_TRIBUS:
2439+
rc = scanhash_tribus(thr_id, &work, max_nonce, &hashes_done);
2440+
break;
24362441
case ALGO_BITCORE:
24372442
rc = scanhash_bitcore(thr_id, &work, max_nonce, &hashes_done);
24382443
break;

Diff for: ccminer.vcxproj

+2-1
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,7 @@
531531
<CudaCompile Include="cuda_skeincoin.cu">
532532
<MaxRegCount>48</MaxRegCount>
533533
</CudaCompile>
534+
<CudaCompile Include="tribus.cu" />
534535
<ClInclude Include="x11\cuda_x11_aes.cuh" />
535536
<CudaCompile Include="x11\cuda_x11_cubehash512.cu" />
536537
<CudaCompile Include="x11\cuda_x11_echo.cu">
@@ -598,4 +599,4 @@
598599
<Target Name="AfterClean">
599600
<Delete Files="@(FilesToCopy->'$(OutDir)%(Filename)%(Extension)')" TreatErrorsAsWarnings="true" />
600601
</Target>
601-
</Project>
602+
</Project>

Diff for: ccminer.vcxproj.filters

+3
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,9 @@
754754
<CudaCompile Include="pentablake.cu">
755755
<Filter>Source Files\CUDA</Filter>
756756
</CudaCompile>
757+
<CudaCompile Include="tribus.cu">
758+
<Filter>Source Files\CUDA</Filter>
759+
</CudaCompile>
757760
<CudaCompile Include="x11\sib.cu">
758761
<Filter>Source Files\CUDA\x11</Filter>
759762
</CudaCompile>

Diff for: miner.h

+3
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ extern int scanhash_skeincoin(int thr_id, struct work* work, uint32_t max_nonce,
310310
extern int scanhash_skein2(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done);
311311
extern int scanhash_s3(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done);
312312
extern int scanhash_timetravel(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done);
313+
extern int scanhash_tribus(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done);
313314
extern int scanhash_bitcore(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done);
314315
extern int scanhash_vanilla(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done, int8_t blake_rounds);
315316
extern int scanhash_veltor(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done);
@@ -369,6 +370,7 @@ extern void free_skeincoin(int thr_id);
369370
extern void free_skein2(int thr_id);
370371
extern void free_s3(int thr_id);
371372
extern void free_timetravel(int thr_id);
373+
extern void free_tribus(int thr_id);
372374
extern void free_bitcore(int thr_id);
373375
extern void free_vanilla(int thr_id);
374376
extern void free_veltor(int thr_id);
@@ -909,6 +911,7 @@ void skein2hash(void *output, const void *input);
909911
void s3hash(void *output, const void *input);
910912
void timetravel_hash(void *output, const void *input);
911913
void bitcore_hash(void *output, const void *input);
914+
void tribus_hash(void *output, const void *input);
912915
void veltorhash(void *output, const void *input);
913916
void wcoinhash(void *state, const void *input);
914917
void whirlxHash(void *state, const void *input);

Diff for: tribus.cu

+166
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
/**
2+
* Tribus Algo for Denarius
3+
*
4+
* tpruvot@github 06 2017 - GPLv3
5+
*
6+
*/
7+
extern "C" {
8+
#include "sph/sph_jh.h"
9+
#include "sph/sph_keccak.h"
10+
#include "sph/sph_echo.h"
11+
}
12+
13+
#include "miner.h"
14+
#include "cuda_helper.h"
15+
#include "x11/cuda_x11.h"
16+
17+
void jh512_setBlock_80(int thr_id, uint32_t *endiandata);
18+
void jh512_cuda_hash_80(const int thr_id, const uint32_t threads, const uint32_t startNounce, uint32_t *d_hash);
19+
20+
static uint32_t *d_hash[MAX_GPUS];
21+
22+
23+
// cpu hash
24+
25+
extern "C" void tribus_hash(void *state, const void *input)
26+
{
27+
uint8_t _ALIGN(64) hash[64];
28+
29+
sph_jh512_context ctx_jh;
30+
sph_keccak512_context ctx_keccak;
31+
sph_echo512_context ctx_echo;
32+
33+
sph_jh512_init(&ctx_jh);
34+
sph_jh512(&ctx_jh, input, 80);
35+
sph_jh512_close(&ctx_jh, (void*) hash);
36+
37+
sph_keccak512_init(&ctx_keccak);
38+
sph_keccak512(&ctx_keccak, (const void*) hash, 64);
39+
sph_keccak512_close(&ctx_keccak, (void*) hash);
40+
41+
sph_echo512_init(&ctx_echo);
42+
sph_echo512(&ctx_echo, (const void*) hash, 64);
43+
sph_echo512_close(&ctx_echo, (void*) hash);
44+
45+
memcpy(state, hash, 32);
46+
}
47+
48+
static bool init[MAX_GPUS] = { 0 };
49+
50+
extern "C" int scanhash_tribus(int thr_id, struct work *work, uint32_t max_nonce, unsigned long *hashes_done)
51+
{
52+
uint32_t _ALIGN(64) endiandata[20];
53+
uint32_t *pdata = work->data;
54+
uint32_t *ptarget = work->target;
55+
const uint32_t first_nonce = pdata[19];
56+
57+
int8_t intensity = is_windows() ? 20 : 23;
58+
uint32_t throughput = cuda_default_throughput(thr_id, 1 << intensity);
59+
if (init[thr_id]) throughput = min(throughput, max_nonce - first_nonce);
60+
61+
if (opt_benchmark)
62+
((uint32_t*)ptarget)[7] = 0x00FF;
63+
64+
if (!init[thr_id])
65+
{
66+
cudaSetDevice(device_map[thr_id]);
67+
if (opt_cudaschedule == -1 && gpu_threads == 1) {
68+
cudaDeviceReset();
69+
// reduce cpu usage
70+
cudaSetDeviceFlags(cudaDeviceScheduleBlockingSync);
71+
CUDA_LOG_ERROR();
72+
}
73+
gpulog(LOG_INFO, thr_id, "Intensity set to %g, %u cuda threads", throughput2intensity(throughput), throughput);
74+
75+
quark_jh512_cpu_init(thr_id, throughput);
76+
quark_keccak512_cpu_init(thr_id, throughput);
77+
x11_echo512_cpu_init(thr_id, throughput);
78+
79+
// char[64] work space for hashes results
80+
CUDA_SAFE_CALL(cudaMalloc(&d_hash[thr_id], (size_t)64 * throughput));
81+
82+
cuda_check_cpu_init(thr_id, throughput);
83+
init[thr_id] = true;
84+
}
85+
86+
for (int k=0; k < 20; k++)
87+
be32enc(&endiandata[k], pdata[k]);
88+
89+
jh512_setBlock_80(thr_id, endiandata);
90+
cuda_check_cpu_setTarget(ptarget);
91+
92+
work->valid_nonces = 0;
93+
94+
do {
95+
int order = 1;
96+
97+
// Hash with CUDA
98+
jh512_cuda_hash_80(thr_id, throughput, pdata[19], d_hash[thr_id]);
99+
quark_keccak512_cpu_hash_64(thr_id, throughput, pdata[19], NULL, d_hash[thr_id], order++);
100+
x11_echo512_cpu_hash_64(thr_id, throughput, pdata[19], NULL, d_hash[thr_id], order++);
101+
102+
*hashes_done = pdata[19] - first_nonce + throughput;
103+
104+
work->nonces[0] = cuda_check_hash(thr_id, throughput, pdata[19], d_hash[thr_id]);
105+
if (work->nonces[0] != UINT32_MAX)
106+
{
107+
const uint32_t Htarg = ptarget[7];
108+
uint32_t _ALIGN(64) vhash[8];
109+
be32enc(&endiandata[19], work->nonces[0]);
110+
tribus_hash(vhash, endiandata);
111+
112+
if (vhash[7] <= Htarg && fulltest(vhash, ptarget)) {
113+
work->valid_nonces = 1;
114+
work_set_target_ratio(work, vhash);
115+
work->nonces[1] = cuda_check_hash_suppl(thr_id, throughput, pdata[19], d_hash[thr_id], 1);
116+
if (work->nonces[1] != 0) {
117+
be32enc(&endiandata[19], work->nonces[1]);
118+
tribus_hash(vhash, endiandata);
119+
bn_set_target_ratio(work, vhash, 1);
120+
work->valid_nonces++;
121+
pdata[19] = max(work->nonces[0], work->nonces[1]) + 1;
122+
} else {
123+
pdata[19] = work->nonces[0] + 1; // cursor
124+
}
125+
goto out;
126+
}
127+
else if (vhash[7] > Htarg) {
128+
gpu_increment_reject(thr_id);
129+
if (!opt_quiet)
130+
gpulog(LOG_WARNING, thr_id, "result for %08x does not validate on CPU!", work->nonces[0]);
131+
pdata[19] = work->nonces[0] + 1;
132+
continue;
133+
}
134+
}
135+
136+
if ((uint64_t) throughput + pdata[19] >= max_nonce) {
137+
pdata[19] = max_nonce;
138+
break;
139+
}
140+
141+
pdata[19] += throughput;
142+
143+
} while (!work_restart[thr_id].restart);
144+
145+
out:
146+
// *hashes_done = pdata[19] - first_nonce;
147+
148+
return work->valid_nonces;
149+
}
150+
151+
// ressources cleanup
152+
extern "C" void free_tribus(int thr_id)
153+
{
154+
if (!init[thr_id])
155+
return;
156+
157+
cudaThreadSynchronize();
158+
159+
cudaFree(d_hash[thr_id]);
160+
161+
quark_groestl512_cpu_free(thr_id);
162+
cuda_check_cpu_free(thr_id);
163+
init[thr_id] = false;
164+
165+
cudaDeviceSynchronize();
166+
}

Diff for: util.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -2279,6 +2279,9 @@ void print_hash_tests(void)
22792279
blake256hash(&hash[0], &buf[0], 8);
22802280
printpfx("vanilla", hash);
22812281

2282+
tribus_hash(&hash[0], &buf[0]);
2283+
printpfx("tribus", hash);
2284+
22822285
veltorhash(&hash[0], &buf[0]);
22832286
printpfx("veltor", hash);
22842287

0 commit comments

Comments
 (0)