Browse Source

opencl: Replace (and deprecate) --no-opencl-binaries option, with --set opencl:binary=no

Luke Dashjr 12 years ago
parent
commit
4505195031
5 changed files with 67 additions and 15 deletions
  1. 0 1
      README
  2. 27 0
      driver-opencl.c
  3. 9 0
      driver-opencl.h
  4. 10 2
      miner.c
  5. 21 12
      ocl.c

+ 0 - 1
README

@@ -251,7 +251,6 @@ Options for both config file and command line:
 --no-restart        Do not attempt to restart devices that hang
 --no-restart        Do not attempt to restart devices that hang
 --no-stratum        Disable Stratum detection
 --no-stratum        Disable Stratum detection
 --no-submit-stale   Don't submit shares if they are detected as stale
 --no-submit-stale   Don't submit shares if they are detected as stale
---no-opencl-binaries Don't attempt to use or save OpenCL kernel binaries
 --no-unicode        Don't use Unicode characters in TUI
 --no-unicode        Don't use Unicode characters in TUI
 --noncelog <arg>    Create log of all nonces found
 --noncelog <arg>    Create log of all nonces found
 --pass|-p <arg>     Password for bitcoin JSON-RPC server
 --pass|-p <arg>     Password for bitcoin JSON-RPC server

+ 27 - 0
driver-opencl.c

@@ -406,6 +406,31 @@ const char *set_kernel(char *arg)
 }
 }
 #endif
 #endif
 
 
+static
+const char *opencl_init_binary(struct cgpu_info * const proc, const char * const optname, const char * const newvalue, char * const replybuf, enum bfg_set_device_replytype * const out_success)
+{
+	struct opencl_device_data * const data = proc->device_data;
+	
+	if (!(strcasecmp(newvalue, "no") && strcasecmp(newvalue, "never") && strcasecmp(newvalue, "none")))
+		data->opt_opencl_binaries = OBU_NONE;
+	else
+	if (!(strcasecmp(newvalue, "load") && strcasecmp(newvalue, "read")))
+		data->opt_opencl_binaries = OBU_LOAD;
+	else
+	if (!(strcasecmp(newvalue, "save") && strcasecmp(newvalue, "write")))
+		data->opt_opencl_binaries = OBU_SAVE;
+	else
+	if (!(strcasecmp(newvalue, "yes") && strcasecmp(newvalue, "always") && strcasecmp(newvalue, "both")))
+		data->opt_opencl_binaries = OBU_LOADSAVE;
+	else
+	if (!(strcasecmp(newvalue, "default")))
+		data->opt_opencl_binaries = OBU_DEFAULT;
+	else
+		return "Invalid value passed to opencl binary";
+	
+	return NULL;
+}
+
 #ifdef HAVE_ADL
 #ifdef HAVE_ADL
 /* This function allows us to map an adl device to an opencl device for when
 /* This function allows us to map an adl device to an opencl device for when
  * simple enumeration has failed to match them. */
  * simple enumeration has failed to match them. */
@@ -1781,6 +1806,7 @@ static const struct bfg_set_device_definition opencl_set_device_funcs_probe[] =
 	{"threads", opencl_init_gpu_threads},
 	{"threads", opencl_init_gpu_threads},
 	{"vector", opencl_init_vector},
 	{"vector", opencl_init_vector},
 	{"work_size", opencl_init_worksize},
 	{"work_size", opencl_init_worksize},
+	{"binary", opencl_init_binary},
 #ifdef HAVE_ADL
 #ifdef HAVE_ADL
 	{"adl_mapping", opencl_init_gpu_map},
 	{"adl_mapping", opencl_init_gpu_map},
 	{"clock", opencl_init_gpu_engine},
 	{"clock", opencl_init_gpu_engine},
@@ -1805,6 +1831,7 @@ static const struct bfg_set_device_definition opencl_set_device_funcs[] = {
 	{"threads", opencl_cannot_set, "Number of threads"},
 	{"threads", opencl_cannot_set, "Number of threads"},
 	{"vector", opencl_cannot_set, ""},
 	{"vector", opencl_cannot_set, ""},
 	{"work_size", opencl_cannot_set, ""},
 	{"work_size", opencl_cannot_set, ""},
+	{"binary", opencl_cannot_set, ""},
 #ifdef HAVE_ADL
 #ifdef HAVE_ADL
 	{"adl_mapping", opencl_cannot_set, "Map to ADL device"},
 	{"adl_mapping", opencl_cannot_set, "Map to ADL device"},
 	{"clock", opencl_set_gpu_engine, "GPU engine clock"},
 	{"clock", opencl_set_gpu_engine, "GPU engine clock"},

+ 9 - 0
driver-opencl.h

@@ -10,6 +10,14 @@
 
 
 #include "miner.h"
 #include "miner.h"
 
 
+enum opencl_binary_usage {
+	OBU_DEFAULT  = 0,
+	OBU_LOAD     = 1,
+	OBU_SAVE     = 2,
+	OBU_LOADSAVE = 3,
+	OBU_NONE     = 4,
+};
+
 struct opencl_device_data {
 struct opencl_device_data {
 	bool mapped;
 	bool mapped;
 	int virtual_gpu;
 	int virtual_gpu;
@@ -23,6 +31,7 @@ struct opencl_device_data {
 	enum cl_kernels kernel;
 	enum cl_kernels kernel;
 	cl_ulong max_alloc;
 	cl_ulong max_alloc;
 	
 	
+	enum opencl_binary_usage opt_opencl_binaries;
 #ifdef USE_SCRYPT
 #ifdef USE_SCRYPT
 	int opt_lg, lookup_gap;
 	int opt_lg, lookup_gap;
 	size_t opt_tc, thread_concurrency;
 	size_t opt_tc, thread_concurrency;

+ 10 - 2
miner.c

@@ -1747,6 +1747,14 @@ char *set_temp_target(char *arg)
 	return NULL;
 	return NULL;
 }
 }
 
 
+static
+char *set_no_opencl_binaries(__maybe_unused void * const dummy)
+{
+	applog(LOG_WARNING, "The --no-opencl-binaries option is deprecated! Use --set-device OCL:binary=no");
+	add_set_device_option("OCL:binary=no");
+	return NULL;
+}
+
 static char *set_api_allow(const char *arg)
 static char *set_api_allow(const char *arg)
 {
 {
 	opt_set_charp(arg, &opt_api_allow);
 	opt_set_charp(arg, &opt_api_allow);
@@ -2192,8 +2200,8 @@ static struct opt_table opt_config_table[] = {
 		        "Don't submit shares if they are detected as stale"),
 		        "Don't submit shares if they are detected as stale"),
 #ifdef HAVE_OPENCL
 #ifdef HAVE_OPENCL
 	OPT_WITHOUT_ARG("--no-opencl-binaries",
 	OPT_WITHOUT_ARG("--no-opencl-binaries",
-	                opt_set_invbool, &opt_opencl_binaries,
-	                "Don't attempt to use or save OpenCL kernel binaries"),
+	                set_no_opencl_binaries, NULL,
+	                opt_hidden),
 #endif
 #endif
 	OPT_WITHOUT_ARG("--no-unicode",
 	OPT_WITHOUT_ARG("--no-unicode",
 #ifdef USE_UNICODE
 #ifdef USE_UNICODE

+ 21 - 12
ocl.c

@@ -209,12 +209,6 @@ CL_API_ENTRY cl_int CL_API_CALL
                        cl_event *       /* event */) CL_API_SUFFIX__VERSION_1_0;
                        cl_event *       /* event */) CL_API_SUFFIX__VERSION_1_0;
 
 
 int opt_platform_id = -1;
 int opt_platform_id = -1;
-#ifdef __APPLE__
-// Apple OpenCL doesn't like using binaries this way
-bool opt_opencl_binaries;
-#else
-bool opt_opencl_binaries = true;
-#endif
 
 
 char *file_contents(const char *filename, int *length)
 char *file_contents(const char *filename, int *length)
 {
 {
@@ -393,7 +387,7 @@ _clState *initCl(unsigned int gpu, char *name, size_t nameSize)
 {
 {
 	_clState *clState = calloc(1, sizeof(_clState));
 	_clState *clState = calloc(1, sizeof(_clState));
 	bool patchbfi = false, prog_built = false;
 	bool patchbfi = false, prog_built = false;
-	bool usebinary = opt_opencl_binaries, ismesa = false;
+	bool ismesa = false;
 	struct cgpu_info *cgpu = &gpus[gpu];
 	struct cgpu_info *cgpu = &gpus[gpu];
 	struct opencl_device_data * const data = cgpu->device_data;
 	struct opencl_device_data * const data = cgpu->device_data;
 	cl_platform_id platform = NULL;
 	cl_platform_id platform = NULL;
@@ -586,14 +580,29 @@ _clState *initCl(unsigned int gpu, char *name, size_t nameSize)
 			minor = 0;
 			minor = 0;
 		if (major < 10 || (major == 10 && minor < 1))
 		if (major < 10 || (major == 10 && minor < 1))
 		{
 		{
-			applog(LOG_DEBUG, "Mesa OpenCL platform detected (v%ld.%ld), disabling OpenCL kernel binaries and bitalign", major, minor);
+			if (data->opt_opencl_binaries == OBU_DEFAULT)
+			{
+				applog(LOG_DEBUG, "Mesa OpenCL platform detected (v%ld.%ld), disabling OpenCL kernel binaries and bitalign", major, minor);
+				data->opt_opencl_binaries = OBU_NONE;
+			}
+			else
+				applog(LOG_DEBUG, "Mesa OpenCL platform detected (v%ld.%ld), disabling bitalign", major, minor);
 			clState->hasBitAlign = false;
 			clState->hasBitAlign = false;
-			usebinary = false;
 		}
 		}
 		else
 		else
 			applog(LOG_DEBUG, "Mesa OpenCL platform detected (v%ld.%ld)", major, minor);
 			applog(LOG_DEBUG, "Mesa OpenCL platform detected (v%ld.%ld)", major, minor);
 		ismesa = true;
 		ismesa = true;
 	}
 	}
+	
+	if (data->opt_opencl_binaries == OBU_DEFAULT)
+	{
+#ifdef __APPLE__
+		// Apple OpenCL doesn't like using binaries this way
+		data->opt_opencl_binaries = OBU_NONE;
+#else
+		data->opt_opencl_binaries = OBU_LOADSAVE;
+#endif
+	}
 
 
 	/* Create binary filename based on parameters passed to opencl
 	/* Create binary filename based on parameters passed to opencl
 	 * compiler to ensure we only load a binary that matches what would
 	 * compiler to ensure we only load a binary that matches what would
@@ -775,7 +784,7 @@ _clState *initCl(unsigned int gpu, char *name, size_t nameSize)
 	applog(LOG_DEBUG, "OCL%2u: Configured OpenCL kernel name: %s", gpu, binaryfilename);
 	applog(LOG_DEBUG, "OCL%2u: Configured OpenCL kernel name: %s", gpu, binaryfilename);
 	strcat(binaryfilename, ".bin");
 	strcat(binaryfilename, ".bin");
 	
 	
-	if (!usebinary)
+	if (!(data->opt_opencl_binaries & OBU_LOAD))
 		goto build;
 		goto build;
 
 
 	binaryfile = fopen(binaryfilename, "rb");
 	binaryfile = fopen(binaryfilename, "rb");
@@ -877,7 +886,7 @@ build:
 		applog(LOG_DEBUG, "cl_amd_media_ops not found, will not set BITALIGN");
 		applog(LOG_DEBUG, "cl_amd_media_ops not found, will not set BITALIGN");
 
 
 	if (patchbfi) {
 	if (patchbfi) {
-		if (usebinary)
+		if (data->opt_opencl_binaries == OBU_LOADSAVE)
 		{
 		{
 			strcat(CompilerOptions, " -D BFI_INT");
 			strcat(CompilerOptions, " -D BFI_INT");
 			applog(LOG_DEBUG, "BFI_INT patch requiring device found, patched source with BFI_INT");
 			applog(LOG_DEBUG, "BFI_INT patch requiring device found, patched source with BFI_INT");
@@ -913,7 +922,7 @@ build:
 
 
 	prog_built = true;
 	prog_built = true;
 	
 	
-	if (!usebinary)
+	if (!(data->opt_opencl_binaries & OBU_SAVE))
 		goto built;
 		goto built;
 
 
 	status = clGetProgramInfo(clState->program, CL_PROGRAM_NUM_DEVICES, sizeof(cl_uint), &cpnd, NULL);
 	status = clGetProgramInfo(clState->program, CL_PROGRAM_NUM_DEVICES, sizeof(cl_uint), &cpnd, NULL);