Skip to content

Commit b22be6e

Browse files
authored
Merge pull request #265 from fancyIX/feature/#264
Feature/#264
2 parents d5daa58 + 1d10379 commit b22be6e

File tree

13 files changed

+2571
-46
lines changed

13 files changed

+2571
-46
lines changed

Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ sgminer_SOURCES += ocl/binary_kernel.c ocl/binary_kernel.h
5454
sgminer_SOURCES += kernel/*.cl
5555
sgminer_SOURCES += algorithm/scrypt.c algorithm/scrypt.h
5656
sgminer_SOURCES += algorithm/darkcoin.c algorithm/darkcoin.h
57+
sgminer_SOURCES += algorithm/chainox.c algorithm/chainox.h
5758
sgminer_SOURCES += algorithm/qubitcoin.c algorithm/qubitcoin.h
5859
sgminer_SOURCES += algorithm/quarkcoin.c algorithm/quarkcoin.h
5960
sgminer_SOURCES += algorithm/myriadcoin-groestl.c algorithm/myriadcoin-groestl.h

algorithm.c

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "algorithm/qubitcoin.h"
2121
#include "algorithm/sifcoin.h"
2222
#include "algorithm/darkcoin.h"
23+
#include "algorithm/chainox.h"
2324
#include "algorithm/myriadcoin-groestl.h"
2425
#include "algorithm/fuguecoin.h"
2526
#include "algorithm/groestlcoin.h"
@@ -75,6 +76,7 @@ const char *algorithm_type_str[] = {
7576
"NScrypt",
7677
"Pascal",
7778
"X11",
79+
"0X10",
7880
"X13",
7981
"X14",
8082
"X15",
@@ -715,6 +717,62 @@ static cl_int queue_darkcoin_mod_kernel(struct __clState *clState, struct _dev_b
715717
return status;
716718
}
717719

720+
static cl_int queue_chainox_kernel(struct __clState *clState, struct _dev_blk_ctx *blk, __maybe_unused cl_uint threads)
721+
{
722+
cl_kernel *kernel;
723+
unsigned int num;
724+
cl_ulong le_target;
725+
cl_int status = 0;
726+
727+
le_target = *(cl_ulong *)(blk->work->device_target + 24);
728+
flip80(clState->cldata, blk->work->data);
729+
status = clEnqueueWriteBuffer(clState->commandQueue, clState->CLbuffer0, true, 0, 80, clState->cldata, 0, NULL, NULL);
730+
731+
if (status != CL_SUCCESS) applog(LOG_ERR, "Error %d: write buffer failed.", status);
732+
// blake - search
733+
kernel = &clState->kernel;
734+
num = 0;
735+
CL_SET_ARG(clState->CLbuffer0);
736+
CL_SET_ARG(clState->padbuffer8);
737+
if (status != CL_SUCCESS) applog(LOG_ERR, "Error %d: search arg failed.", status);
738+
// skein - search1
739+
kernel = clState->extra_kernels;
740+
CL_SET_ARG_0(clState->padbuffer8);
741+
if (status != CL_SUCCESS) applog(LOG_ERR, "Error %d: search1 arg failed.", status);
742+
// bmw - search2
743+
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
744+
if (status != CL_SUCCESS) applog(LOG_ERR, "Error %d: search2 arg failed.", status);
745+
// groestl - search3
746+
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
747+
if (status != CL_SUCCESS) applog(LOG_ERR, "Error %d: search3 arg failed.", status);
748+
// jh - search4
749+
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
750+
if (status != CL_SUCCESS) applog(LOG_ERR, "Error %d: search4 arg failed.", status);
751+
// luffa - search5
752+
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
753+
if (status != CL_SUCCESS) applog(LOG_ERR, "Error %d: search5 arg failed.", status);
754+
// keccak - search6
755+
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
756+
if (status != CL_SUCCESS) applog(LOG_ERR, "Error %d: search6 arg failed.", status);
757+
// simd - search7
758+
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
759+
if (status != CL_SUCCESS) applog(LOG_ERR, "Error %d: search7 arg failed.", status);
760+
// shavite - search8
761+
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
762+
if (status != CL_SUCCESS) applog(LOG_ERR, "Error %d: search8 arg failed.", status);
763+
// cubehash - search9
764+
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
765+
if (status != CL_SUCCESS) applog(LOG_ERR, "Error %d: search9 arg failed.", status);
766+
// echo - search10
767+
num = 0;
768+
CL_NEXTKERNEL_SET_ARG(clState->padbuffer8);
769+
CL_SET_ARG(clState->outputBuffer);
770+
CL_SET_ARG(le_target);
771+
if (status != CL_SUCCESS) applog(LOG_ERR, "Error %d: search10 arg failed.", status);
772+
773+
return status;
774+
}
775+
718776
static cl_int queue_allium_kernel(struct __clState *clState, struct _dev_blk_ctx *blk, __maybe_unused cl_uint threads)
719777
{
720778
cl_kernel *kernel;
@@ -2563,6 +2621,8 @@ static algorithm_settings_t algos[] = {
25632621
{ "maxcoin", ALGO_KECCAK, "", 1, 256, 1, 4, 15, 0x0F, 0xFFFFULL, 0x000000ffUL, 0, 0, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, maxcoin_regenhash, NULL, NULL, queue_maxcoin_kernel, sha256, NULL },
25642622

25652623
{ "darkcoin-mod", ALGO_X11, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 10, 8 * 16 * 4194304, 0, darkcoin_regenhash, NULL, NULL, queue_darkcoin_mod_kernel, gen_hash, append_x11_compiler_options },
2624+
{ "chainox", ALGO_0X10, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 10, 8 * 16 * 4194304, 0, chainox_regenhash, NULL, NULL, queue_chainox_kernel, gen_hash, append_x11_compiler_options },
2625+
{ "chainox_navi", ALGO_0X10_NAVI, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 10, 8 * 16 * 4194304, 0, chainox_regenhash, NULL, NULL, queue_chainox_kernel, gen_hash, append_x11_compiler_options },
25662626

25672627
{ "sibcoin-mod", ALGO_X11, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 11, 2 * 16 * 4194304, 0, sibcoin_regenhash, NULL, NULL, queue_sibcoin_mod_kernel, gen_hash, append_x11_compiler_options },
25682628

@@ -2688,6 +2748,8 @@ static const char *lookup_algorithm_alias(const char *lookup_alias, uint8_t *nfa
26882748
ALGO_ALIAS_NF("adaptive-n-scrypt", "ckolivas", 11);
26892749
ALGO_ALIAS("x11mod", "darkcoin-mod");
26902750
ALGO_ALIAS("x11", "darkcoin-mod");
2751+
ALGO_ALIAS("0x10", "chainox");
2752+
ALGO_ALIAS("0x10_navi", "chainox_navi");
26912753
ALGO_ALIAS("x11-gost", "sibcoin-mod");
26922754
ALGO_ALIAS("x13mod", "marucoin-mod");
26932755
ALGO_ALIAS("x13", "marucoin-mod");

algorithm.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ typedef enum {
2222
ALGO_NSCRYPT,
2323
ALGO_PASCAL,
2424
ALGO_X11,
25+
ALGO_0X10,
26+
ALGO_0X10_NAVI,
2527
ALGO_X13,
2628
ALGO_X14,
2729
ALGO_X15,

algorithm/chainox.c

Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
/*-
2+
* Copyright 2009 Colin Percival, 2011 ArtForz
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions
7+
* are met:
8+
* 1. Redistributions of source code must retain the above copyright
9+
* notice, this list of conditions and the following disclaimer.
10+
* 2. Redistributions in binary form must reproduce the above copyright
11+
* notice, this list of conditions and the following disclaimer in the
12+
* documentation and/or other materials provided with the distribution.
13+
*
14+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17+
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23+
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24+
* SUCH DAMAGE.
25+
*
26+
* This file was originally written by Colin Percival as part of the Tarsnap
27+
* online backup system.
28+
*/
29+
30+
#include "config.h"
31+
#include "miner.h"
32+
33+
#include <stdlib.h>
34+
#include <stdint.h>
35+
#include <string.h>
36+
37+
38+
#include "sph/sph_blake.h"
39+
#include "sph/sph_bmw.h"
40+
#include "sph/sph_groestl.h"
41+
#include "sph/sph_jh.h"
42+
#include "sph/sph_keccak.h"
43+
#include "sph/sph_skein.h"
44+
#include "sph/sph_luffa.h"
45+
#include "sph/sph_cubehash.h"
46+
#include "sph/sph_shavite.h"
47+
#include "sph/sph_simd.h"
48+
#include "sph/sph_echo.h"
49+
50+
/* Move init out of loop, so init once externally, and then use one single memcpy with that bigger memory block */
51+
typedef struct {
52+
sph_blake512_context blake1;
53+
sph_bmw512_context bmw1;
54+
sph_groestl512_context groestl1;
55+
sph_skein512_context skein1;
56+
sph_jh512_context jh1;
57+
sph_keccak512_context keccak1;
58+
sph_luffa512_context luffa1;
59+
sph_cubehash512_context cubehash1;
60+
sph_shavite512_context shavite1;
61+
sph_simd512_context simd1;
62+
sph_echo512_context echo1;
63+
} Xhash_context_holder;
64+
65+
static Xhash_context_holder base_contexts;
66+
67+
68+
static void init_Xhash_contexts()
69+
{
70+
sph_blake512_init(&base_contexts.blake1);
71+
sph_skein512_init(&base_contexts.skein1);
72+
sph_bmw512_init(&base_contexts.bmw1);
73+
sph_groestl512_init(&base_contexts.groestl1);
74+
sph_jh512_init(&base_contexts.jh1);
75+
sph_luffa512_init(&base_contexts.luffa1);
76+
sph_keccak512_init(&base_contexts.keccak1);
77+
sph_cubehash512_init(&base_contexts.cubehash1);
78+
sph_simd512_init(&base_contexts.simd1);
79+
sph_shavite512_init(&base_contexts.shavite1);
80+
sph_echo512_init(&base_contexts.echo1);
81+
}
82+
83+
static void xhash(void *state, const void *input)
84+
{
85+
init_Xhash_contexts();
86+
87+
Xhash_context_holder ctx;
88+
89+
uint32_t hashA[16], hashB[16];
90+
//blake-bmw-groestl-sken-jh-meccak-luffa-cubehash-shivite-simd-echo
91+
memcpy(&ctx, &base_contexts, sizeof(base_contexts));
92+
93+
sph_blake512 (&ctx.blake1, input, 80);
94+
sph_blake512_close (&ctx.blake1, hashA);
95+
96+
sph_skein512 (&ctx.skein1, hashA, 64);
97+
sph_skein512_close(&ctx.skein1, hashB);
98+
99+
sph_bmw512 (&ctx.bmw1, hashB, 64);
100+
sph_bmw512_close(&ctx.bmw1, hashA);
101+
102+
sph_groestl512 (&ctx.groestl1, hashA, 64);
103+
sph_groestl512_close(&ctx.groestl1, hashB);
104+
105+
sph_jh512 (&ctx.jh1, hashB, 64);
106+
sph_jh512_close(&ctx.jh1, hashA);
107+
108+
sph_luffa512 (&ctx.luffa1, hashA, 64);
109+
sph_luffa512_close (&ctx.luffa1, hashB);
110+
111+
sph_keccak512 (&ctx.keccak1, hashB, 64);
112+
sph_keccak512_close(&ctx.keccak1, hashA);
113+
114+
sph_cubehash512 (&ctx.cubehash1, hashA, 64);
115+
sph_cubehash512_close(&ctx.cubehash1, hashB);
116+
117+
sph_simd512 (&ctx.simd1, hashB, 64);
118+
sph_simd512_close(&ctx.simd1, hashA);
119+
120+
sph_shavite512 (&ctx.shavite1, hashA, 64);
121+
sph_shavite512_close(&ctx.shavite1, hashB);
122+
123+
sph_echo512 (&ctx.echo1, hashB, 64);
124+
sph_echo512_close(&ctx.echo1, hashA);
125+
126+
memcpy(state, hashA, 32);
127+
128+
}
129+
130+
static const uint32_t diff1targ = 0x0000ffff;
131+
132+
133+
/* Used externally as confirmation of correct OCL code */
134+
int chainox_test(unsigned char *pdata, const unsigned char *ptarget, uint32_t nonce)
135+
{
136+
uint32_t tmp_hash7, Htarg = le32toh(((const uint32_t *)ptarget)[7]);
137+
uint32_t data[20], ohash[8];
138+
139+
be32enc_vect(data, (const uint32_t *)pdata, 19);
140+
data[19] = htobe32(nonce);
141+
xhash(ohash, data);
142+
tmp_hash7 = be32toh(ohash[7]);
143+
144+
applog(LOG_DEBUG, "htarget %08lx diff1 %08lx hash %08lx",
145+
(long unsigned int)Htarg,
146+
(long unsigned int)diff1targ,
147+
(long unsigned int)tmp_hash7);
148+
if (tmp_hash7 > diff1targ)
149+
return -1;
150+
if (tmp_hash7 > Htarg)
151+
return 0;
152+
return 1;
153+
}
154+
155+
void chainox_regenhash(struct work *work)
156+
{
157+
uint32_t data[20];
158+
uint32_t *nonce = (uint32_t *)(work->data + 76);
159+
uint32_t *ohash = (uint32_t *)(work->hash);
160+
161+
be32enc_vect(data, (const uint32_t *)work->data, 19);
162+
data[19] = htobe32(*nonce);
163+
xhash(ohash, data);
164+
}
165+
166+
bool scanhash_chainox(struct thr_info *thr, const unsigned char __maybe_unused *pmidstate,
167+
unsigned char *pdata, unsigned char __maybe_unused *phash1,
168+
unsigned char __maybe_unused *phash, const unsigned char *ptarget,
169+
uint32_t max_nonce, uint32_t *last_nonce, uint32_t n)
170+
{
171+
uint32_t *nonce = (uint32_t *)(pdata + 76);
172+
uint32_t data[20];
173+
uint32_t tmp_hash7;
174+
uint32_t Htarg = le32toh(((const uint32_t *)ptarget)[7]);
175+
bool ret = false;
176+
177+
be32enc_vect(data, (const uint32_t *)pdata, 19);
178+
179+
while(1) {
180+
uint32_t ostate[8];
181+
182+
*nonce = ++n;
183+
data[19] = (n);
184+
xhash(ostate, data);
185+
tmp_hash7 = (ostate[7]);
186+
187+
applog(LOG_INFO, "data7 %08lx",
188+
(long unsigned int)data[7]);
189+
190+
if (unlikely(tmp_hash7 <= Htarg)) {
191+
((uint32_t *)pdata)[19] = htobe32(n);
192+
*last_nonce = n;
193+
ret = true;
194+
break;
195+
}
196+
197+
if (unlikely((n >= max_nonce) || thr->work_restart)) {
198+
*last_nonce = n;
199+
break;
200+
}
201+
}
202+
203+
return ret;
204+
}
205+
206+
207+

algorithm/chainox.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#ifndef CHAINOX_H
2+
#define CHAINOX_H
3+
4+
#include "miner.h"
5+
6+
extern int chainox_test(unsigned char *pdata, const unsigned char *ptarget,
7+
uint32_t nonce);
8+
extern void chainox_regenhash(struct work *work);
9+
10+
#endif /* CHAINOX_H */

configure.ac

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##
22
##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##
33
m4_define([v_maj], [0])
4-
m4_define([v_min], [8])
5-
m4_define([v_mic], [1])
4+
m4_define([v_min], [9])
5+
m4_define([v_mic], [0])
66
m4_define([v_rev], [0])
77
##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##
88
m4_ifdef([v_rev], [m4_define([v_ver], [v_maj.v_min.v_mic-v_rev])], [m4_define([v_ver], [v_maj.v_min.v_mic])])

driver-opencl.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1428,7 +1428,7 @@ static int64_t opencl_scanhash(struct thr_info *thr, struct work *work,
14281428

14291429
status = thrdata->queue_kernel_parameters(clState, &work->blk, globalThreads[0]);
14301430
if (unlikely(status != CL_SUCCESS)) {
1431-
applog(LOG_ERR, "Error: clSetKernelArg of all params failed.");
1431+
applog(LOG_ERR, "Error %d: clSetKernelArg of all params failed.", status);
14321432
return -1;
14331433
}
14341434

@@ -1594,6 +1594,24 @@ if (gpu->algorithm.type != ALGO_MTP && gpu->algorithm.type != ALGO_YESCRYPT_NAVI
15941594
const size_t global3[] = { 4, throughput };
15951595
const size_t local3[] = { 4, 8 };
15961596
status = clEnqueueNDRangeKernel(clState->commandQueue, clState->extra_kernels[i], 2, NULL, global3, local3, 0, NULL, NULL);
1597+
} else if (gpu->algorithm.type == ALGO_0X10_NAVI && i == 2) {
1598+
size_t globalThreads2[1];
1599+
size_t localThreads2[1];
1600+
size_t globalOffset2[1];
1601+
globalThreads2[0] = globalThreads[0] * 4;
1602+
localThreads2[0] = 32;
1603+
globalOffset2[0] = (*p_global_work_offset) * 4;
1604+
status = clEnqueueNDRangeKernel(clState->commandQueue, clState->extra_kernels[i], 1, globalOffset2,
1605+
globalThreads2, localThreads2, 0, NULL, NULL);
1606+
} else if (gpu->algorithm.type == ALGO_0X10 && i== 2 && clState->prebuilt) {
1607+
size_t globalThreads2[1];
1608+
size_t localThreads2[1];
1609+
size_t globalOffset2[1];
1610+
globalThreads2[0] = globalThreads[0] * 4;
1611+
localThreads2[0] = 64;
1612+
globalOffset2[0] = (*p_global_work_offset) * 4;
1613+
status = clEnqueueNDRangeKernel(clState->commandQueue, clState->extra_kernels[i], 1, globalOffset2,
1614+
globalThreads2, localThreads2, 0, NULL, NULL);
15971615
}
15981616
else
15991617
status = clEnqueueNDRangeKernel(clState->commandQueue, clState->extra_kernels[i], 1, p_global_work_offset,

0 commit comments

Comments
 (0)