Allow the OpenCL platform ID to be chosen with --gpu-platform.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
diff --git a/cgminer.c b/cgminer.c
index adbdc40..d1de12f 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -641,10 +641,13 @@ static struct opt_table opt_config_table[] = {
OPT_WITH_ARG("--expiry|-E",
set_int_0_to_9999, opt_show_intval, &opt_expiry,
"Upper bound on how many seconds after getting work we consider a share from it stale"),
-#ifdef HAVE_OPENCL
OPT_WITHOUT_ARG("--failover-only",
opt_set_bool, &opt_fail_only,
"Don't leak work to backup pools when primary pool is lagging"),
+#ifdef HAVE_OPENCL
+ OPT_WITH_ARG("--gpu-platform",
+ set_int_0_to_9999, opt_show_intval, &opt_platform_id,
+ "Select OpenCL platform ID to use for GPU mining"),
OPT_WITH_ARG("--gpu-threads|-g",
set_int_1_to_10, opt_show_intval, &opt_g_threads,
"Number of threads per GPU (1 - 10)"),
@@ -938,7 +941,7 @@ static struct opt_table opt_cmdline_table[] = {
#ifdef HAVE_OPENCL
OPT_WITHOUT_ARG("--ndevs|-n",
print_ndevs_and_exit, &nDevs,
- "Display number of detected GPUs, OpenCL information, and exit"),
+ "Display number of detected GPUs, OpenCL platform information, and exit"),
#endif
OPT_WITHOUT_ARG("--version|-V",
opt_version_and_exit, packagename,
diff --git a/ocl.c b/ocl.c
index 7b5f901..76ceb60 100644
--- a/ocl.c
+++ b/ocl.c
@@ -29,6 +29,7 @@
extern int opt_vectors;
extern int opt_worksize;
+int opt_platform_id;
char *file_contents(const char *filename, int *length)
{
@@ -100,23 +101,22 @@ int clDevicesNum(void) {
status = clGetPlatformInfo( platforms[i], CL_PLATFORM_VENDOR, sizeof(pbuff), pbuff, NULL);
if (status != CL_SUCCESS) {
applog(LOG_ERR, "Error: Getting Platform Info. (clGetPlatformInfo)");
- free(platforms);
return -1;
}
platform = platforms[i];
- applog(LOG_INFO, "CL Platform vendor: %s", pbuff);
+ applog(LOG_INFO, "CL Platform %d vendor: %s", i, pbuff);
status = clGetPlatformInfo(platform, CL_PLATFORM_NAME, sizeof(pbuff), pbuff, NULL);
if (status == CL_SUCCESS)
- applog(LOG_INFO, "CL Platform name: %s", pbuff);
+ applog(LOG_INFO, "CL Platform %d name: %s", i, pbuff);
status = clGetPlatformInfo(platform, CL_PLATFORM_VERSION, sizeof(pbuff), pbuff, NULL);
if (status == CL_SUCCESS)
- applog(LOG_INFO, "CL Platform version: %s", pbuff);
+ applog(LOG_INFO, "CL Platform %d version: %s", i, pbuff);
status = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 0, NULL, &numDevices);
if (status != CL_SUCCESS) {
applog(LOG_ERR, "Error: Getting Device IDs (num)");
return -1;
}
- applog(LOG_INFO, "Platform devices: %d", numDevices);
+ applog(LOG_INFO, "Platform %d devices: %d", i, numDevices);
if (numDevices > most_devices)
most_devices = numDevices;
}
@@ -189,11 +189,11 @@ _clState *initCl(unsigned int gpu, char *name, size_t nameSize)
_clState *clState = calloc(1, sizeof(_clState));
bool patchbfi = false, prog_built = false;
cl_platform_id platform = NULL;
+ cl_platform_id* platforms;
cl_device_id *devices;
cl_uint numPlatforms;
cl_uint numDevices;
char pbuff[256];
- unsigned int i;
cl_int status;
status = clGetPlatformIDs(0, NULL, &numPlatforms);
@@ -202,29 +202,24 @@ _clState *initCl(unsigned int gpu, char *name, size_t nameSize)
return NULL;
}
- if (numPlatforms > 0) {
- cl_platform_id* platforms = (cl_platform_id *)malloc(numPlatforms*sizeof(cl_platform_id));
+ platforms = (cl_platform_id *)alloca(numPlatforms*sizeof(cl_platform_id));
+ status = clGetPlatformIDs(numPlatforms, platforms, NULL);
+ if (status != CL_SUCCESS) {
+ applog(LOG_ERR, "Error: Getting Platform Ids. (clGetPlatformsIDs)");
+ return NULL;
+ }
- status = clGetPlatformIDs(numPlatforms, platforms, NULL);
- if (status != CL_SUCCESS) {
- applog(LOG_ERR, "Error: Getting Platform Ids. (clGetPlatformsIDs)");
- return NULL;
- }
+ if (opt_platform_id >= numPlatforms) {
+ applog(LOG_ERR, "Specified platform that does not exist");
+ return NULL;
+ }
- for(i = 0; i < numPlatforms; ++i) {
- status = clGetPlatformInfo( platforms[i], CL_PLATFORM_VENDOR, sizeof(pbuff), pbuff, NULL);
- if (status != CL_SUCCESS) {
- applog(LOG_ERR, "Error: Getting Platform Info. (clGetPlatformInfo)");
- free(platforms);
- return NULL;
- }
- platform = platforms[i];
- if (!strcmp(pbuff, "Advanced Micro Devices, Inc.") ||
- !strcmp(pbuff, "NVIDIA Corporation"))
- break;
- }
- free(platforms);
+ status = clGetPlatformInfo(platforms[opt_platform_id], CL_PLATFORM_VENDOR, sizeof(pbuff), pbuff, NULL);
+ if (status != CL_SUCCESS) {
+ applog(LOG_ERR, "Error: Getting Platform Info. (clGetPlatformInfo)");
+ return NULL;
}
+ platform = platforms[opt_platform_id];
if (platform == NULL) {
perror("NULL platform found!\n");
diff --git a/ocl.h b/ocl.h
index 171af1b..d52bfce 100644
--- a/ocl.h
+++ b/ocl.h
@@ -26,5 +26,6 @@ typedef struct {
extern char *file_contents(const char *filename, int *length);
extern int clDevicesNum(void);
extern _clState *initCl(unsigned int gpu, char *name, size_t nameSize);
+extern int opt_platform_id;
#endif /* HAVE_OPENCL */
#endif /* __OCL_H__ */