Skip to content

Commit

Permalink
Maxcoin initial build
Browse files Browse the repository at this point in the history
  • Loading branch information
reorder committed Feb 10, 2014
1 parent d5ba75f commit 66468d2
Show file tree
Hide file tree
Showing 13 changed files with 634 additions and 8 deletions.
4 changes: 4 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ if HAS_SCRYPT
cgminer_SOURCES += scrypt.c scrypt.h
endif

if HAS_KECCAK
cgminer_SOURCES += keccak.c keccak.h
endif

endif

if NEED_FPGAUTILS
Expand Down
2 changes: 2 additions & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ CGMiner specific configuration options:
--disable-adl Override detection and disable building with adl
--enable-scrypt Compile support for scrypt litecoin mining (default
disabled)
--enable-keccak Compile support for keccak copperlark mining (default disabled)
--enable-avalon Compile support for Avalon (default disabled)
--enable-bflsc Compile support for BFL ASICs (default disabled)
--enable-bitforce Compile support for BitForce FPGAs (default
Expand Down Expand Up @@ -183,6 +184,7 @@ Options for both config file and command line:
--failover-only Don't leak work to backup pools when primary pool is lagging
--fix-protocol Do not redirect to a different getwork protocol (eg. stratum)
--hotplug <arg> Set hotplug check time to <arg> seconds (0=never default: 5) - only with libusb
--keccak Use the keccak algorithm for mining (MaxCoin)
--kernel-path|-K <arg> Specify a path to where bitstream and kernel files are (default: "/usr/local/bin")
--load-balance Change multipool strategy from failover to quota based balance
--log|-l <arg> Interval in seconds between log output (default: 5)
Expand Down
11 changes: 11 additions & 0 deletions api.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ static const char *FALSESTR = "false";
#ifdef USE_SCRYPT
static const char *SCRYPTSTR = "scrypt";
#endif

#ifdef USE_KECCAK
static const char *KECCAKSTR = "keccak";
#endif

static const char *SHA256STR = "sha256";

static const char *DEVICECODE = ""
Expand Down Expand Up @@ -3669,6 +3674,12 @@ static void minecoin(struct io_data *io_data, __maybe_unused SOCKETTYPE c, __may
root = api_add_const(root, "Hash Method", SCRYPTSTR, false);
else
#endif

#ifdef USE_KECCAK
if (opt_keccak)
root = api_add_const(root, "Hash Method", KECCAKSTR, false);
else
#endif
root = api_add_const(root, "Hash Method", SHA256STR, false);

cg_rlock(&ch_lock);
Expand Down
30 changes: 28 additions & 2 deletions cgminer.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ char *curly = ":D";
#include "driver-opencl.h"
#include "bench_block.h"
#include "scrypt.h"
#include "keccak.h"

#ifdef USE_USBUTILS
#include "usbutils.h"
#endif
Expand Down Expand Up @@ -123,6 +125,9 @@ int gpu_threads;
#ifdef USE_SCRYPT
bool opt_scrypt;
#endif
#ifdef USE_KECCAK
bool opt_keccak;
#endif
#endif
bool opt_restart = true;
bool opt_nogpu;
Expand Down Expand Up @@ -1451,6 +1456,11 @@ static struct opt_table opt_config_table[] = {
OPT_WITH_ARG("--shaders",
set_shaders, NULL, NULL,
"GPU shaders per card for tuning scrypt, comma separated"),
#endif
#ifdef USE_KECCAK
OPT_WITHOUT_ARG("--keccak",
opt_set_bool, &opt_keccak,
"Use the keccak algorithm for mining (copperlark only)"),
#endif
OPT_WITH_ARG("--sharelog",
set_sharelog, NULL, NULL,
Expand Down Expand Up @@ -1709,6 +1719,9 @@ static char *opt_verusage_and_exit(const char *extra)
#endif
#ifdef USE_SCRYPT
"scrypt "
#endif
#ifdef USE_KECCAK
"keccak "
#endif
"mining support.\n"
, packagename);
Expand Down Expand Up @@ -3268,6 +3281,8 @@ static void calc_diff(struct work *work, double known)
d64 = truediffone;
if (opt_scrypt)
d64 *= (double)65536;
else if (opt_keccak)
d64 *= (double)256;
dcut64 = le256todouble(work->target);
if (unlikely(!dcut64))
dcut64 = 1;
Expand Down Expand Up @@ -3942,6 +3957,8 @@ static void rebuild_hash(struct work *work)
{
if (opt_scrypt)
scrypt_regenhash(work);
else if (opt_keccak)
keccak_regenhash(work);
else
regen_hash(work);
}
Expand Down Expand Up @@ -4633,6 +4650,9 @@ void write_config(FILE *fcfg)
case KL_SCRYPT:
fprintf(fcfg, "scrypt");
break;
case KL_KECCAK:
fprintf(fcfg, "keccak");
break;
}
}
};
Expand Down Expand Up @@ -6178,6 +6198,8 @@ void set_target(unsigned char *dest_target, double diff)
d64 = truediffone;
if (opt_scrypt)
d64 *= (double)65536;
else if (opt_keccak)
d64 *= (double)256;
d64 /= diff;

dcut64 = d64 / bits192;
Expand Down Expand Up @@ -6237,7 +6259,11 @@ static void gen_stratum_work(struct pool *pool, struct work *work)
cg_dwlock(&pool->data_lock);

/* Generate merkle root */
gen_hash(pool->coinbase, merkle_root, pool->swork.cb_len);
if (opt_keccak) {
sha256(pool->coinbase, pool->swork.cb_len, merkle_root);
} else {
gen_hash(pool->coinbase, merkle_root, pool->swork.cb_len);
}
memcpy(merkle_sha, merkle_root, 32);
for (i = 0; i < pool->swork.merkles; i++) {
memcpy(merkle_sha + 32, pool->swork.merkle_bin[i], 32);
Expand Down Expand Up @@ -6388,7 +6414,7 @@ bool test_nonce(struct work *work, uint32_t nonce)
uint32_t diff1targ;

rebuild_nonce(work, nonce);
diff1targ = opt_scrypt ? 0x0000ffffUL : 0;
diff1targ = opt_scrypt ? 0x0000ffffUL : (opt_keccak ? 0x000000ffUL : 0);

return (le32toh(*hash_32) <= diff1targ);
}
Expand Down
20 changes: 20 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ AC_ARG_ENABLE([adl],
)

scrypt="no"
keccak="no"

if test "$found_opencl" = 1; then
if test "x$adl" != xno; then
Expand All @@ -215,11 +216,20 @@ if test "$found_opencl" = 1; then
if test "x$scrypt" = xyes; then
AC_DEFINE([USE_SCRYPT], [1], [Defined to 1 if scrypt support is wanted])
fi

AC_ARG_ENABLE([keccak],
[AC_HELP_STRING([--enable-keccak],[Compile support for keccak copperlark mining (default disabled)])],
[keccak=$enableval]
)
if test "x$keccak" = xyes; then
AC_DEFINE([USE_KECCAK], [1], [Defined to 1 if keccak support is wanted])
fi
else
DLOPEN_FLAGS=""
fi

AM_CONDITIONAL([HAS_SCRYPT], [test x$scrypt = xyes])
AM_CONDITIONAL([HAS_KECCAK], [test x$keccak = xyes])

avalon="no"

Expand Down Expand Up @@ -481,6 +491,7 @@ AC_DEFINE_UNQUOTED([POCLBM_KERNNAME], ["poclbm130302"], [Filename for poclbm ker
AC_DEFINE_UNQUOTED([DIAKGCN_KERNNAME], ["diakgcn121016"], [Filename for diakgcn kernel])
AC_DEFINE_UNQUOTED([DIABLO_KERNNAME], ["diablo130302"], [Filename for diablo kernel])
AC_DEFINE_UNQUOTED([SCRYPT_KERNNAME], ["scrypt130511"], [Filename for scrypt kernel])
AC_DEFINE_UNQUOTED([KECCAK_KERNNAME], ["keccak130718"], [Filename for keccak kernel])


AC_SUBST(OPENCL_LIBS)
Expand Down Expand Up @@ -535,19 +546,28 @@ if test "x$opencl" != xno; then
echo " scrypt...............: Disabled"
fi


if test "x$keccak" != xno; then
echo " keccak...............: Enabled"
else
echo " keccak...............: Disabled"
fi

else
echo " OpenCL...............: NOT FOUND. GPU mining support DISABLED"
if test "x$avalon$bitforce$bitfury$icarus$modminer$bflsc$hashfast$klondike$knc" = xnonononononononono; then
AC_MSG_ERROR([No mining configured in])
fi
echo " scrypt...............: Disabled (needs OpenCL)"
echo " keccak...............: Disabled (needs OpenCL)"
fi
else
echo " OpenCL...............: Detection overrided. GPU mining support DISABLED"
if test "x$avalon$bitforce$bitfury$icarus$modminer$bflsc$hashfast$klondike$knc" = xnonononononononono; then
AC_MSG_ERROR([No mining configured in])
fi
echo " scrypt...............: Disabled (needs OpenCL)"
echo " keccak...............: Disabled (needs OpenCL)"
fi

if test "x$adl" != xno; then
Expand Down
54 changes: 50 additions & 4 deletions driver-opencl.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
#include "adl.h"
#include "util.h"

#ifdef USE_KECCAK
#include "keccak.h"
#endif

/* TODO: cleanup externals ********************/

#ifdef HAVE_CURSES
Expand Down Expand Up @@ -233,6 +237,10 @@ static enum cl_kernels select_kernel(char *arg)
#ifdef USE_SCRYPT
if (!strcmp(arg, "scrypt"))
return KL_SCRYPT;
#endif
#ifdef USE_KECCAK
if (!strcmp(arg, "keccak"))
return KL_KECCAK;
#endif
return KL_NONE;
}
Expand All @@ -245,6 +253,8 @@ char *set_kernel(char *arg)

if (opt_scrypt)
return "Cannot specify a kernel with scrypt";
if (opt_keccak)
return "Cannot specify a kernel with keccak";
nextptr = strtok(arg, ",");
if (nextptr == NULL)
return "Invalid parameters for set kernel";
Expand Down Expand Up @@ -1296,6 +1306,24 @@ static cl_int queue_scrypt_kernel(_clState *clState, dev_blk_ctx *blk, __maybe_u
return status;
}
#endif
#ifdef USE_KECCAK
static cl_int queue_keccak_kernel(_clState *clState, dev_blk_ctx *blk, __maybe_unused cl_uint threads)
{
cl_kernel *kernel = &clState->kernel;
unsigned int num = 0;
cl_int status = 0;

status = clEnqueueWriteBuffer(clState->commandQueue,
clState->keccak_CLbuffer, true, 0,
KECCAK_BUFFER_SIZE, &blk->keccak_data[0],
0, NULL,NULL);

CL_SET_ARG(clState->keccak_CLbuffer);
CL_SET_ARG(clState->outputBuffer);

return status;
}
#endif

static void set_threads_hashes(unsigned int vectors, unsigned int compute_shaders, int64_t *hashes, size_t *globalThreads,
unsigned int minthreads, __maybe_unused int *intensity, __maybe_unused int *xintensity, __maybe_unused int *rawintensity)
Expand Down Expand Up @@ -1601,6 +1629,12 @@ static bool opencl_thread_prepare(struct thr_info *thr)
cgpu->kname = "scrypt";
break;
#endif

#ifdef USE_KECCAK
case KL_KECCAK:
cgpu->kname = "keccak";
break;
#endif
case KL_POCLBM:
cgpu->kname = "poclbm";
break;
Expand Down Expand Up @@ -1647,6 +1681,11 @@ static bool opencl_thread_init(struct thr_info *thr)
case KL_SCRYPT:
thrdata->queue_kernel_parameters = &queue_scrypt_kernel;
break;
#endif
#ifdef USE_KECCAK
case KL_KECCAK:
thrdata->queue_kernel_parameters = &queue_keccak_kernel;
break;
#endif
default:
case KL_DIABLO:
Expand Down Expand Up @@ -1683,6 +1722,11 @@ static bool opencl_prepare_work(struct thr_info __maybe_unused *thr, struct work
if (opt_scrypt)
work->blk.work = work;
else
#endif
#ifdef USE_KECCAK
if (opt_keccak)
keccak_prepare_work(thr, work);
else
#endif
precalc_hash(&work->blk, (uint32_t *)(work->midstate), (uint32_t *)(work->data + 64));
return true;
Expand Down Expand Up @@ -1788,10 +1832,12 @@ static void opencl_thread_shutdown(struct thr_info *thr)
const int thr_id = thr->id;
_clState *clState = clStates[thr_id];

clReleaseKernel(clState->kernel);
clReleaseProgram(clState->program);
clReleaseCommandQueue(clState->commandQueue);
clReleaseContext(clState->context);
if (clState->kernel) {
clReleaseKernel(clState->kernel);
clReleaseProgram(clState->program);
clReleaseCommandQueue(clState->commandQueue);
clReleaseContext(clState->context);
}
}

struct device_drv opencl_drv = {
Expand Down
1 change: 1 addition & 0 deletions findnonce.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ static void *postcalc_hash(void *userdata)

for (entry = 0; entry < pcd->res[found]; entry++) {
uint32_t nonce = pcd->res[entry];
nonce = swab32(nonce);

applog(LOG_DEBUG, "OCL NONCE %u found in slot %d", nonce, entry);
submit_nonce(thr, pcd->work, nonce);
Expand Down
Loading

0 comments on commit 66468d2

Please sign in to comment.