diff --git a/algorithm.c b/algorithm.c index 2ad221e9..0a321993 100644 --- a/algorithm.c +++ b/algorithm.c @@ -567,6 +567,7 @@ static cl_int queue_fresh_kernel(struct __clState *clState, struct _dev_blk_ctx typedef struct _algorithm_settings_t { const char *name; /* Human-readable identifier */ algorithm_type_t type; //common algorithm type + const char *kernelfile; /* alternate kernel file */ double diff_multiplier1; double diff_multiplier2; double share_diff_multiplier; @@ -587,7 +588,7 @@ typedef struct _algorithm_settings_t { static algorithm_settings_t algos[] = { // kernels starting from this will have difficulty calculated by using litecoin algorithm #define A_SCRYPT(a) \ - { a, ALGO_SCRYPT, 1, 65536, 65536, 0, 0, 0xFF, 0xFFFFFFFFULL, 0x0000ffffUL, 0, -1, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, scrypt_regenhash, queue_scrypt_kernel, gen_hash, append_scrypt_compiler_options} + { a, ALGO_SCRYPT, "", 1, 65536, 65536, 0, 0, 0xFF, 0xFFFFFFFFULL, 0x0000ffffUL, 0, -1, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, scrypt_regenhash, queue_scrypt_kernel, gen_hash, append_scrypt_compiler_options} A_SCRYPT( "ckolivas" ), A_SCRYPT( "alexkarnew" ), A_SCRYPT( "alexkarnold" ), @@ -598,7 +599,7 @@ static algorithm_settings_t algos[] = { // kernels starting from this will have difficulty calculated by using quarkcoin algorithm #define A_QUARK(a, b) \ - { a, ALGO_QUARK, 256, 256, 256, 0, 0, 0xFF, 0xFFFFFFULL, 0x0000ffffUL, 0, 0, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, b, queue_sph_kernel, gen_hash, append_x11_compiler_options} + { a, ALGO_QUARK, "", 256, 256, 256, 0, 0, 0xFF, 0xFFFFFFULL, 0x0000ffffUL, 0, 0, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, b, queue_sph_kernel, gen_hash, append_x11_compiler_options } A_QUARK( "quarkcoin", quarkcoin_regenhash), A_QUARK( "qubitcoin", qubitcoin_regenhash), A_QUARK( "animecoin", animecoin_regenhash), @@ -607,40 +608,40 @@ static algorithm_settings_t algos[] = { // kernels starting from this will have difficulty calculated by using bitcoin algorithm #define A_DARK(a, b) \ - { a, ALGO_X11, 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 0, 0, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, b, queue_sph_kernel, gen_hash, append_x11_compiler_options} + { a, ALGO_X11, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 0, 0, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, b, queue_sph_kernel, gen_hash, append_x11_compiler_options } A_DARK( "darkcoin", darkcoin_regenhash), A_DARK( "inkcoin", inkcoin_regenhash), A_DARK( "myriadcoin-groestl", myriadcoin_groestl_regenhash), #undef A_DARK - { "twecoin", ALGO_TWE, 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 0, 0, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, twecoin_regenhash, queue_sph_kernel, sha256, NULL}, - { "maxcoin", ALGO_KECCAK, 1, 256, 1, 4, 15, 0x0F, 0xFFFFULL, 0x000000ffUL, 0, 0, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, maxcoin_regenhash, queue_maxcoin_kernel, sha256, NULL}, + { "twecoin", ALGO_TWE, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 0, 0, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, twecoin_regenhash, queue_sph_kernel, sha256, NULL}, + { "maxcoin", ALGO_KECCAK, "", 1, 256, 1, 4, 15, 0x0F, 0xFFFFULL, 0x000000ffUL, 0, 0, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, maxcoin_regenhash, queue_maxcoin_kernel, sha256, NULL }, - { "darkcoin-mod", ALGO_X11, 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 10, 8 * 16 * 4194304, 0, darkcoin_regenhash, queue_darkcoin_mod_kernel, gen_hash, append_x11_compiler_options}, + { "darkcoin-mod", ALGO_X11, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 10, 8 * 16 * 4194304, 0, darkcoin_regenhash, queue_darkcoin_mod_kernel, gen_hash, append_x11_compiler_options }, - { "marucoin", ALGO_X13, 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 0, 0, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, marucoin_regenhash, queue_sph_kernel, gen_hash, append_x13_compiler_options}, - { "marucoin-mod", ALGO_X13, 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 12, 8 * 16 * 4194304, 0, marucoin_regenhash, queue_marucoin_mod_kernel, gen_hash, append_x13_compiler_options}, - { "marucoin-modold", ALGO_X13, 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 10, 8 * 16 * 4194304, 0, marucoin_regenhash, queue_marucoin_mod_old_kernel, gen_hash, append_x13_compiler_options}, + { "marucoin", ALGO_X13, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 0, 0, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, marucoin_regenhash, queue_sph_kernel, gen_hash, append_x13_compiler_options }, + { "marucoin-mod", ALGO_X13, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 12, 8 * 16 * 4194304, 0, marucoin_regenhash, queue_marucoin_mod_kernel, gen_hash, append_x13_compiler_options }, + { "marucoin-modold", ALGO_X13, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 10, 8 * 16 * 4194304, 0, marucoin_regenhash, queue_marucoin_mod_old_kernel, gen_hash, append_x13_compiler_options }, - { "x14", ALGO_X14, 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 13, 8 * 16 * 4194304, 0, x14_regenhash, queue_x14_kernel, gen_hash, append_x13_compiler_options}, - { "x14old", ALGO_X14, 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 10, 8 * 16 * 4194304, 0, x14_regenhash, queue_x14_old_kernel, gen_hash, append_x13_compiler_options}, + { "x14", ALGO_X14, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 13, 8 * 16 * 4194304, 0, x14_regenhash, queue_x14_kernel, gen_hash, append_x13_compiler_options }, + { "x14old", ALGO_X14, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 10, 8 * 16 * 4194304, 0, x14_regenhash, queue_x14_old_kernel, gen_hash, append_x13_compiler_options }, - { "bitblock", ALGO_X15, 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 14, 4 * 16 * 4194304, 0, bitblock_regenhash, queue_bitblock_kernel, gen_hash, append_x13_compiler_options}, - { "bitblockold", ALGO_X15, 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 10, 4 * 16 * 4194304, 0, bitblock_regenhash, queue_bitblockold_kernel, gen_hash, append_x13_compiler_options}, + { "bitblock", ALGO_X15, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 14, 4 * 16 * 4194304, 0, bitblock_regenhash, queue_bitblock_kernel, gen_hash, append_x13_compiler_options }, + { "bitblockold", ALGO_X15, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 10, 4 * 16 * 4194304, 0, bitblock_regenhash, queue_bitblockold_kernel, gen_hash, append_x13_compiler_options }, - { "talkcoin-mod", ALGO_NIST, 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 4, 8 * 16 * 4194304, 0, talkcoin_regenhash, queue_talkcoin_mod_kernel, gen_hash, append_x11_compiler_options}, + { "talkcoin-mod", ALGO_NIST, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 4, 8 * 16 * 4194304, 0, talkcoin_regenhash, queue_talkcoin_mod_kernel, gen_hash, append_x11_compiler_options }, - { "fresh", ALGO_FRESH, 1, 256, 256, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 4, 4 * 16 * 4194304, 0, fresh_regenhash, queue_fresh_kernel, gen_hash, NULL}, + { "fresh", ALGO_FRESH, "", 1, 256, 256, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 4, 4 * 16 * 4194304, 0, fresh_regenhash, queue_fresh_kernel, gen_hash, NULL }, // kernels starting from this will have difficulty calculated by using fuguecoin algorithm #define A_FUGUE(a, b) \ - { a, ALGO_FUGUE, 1, 256, 256, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 0, 0, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, b, queue_sph_kernel, sha256, NULL} + { a, ALGO_FUGUE, "", 1, 256, 256, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 0, 0, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, b, queue_sph_kernel, sha256, NULL } A_FUGUE( "fuguecoin", fuguecoin_regenhash), A_FUGUE( "groestlcoin", groestlcoin_regenhash), #undef A_FUGUE // Terminator (do not remove) - { NULL, ALGO_UNK, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL} + { NULL, ALGO_UNK, "", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL } }; void copy_algorithm_settings(algorithm_t* dest, const char* algo) @@ -653,6 +654,7 @@ void copy_algorithm_settings(algorithm_t* dest, const char* algo) if (strcmp(src->name, algo) == 0) { strcpy(dest->name, src->name); + dest->kernelfile = src->kernelfile; dest->type = src->type; dest->diff_multiplier1 = src->diff_multiplier1; @@ -720,6 +722,8 @@ void set_algorithm(algorithm_t* algo, const char* newname_alias) const char* newname; //load previous algorithm nfactor in case nfactor was applied before algorithm... or default to 10 uint8_t old_nfactor = ((algo->nfactor)?algo->nfactor:0); + //load previous kernel file name if was applied before algorithm... + const char *kernelfile = algo->kernelfile; uint8_t nfactor = 10; if (!(newname = lookup_algorithm_alias(newname_alias, &nfactor))) @@ -732,6 +736,11 @@ void set_algorithm(algorithm_t* algo, const char* newname_alias) nfactor = old_nfactor; set_algorithm_nfactor(algo, nfactor); + + //reapply kernelfile if was set + if (!empty_string(kernelfile)) { + algo->kernelfile = kernelfile; + } } void set_algorithm_nfactor(algorithm_t* algo, const uint8_t nfactor) @@ -761,6 +770,5 @@ void set_algorithm_nfactor(algorithm_t* algo, const uint8_t nfactor) bool cmp_algorithm(algorithm_t* algo1, algorithm_t* algo2) { - return (strcmp(algo1->name, algo2->name) == 0) && - (algo1->nfactor == algo2->nfactor); + return (!safe_cmp(algo1->name, algo2->name) && !safe_cmp(algo1->kernelfile, algo2->kernelfile) && (algo1->nfactor == algo2->nfactor)); } diff --git a/algorithm.h b/algorithm.h index 7deffd18..21499753 100644 --- a/algorithm.h +++ b/algorithm.h @@ -42,6 +42,7 @@ struct work; typedef struct _algorithm_t { char name[20]; /* Human-readable identifier */ algorithm_type_t type; //algorithm type + const char *kernelfile; /* alternate kernel file */ uint32_t n; /* N (CPU/Memory tradeoff parameter) */ uint8_t nfactor; /* Factor of N above (n = 2^nfactor) */ double diff_multiplier1; diff --git a/config_parser.c b/config_parser.c index d70c6685..33d85cc4 100644 --- a/config_parser.c +++ b/config_parser.c @@ -173,6 +173,14 @@ char *set_default_devices(const char *arg) return NULL; } +char *set_default_kernelfile(const char *arg) +{ + applog(LOG_INFO, "Set default kernel file to %s", arg); + default_profile.algorithm.kernelfile = arg; + + return NULL; +} + char *set_default_lookup_gap(const char *arg) { default_profile.lookup_gap = arg; @@ -276,7 +284,7 @@ char *set_profile_algorithm(const char *arg) { struct profile *profile = get_current_profile(); - //applog(LOG_DEBUG, "Setting profile %s algorithm to %s", profile->name, arg); + applog(LOG_DEBUG, "Setting profile %s algorithm to %s", profile->name, arg); set_algorithm(&profile->algorithm, arg); return NULL; @@ -289,6 +297,16 @@ char *set_profile_devices(const char *arg) return NULL; } +char *set_profile_kernelfile(const char *arg) +{ + struct profile *profile = get_current_profile(); + + applog(LOG_DEBUG, "Setting profile %s algorithm kernel file to %s", profile->name, arg); + profile->algorithm.kernelfile = arg; + + return NULL; +} + char *set_profile_lookup_gap(const char *arg) { struct profile *profile = get_current_profile(); @@ -946,6 +964,20 @@ void apply_pool_profile(struct pool *pool) } applog(LOG_DEBUG, "Pool %i Algorithm set to \"%s\"", pool->pool_no, pool->algorithm.name); + // if the pool doesn't have a specific kernel file... + if (empty_string(pool->algorithm.kernelfile)) { + // ...but profile does, apply it to the pool + if (!empty_string(profile->algorithm.kernelfile)) { + pool->algorithm.kernelfile = profile->algorithm.kernelfile; + applog(LOG_DEBUG, "Pool %i Kernel File set to \"%s\"", pool->pool_no, pool->algorithm.kernelfile); + // ...or default profile does, apply it to the pool + } + else if (!empty_string(default_profile.algorithm.kernelfile)) { + pool->algorithm.kernelfile = default_profile.algorithm.kernelfile; + applog(LOG_DEBUG, "Pool %i Kernel File set to \"%s\"", pool->pool_no, pool->algorithm.kernelfile); + } + } + if(pool_cmp(pool->devices, default_profile.devices)) { if(!empty_string(profile->devices)) @@ -1233,6 +1265,10 @@ static json_t *build_pool_json() // devices if (!build_pool_json_add(obj, "device", pool->devices, profile->devices, default_profile.devices, pool->pool_no)) return NULL; + + // kernelfile + if (!build_pool_json_add(obj, "kernelfile", pool->algorithm.kernelfile, profile->algorithm.kernelfile, default_profile.algorithm.kernelfile, pool->pool_no)) + return NULL; // lookup-gap if (!build_pool_json_add(obj, "lookup-gap", pool->lookup_gap, profile->lookup_gap, default_profile.lookup_gap, pool->pool_no)) @@ -1338,6 +1374,10 @@ static json_t *build_profile_settings_json(json_t *object, struct profile *profi if (!build_profile_json_add(object, "device", profile->devices, default_profile.devices, isdefault, parentkey, profile->profile_no)) return NULL; + // kernelfile + if (!build_profile_json_add(object, "kernelfile", profile->algorithm.kernelfile, default_profile.algorithm.kernelfile, isdefault, parentkey, profile->profile_no)) + return NULL; + // lookup-gap if (!build_profile_json_add(object, "lookup-gap", profile->lookup_gap, default_profile.lookup_gap, isdefault, parentkey, profile->profile_no)) return NULL; diff --git a/config_parser.h b/config_parser.h index a662c977..0c3e2b2c 100644 --- a/config_parser.h +++ b/config_parser.h @@ -47,6 +47,7 @@ extern int total_profiles; extern char *set_default_algorithm(const char *arg); extern char *set_default_nfactor(const char *arg); extern char *set_default_devices(const char *arg); +extern char *set_default_kernelfile(const char *arg); extern char *set_default_lookup_gap(const char *arg); extern char *set_default_intensity(const char *arg); extern char *set_default_xintensity(const char *arg); @@ -67,6 +68,7 @@ extern char *set_default_worksize(const char *arg); extern char *set_profile_name(const char *arg); extern char *set_profile_algorithm(const char *arg); extern char *set_profile_devices(const char *arg); +extern char *set_profile_kernelfile(const char *arg); extern char *set_profile_lookup_gap(const char *arg); extern char *set_profile_intensity(const char *arg); extern char *set_profile_xintensity(const char *arg); diff --git a/ocl.c b/ocl.c index 9f987e5a..ea458143 100644 --- a/ocl.c +++ b/ocl.c @@ -298,8 +298,9 @@ _clState *initCl(unsigned int gpu, char *name, size_t nameSize, algorithm_t *alg char filename[255]; char strbuf[32]; - sprintf(strbuf, "%s.cl", cgpu->algorithm.name); + sprintf(strbuf, "%s.cl", (!empty_string(cgpu->algorithm.kernelfile) ? cgpu->algorithm.kernelfile : cgpu->algorithm.name)); strcpy(filename, strbuf); + applog(LOG_DEBUG, "Using source file %s", filename); /* For some reason 2 vectors is still better even if the card says * otherwise, and many cards lie about their max so use 256 as max @@ -382,7 +383,7 @@ _clState *initCl(unsigned int gpu, char *name, size_t nameSize, algorithm_t *alg build_data->opencl_version = get_opencl_version(devices[gpu]); build_data->patch_bfi = needs_bfi_patch(build_data); - strcpy(build_data->binary_filename, cgpu->algorithm.name); + strcpy(build_data->binary_filename, (!empty_string(cgpu->algorithm.kernelfile) ? cgpu->algorithm.kernelfile : cgpu->algorithm.name)); strcat(build_data->binary_filename, name); if (clState->goffset) strcat(build_data->binary_filename, "g"); @@ -392,6 +393,7 @@ _clState *initCl(unsigned int gpu, char *name, size_t nameSize, algorithm_t *alg algorithm->set_compile_options(build_data, cgpu, algorithm); strcat(build_data->binary_filename, ".bin"); + applog(LOG_DEBUG, "Using binary file %s", build_data->binary_filename); // Load program from file or build it if it doesn't exist if (!(clState->program = load_opencl_binary_kernel(build_data))) { diff --git a/sgminer.c b/sgminer.c index e76a7a01..0ad3fe69 100644 --- a/sgminer.c +++ b/sgminer.c @@ -797,6 +797,16 @@ static char *set_pool_devices(const char *arg) return NULL; } +static char *set_pool_kernelfile(const char *arg) +{ + struct pool *pool = get_current_pool(); + + applog(LOG_DEBUG, "Setting pool %i algorithm kernel file to %s", pool->pool_no, arg); + pool->algorithm.kernelfile = arg; + + return NULL; +} + static char *set_pool_lookup_gap(const char *arg) { struct pool *pool = get_current_pool(); @@ -1421,6 +1431,9 @@ struct opt_table opt_config_table[] = { OPT_WITH_ARG("--keccak-unroll", set_int_0_to_9999, opt_show_intval, &opt_keccak_unroll, "Set SPH_KECCAK_UNROLL for Xn derived algorithms (Default: 0)"), + OPT_WITH_ARG("--kernelfile", + set_default_kernelfile, NULL, NULL, + "Set the algorithm kernel source file (without file extension)."), OPT_WITH_ARG("--lookup-gap", set_default_lookup_gap, NULL, NULL, "Set GPU lookup gap for scrypt mining, comma separated"), @@ -1523,6 +1536,9 @@ struct opt_table opt_config_table[] = { OPT_WITH_ARG("--pool-device", set_pool_devices, NULL, NULL, "Select devices to use with pool, one value, range and/or comma separated (e.g. 0-2,4) default: all"), + OPT_WITH_ARG("--pool-kernelfile", + set_pool_kernelfile, NULL, NULL, + "Set the pool's algorithm kernel source file (without file extension)."), OPT_WITH_ARG("--pool-lookup-gap", set_pool_lookup_gap, NULL, NULL, "Set Pool GPU lookup gap for scrypt mining, comma separated"), @@ -1581,6 +1597,9 @@ struct opt_table opt_config_table[] = { OPT_WITH_ARG("--profile-device", set_profile_devices, NULL, NULL, "Select devices to use with profile, one value, range and/or comma separated (e.g. 0-2,4) default: all"), + OPT_WITH_ARG("--profile-kernelfile", + set_profile_kernelfile, NULL, NULL, + "Set the profile's algorithm kernel source file (without file extension)."), OPT_WITH_ARG("--profile-lookup-gap", set_profile_lookup_gap, NULL, NULL, "Set Profile GPU lookup gap for scrypt mining, comma separated"), @@ -2865,9 +2884,10 @@ static void show_hash(struct work *work, char *hashshow) work->block? " BLOCK!" : ""); } else { swab256(rhash, work->hash); - for (ofs = 0; ofs <= 28; ofs ++) { - if (rhash[ofs]) + for (ofs = 0; ofs <= 28; ++ofs) { + if (rhash[ofs]) { break; + } } hash32 = (uint32_t *)(rhash + ofs); h32 = be32toh(*hash32); @@ -3277,9 +3297,9 @@ static void calc_diff(struct work *work, double known) struct sgminer_pool_stats *pool_stats = &(work->pool->sgminer_pool_stats); double difficulty; - if (known) + if (known) { work->work_difficulty = known; - else { + } else { double d64, dcut64; d64 = work->pool->algorithm.diff_multiplier2 * truediffone;