Skip to content

Commit

Permalink
import and adapt scrypt from cudaminer project
Browse files Browse the repository at this point in the history
scrypt-jane under work...
  • Loading branch information
tpruvot committed Apr 18, 2015
1 parent 275a028 commit 9dc78da
Show file tree
Hide file tree
Showing 38 changed files with 12,675 additions and 773 deletions.
13 changes: 12 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ bin_PROGRAMS = ccminer
ccminer_SOURCES = elist.h miner.h compat.h \
compat/inttypes.h compat/stdbool.h compat/unistd.h \
compat/sys/time.h compat/getopt/getopt.h \
crc32.c hefty1.c scrypt.c \
crc32.c hefty1.c \
ccminer.cpp util.cpp \
api.cpp hashlog.cpp nvml.cpp stats.cpp sysinfos.cpp cuda.cpp \
heavy/heavy.cu \
Expand Down Expand Up @@ -57,6 +57,13 @@ ccminer_SOURCES = elist.h miner.h compat.h \
x17/x17.cu x17/cuda_x17_haval512.cu x17/cuda_x17_sha512.cu \
x11/s3.cu

# scrypt
ccminer_SOURCES += scrypt.cpp scrypt-jane.cpp \
scrypt/blake.cu scrypt/keccak.cu scrypt/sha256.cu \
scrypt/salsa_kernel.cu scrypt/test_kernel.cu \
scrypt/fermi_kernel.cu scrypt/kepler_kernel.cu \
scrypt/nv_kernel.cu scrypt/nv_kernel2.cu scrypt/titan_kernel.cu

if HAVE_NVML
nvml_defs = -DUSE_WRAPNVML
nvml_libs = -ldl
Expand Down Expand Up @@ -118,6 +125,10 @@ quark/cuda_quark_compactionTest.o: quark/cuda_quark_compactionTest.cu
JHA/cuda_jha_compactionTest.o: JHA/cuda_jha_compactionTest.cu
$(NVCC) $(nvcc_FLAGS) -I cudpp-2.1/include --maxrregcount=80 -o $@ -c $<

# This kernel need also an older SM to be able to autotune kernels
scrypt/salsa_kernel.o: scrypt/salsa_kernel.cu
$(NVCC) $(nvcc_FLAGS) -gencode=arch=compute_20,code=\"sm_21,compute_20\" --maxrregcount=80 -o $@ -c $<

skein.o: skein.cu
$(NVCC) $(nvcc_FLAGS) --maxrregcount=64 -o $@ -c $<

Expand Down
65 changes: 62 additions & 3 deletions ccminer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ enum sha_algos {
ALGO_PLUCK,
ALGO_QUARK,
ALGO_QUBIT,
ALGO_SCRYPT,
ALGO_SCRYPT_JANE,
ALGO_SKEIN,
ALGO_SKEIN2,
ALGO_S3,
Expand Down Expand Up @@ -137,6 +139,8 @@ static const char *algo_names[] = {
"pluck",
"quark",
"qubit",
"scrypt",
"scrypt-jane",
"skein",
"skein2",
"s3",
Expand Down Expand Up @@ -184,6 +188,20 @@ char * device_name[MAX_GPUS];
short device_map[MAX_GPUS] = { 0 };
long device_sm[MAX_GPUS] = { 0 };
uint32_t gpus_intensity[MAX_GPUS] = { 0 };

int device_interactive[MAX_GPUS] = { 0 };
int device_batchsize[MAX_GPUS] = { 0 };
int device_backoff[MAX_GPUS] = { 0 };
int device_lookup_gap[MAX_GPUS] = { 0 };
int device_texturecache[MAX_GPUS] = { 0 };
int device_singlememory[MAX_GPUS] = { 0 };
char *device_config[MAX_GPUS] = { 0 };
int opt_nfactor = 0;
int parallel = 2;
bool autotune = true;
bool abort_flag = false;
char *jane_params = NULL;

char *rpc_user = NULL;
static char *rpc_pass;
static char *rpc_userpass = NULL;
Expand Down Expand Up @@ -255,6 +273,8 @@ Options:\n\
pluck SupCoin\n\
quark Quark\n\
qubit Qubit\n\
scrypt Scrypt\n\
scrypt-jane Scrypt-jane Chacha\n\
skein Skein SHA2 (Skeincoin)\n\
skein2 Double Skein (Woodcoin)\n\
s3 S3 (1Coin)\n\
Expand Down Expand Up @@ -439,6 +459,7 @@ void get_currentalgo(char* buf, int sz)
*/
void proper_exit(int reason)
{
abort_flag = true;
cuda_devicereset();

if (check_dups)
Expand Down Expand Up @@ -1173,6 +1194,8 @@ static void stratum_gen_work(struct stratum_ctx *sctx, struct work *work)
switch (opt_algo) {
case ALGO_JACKPOT:
case ALGO_PLUCK:
case ALGO_SCRYPT:
case ALGO_SCRYPT_JANE:
diff_to_target(work->target, sctx->job.diff / (65536.0 * opt_difficulty));
break;
case ALGO_DMD_GR:
Expand Down Expand Up @@ -1386,6 +1409,8 @@ static void *miner_thread(void *userdata)
minmax = 0x400000;
break;
case ALGO_LYRA2:
case ALGO_SCRYPT:
case ALGO_SCRYPT_JANE:
minmax = 0x100000;
break;
case ALGO_PLUCK:
Expand Down Expand Up @@ -1526,6 +1551,16 @@ static void *miner_thread(void *userdata)
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);
break;

case ALGO_SCRYPT_JANE:
rc = scanhash_scrypt_jane(thr_id, work.data, work.target, NULL,
max_nonce, &hashes_done, &tv_start, &tv_end);
break;

case ALGO_SKEIN:
rc = scanhash_skeincoin(thr_id, work.data, work.target,
max_nonce, &hashes_done);
Expand Down Expand Up @@ -1942,15 +1977,29 @@ void parse_arg(int key, char *arg)

switch(key) {
case 'a':
p = strstr(arg, ":"); // optional factor
if (p) *p = '\0';
for (i = 0; i < ARRAY_SIZE(algo_names); i++) {
if (algo_names[i] &&
!strcmp(arg, algo_names[i])) {
if (algo_names[i] && !strcasecmp(arg, algo_names[i])) {
opt_algo = (enum sha_algos)i;
break;
}
}
if (i == ARRAY_SIZE(algo_names))
show_usage_and_exit(1);
if (p) {
opt_nfactor = atoi(p + 1);
if (opt_algo == ALGO_SCRYPT_JANE) {
free(jane_params);
jane_params = strdup(p+1);
}
}
if (!opt_nfactor) {
switch (opt_algo) {
case ALGO_SCRYPT: opt_nfactor = 9; break;
case ALGO_SCRYPT_JANE: opt_nfactor = 14; break;
}
}
break;
case 'b':
p = strstr(arg, ":");
Expand Down Expand Up @@ -2404,6 +2453,8 @@ int main(int argc, char *argv[])
rpc_pass = strdup("");
rpc_url = strdup("");

jane_params = strdup("");

pthread_mutex_init(&applog_lock, NULL);

// number of cpus for thread affinity
Expand All @@ -2423,9 +2474,17 @@ int main(int argc, char *argv[])
if (num_cpus < 1)
num_cpus = 1;

// default thread to device map
for (i = 0; i < MAX_GPUS; i++) {
device_map[i] = i;
device_name[i] = NULL;
// for future use, maybe
device_interactive[i] = -1;
device_batchsize[i] = 1024;
device_backoff[i] = is_windows() ? 12 : 2;
device_lookup_gap[i] = 1;
device_texturecache[i] = -1;
device_singlememory[i] = -1;
device_config[i] = NULL;
}

// number of gpus
Expand Down
25 changes: 20 additions & 5 deletions ccminer.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@
<TreatWChar_tAsBuiltInType>false</TreatWChar_tAsBuiltInType>
<Optimization Condition="'$(Configuration)'=='Release'">Full</Optimization>
</ClCompile>
<ClCompile Include="scrypt-jane.cpp" />
<ClCompile Include="scrypt.cpp" />
<ClCompile Include="util.cpp" />
<ClCompile Include="fuguecoin.cpp" />
<ClCompile Include="groestlcoin.cpp" />
Expand All @@ -261,10 +263,6 @@
<ClCompile Include="crc32.c" />
<ClCompile Include="hefty1.c" />
<ClCompile Include="myriadgroestl.cpp" />
<ClCompile Include="scrypt.c">
<Optimization Condition="'$(Configuration)'=='Release'">Full</Optimization>
<AdditionalOptions>/Tp %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<ClCompile Include="lyra2\Lyra2.c" />
<ClCompile Include="lyra2\Sponge.c" />
<ClCompile Include="sph\aes_helper.c" />
Expand Down Expand Up @@ -322,6 +320,7 @@
<ClInclude Include="miner.h" />
<ClInclude Include="nvml.h" />
<ClInclude Include="res\resource.h" />
<ClInclude Include="scrypt\salsa_kernel.h" />
<ClInclude Include="sph\sph_blake.h" />
<ClInclude Include="sph\sph_bmw.h" />
<ClInclude Include="sph\sph_cubehash.h" />
Expand Down Expand Up @@ -352,6 +351,22 @@
<CudaCompile Include="cuda_myriadgroestl.cu" />
<CudaCompile Include="cuda_nist5.cu">
</CudaCompile>
<CudaCompile Include="scrypt\blake.cu" />
<CudaCompile Include="scrypt\fermi_kernel.cu">
<CodeGeneration Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">compute_20,sm_21;compute_30,sm_30;compute_35,sm_35;compute_50,sm_50;compute_52,sm_52</CodeGeneration>
</CudaCompile>
<CudaCompile Include="scrypt\keccak.cu" />
<CudaCompile Include="scrypt\kepler_kernel.cu" />
<CudaCompile Include="scrypt\nv_kernel.cu" />
<CudaCompile Include="scrypt\nv_kernel2.cu">
<CodeGeneration Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">compute_35,sm_35;compute_50,sm_50;compute_52,sm_52</CodeGeneration>
</CudaCompile>
<CudaCompile Include="scrypt\salsa_kernel.cu">
<CodeGeneration Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">compute_20,sm_21</CodeGeneration>
</CudaCompile>
<CudaCompile Include="scrypt\sha256.cu" />
<CudaCompile Include="scrypt\test_kernel.cu" />
<CudaCompile Include="scrypt\titan_kernel.cu" />
<CudaCompile Include="zr5.cu" />
<CudaCompile Include="heavy\cuda_blake512.cu">
</CudaCompile>
Expand Down Expand Up @@ -510,4 +525,4 @@
<Target Name="AfterClean">
<Delete Files="@(FilesToCopy->'$(OutDir)%(Filename)%(Extension)')" TreatErrorsAsWarnings="true" />
</Target>
</Project>
</Project>
47 changes: 43 additions & 4 deletions ccminer.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@
<Filter Include="Ressources">
<UniqueIdentifier>{f5117ccb-a70d-411a-b7ea-d6faed230bc7}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\CUDA\scrypt">
<UniqueIdentifier>{c26f5b02-37b5-4420-a4e8-ee1ad517dc95}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="compat\jansson\dump.c">
Expand Down Expand Up @@ -111,9 +114,6 @@
<ClCompile Include="hefty1.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="scrypt.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="fuguecoin.cpp">
<Filter>Source Files</Filter>
</ClCompile>
Expand Down Expand Up @@ -225,6 +225,12 @@
<ClCompile Include="lyra2\Sponge.c">
<Filter>Source Files\sph</Filter>
</ClCompile>
<ClCompile Include="scrypt.cpp">
<Filter>Source Files\CUDA\scrypt</Filter>
</ClCompile>
<ClCompile Include="scrypt-jane.cpp">
<Filter>Source Files\CUDA\scrypt</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="compat.h">
Expand Down Expand Up @@ -377,6 +383,9 @@
<ClInclude Include="res\resource.h">
<Filter>Ressources</Filter>
</ClInclude>
<ClInclude Include="scrypt\salsa_kernel.h">
<Filter>Source Files\CUDA\scrypt</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<CudaCompile Include="cuda.cpp">
Expand Down Expand Up @@ -580,6 +589,36 @@
<CudaCompile Include="skein2.cu">
<Filter>Source Files\CUDA</Filter>
</CudaCompile>
<CudaCompile Include="scrypt\blake.cu">
<Filter>Source Files\CUDA\scrypt</Filter>
</CudaCompile>
<CudaCompile Include="scrypt\fermi_kernel.cu">
<Filter>Source Files\CUDA\scrypt</Filter>
</CudaCompile>
<CudaCompile Include="scrypt\keccak.cu">
<Filter>Source Files\CUDA\scrypt</Filter>
</CudaCompile>
<CudaCompile Include="scrypt\kepler_kernel.cu">
<Filter>Source Files\CUDA\scrypt</Filter>
</CudaCompile>
<CudaCompile Include="scrypt\nv_kernel.cu">
<Filter>Source Files\CUDA\scrypt</Filter>
</CudaCompile>
<CudaCompile Include="scrypt\nv_kernel2.cu">
<Filter>Source Files\CUDA\scrypt</Filter>
</CudaCompile>
<CudaCompile Include="scrypt\salsa_kernel.cu">
<Filter>Source Files\CUDA\scrypt</Filter>
</CudaCompile>
<CudaCompile Include="scrypt\sha256.cu">
<Filter>Source Files\CUDA\scrypt</Filter>
</CudaCompile>
<CudaCompile Include="scrypt\test_kernel.cu">
<Filter>Source Files\CUDA\scrypt</Filter>
</CudaCompile>
<CudaCompile Include="scrypt\titan_kernel.cu">
<Filter>Source Files\CUDA\scrypt</Filter>
</CudaCompile>
</ItemGroup>
<ItemGroup>
<Image Include="res\ccminer.ico">
Expand All @@ -596,4 +635,4 @@
<Filter>Ressources</Filter>
</Text>
</ItemGroup>
</Project>
</Project>
11 changes: 7 additions & 4 deletions miner.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,6 @@ void sha256_transform_8way(uint32_t *state, const uint32_t *block, int swap);
extern int scanhash_sha256d(int thr_id, uint32_t *pdata,
const uint32_t *ptarget, uint32_t max_nonce, unsigned long *hashes_done);

extern unsigned char *scrypt_buffer_alloc();

extern int scanhash_deep(int thr_id, uint32_t *pdata,
const uint32_t *ptarget, uint32_t max_nonce,
unsigned long *hashes_done);
Expand Down Expand Up @@ -343,8 +341,12 @@ extern int scanhash_qubit(int thr_id, uint32_t *pdata,
unsigned long *hashes_done);

extern int scanhash_scrypt(int thr_id, uint32_t *pdata,
unsigned char *scratchbuf, const uint32_t *ptarget,
uint32_t max_nonce, unsigned long *hashes_done);
const uint32_t *ptarget, unsigned char *scratchbuf, uint32_t max_nonce,
unsigned long *hashes_done, struct timeval *tv_start, struct timeval *tv_end);

extern int scanhash_scrypt_jane(int thr_id, uint32_t *pdata,
const uint32_t *ptarget, unsigned char *scratchbuf, uint32_t max_nonce,
unsigned long *hashes_done, struct timeval *tv_start, struct timeval *tv_end);

extern int scanhash_skeincoin(int thr_id, uint32_t *pdata,
const uint32_t *ptarget, uint32_t max_nonce,
Expand Down Expand Up @@ -683,6 +685,7 @@ 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);
void skeincoinhash(void *output, const void *input);
void skein2hash(void *output, const void *input);
void s3hash(void *output, const void *input);
Expand Down
Loading

0 comments on commit 9dc78da

Please sign in to comment.