From a53a6e52da303224077b17b0471703be4c4b4a3c Mon Sep 17 00:00:00 2001 From: samr7 Date: Mon, 1 Aug 2011 22:26:52 -0700 Subject: [PATCH] Add safe mode option to disable problematic optimizations. With safe mode, oclvanitygen works with AMD's CPU OpenCL device. --- oclvanitygen.c | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/oclvanitygen.c b/oclvanitygen.c index 1f039e9..e33c98a 100644 --- a/oclvanitygen.c +++ b/oclvanitygen.c @@ -422,8 +422,10 @@ vg_ocl_hash_program(vg_ocl_context_t *vocp, const char *opts, MD5_Update(&ctx, str, strlen(str) + 1); str = vg_ocl_device_getstr(vocp->voc_ocldid, CL_DEVICE_NAME); MD5_Update(&ctx, str, strlen(str) + 1); - MD5_Update(&ctx, opts, strlen(opts) + 1); - MD5_Update(&ctx, program, size); + if (opts) + MD5_Update(&ctx, opts, strlen(opts) + 1); + if (size) + MD5_Update(&ctx, program, size); MD5_Final(hash_out, &ctx); } @@ -616,7 +618,8 @@ vg_ocl_context_callback(const char *errinfo, } int -vg_ocl_init(vg_context_t *vcp, vg_ocl_context_t *vocp, cl_device_id did) +vg_ocl_init(vg_context_t *vcp, vg_ocl_context_t *vocp, cl_device_id did, + int safe_mode) { cl_int ret; const char *vend, *options; @@ -633,7 +636,7 @@ vg_ocl_init(vg_context_t *vcp, vg_ocl_context_t *vocp, cl_device_id did) if (vcp->vc_verbose > 1) vg_ocl_dump_info(vocp); - if (!vg_ocl_check_driver(vocp)) { + if (!vg_ocl_check_driver(vocp) && (vcp->vc_verbose > 0)) { char yesbuf[16]; printf("Type 'yes' to continue: "); fflush(stdout); @@ -661,9 +664,12 @@ vg_ocl_init(vg_context_t *vcp, vg_ocl_context_t *vocp, cl_device_id did) } options = "-DUNROLL_MAX=16"; - vend = vg_ocl_device_getstr(did, CL_DEVICE_VENDOR); - if (!strcmp(vend, "Advanced Micro Devices, Inc.") || + + if (safe_mode) { + options = NULL; + + } else if (!strcmp(vend, "Advanced Micro Devices, Inc.") || !strcmp(vend, "AMD")) { /* Radeons do better with less flow control */ options = "-DUNROLL_MAX=16 -DVERY_EXPENSIVE_BRANCHES"; @@ -1335,8 +1341,8 @@ out: */ void * -vg_opencl_loop(vg_context_t *vcp, cl_device_id did, int worksize, - int nrows, int ncols, int invsize) +vg_opencl_loop(vg_context_t *vcp, cl_device_id did, int safe_mode, + int worksize, int nrows, int ncols, int invsize) { int i; int round, full_worksize; @@ -1363,7 +1369,7 @@ vg_opencl_loop(vg_context_t *vcp, cl_device_id did, int worksize, struct timeval tvstart; - if (!vg_ocl_init(vcp, &ctx, did)) + if (!vg_ocl_init(vcp, &ctx, did, safe_mode)) return NULL; pkey = vxcp->vxc_key; @@ -1983,11 +1989,12 @@ main(int argc, char **argv) int nrows = 0, ncols = 0; int invsize = 0; int remove_on_match = 1; + int safe_mode = 0; vg_context_t *vcp = NULL; cl_device_id did; const char *result_file = NULL; - while ((opt = getopt(argc, argv, "vqrikNTp:d:w:g:b:h?f:o:s:")) != -1) { + while ((opt = getopt(argc, argv, "vqrikNTp:d:w:g:b:Sh?f:o:s:")) != -1) { switch (opt) { case 'v': verbose = 2; @@ -2049,6 +2056,9 @@ main(int argc, char **argv) return 1; } break; + case 'S': + safe_mode = 1; + break; case 'f': if (fp) { printf("Multiple files specified\n"); @@ -2161,6 +2171,7 @@ main(int argc, char **argv) return 1; } - vg_opencl_loop(vcp, did, worksize, nrows, ncols, invsize); + vg_opencl_loop(vcp, did, safe_mode, + worksize, nrows, ncols, invsize); return 0; }