Browse Source

Allow the OpenCL platform ID to be chosen with --gpu-platform.

nfactor-troky
ckolivas 13 years ago
parent
commit
53c1e9ae37
  1. 7
      cgminer.c
  2. 33
      ocl.c
  3. 1
      ocl.h

7
cgminer.c

@ -641,10 +641,13 @@ static struct opt_table opt_config_table[] = {
OPT_WITH_ARG("--expiry|-E", OPT_WITH_ARG("--expiry|-E",
set_int_0_to_9999, opt_show_intval, &opt_expiry, 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"), "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_WITHOUT_ARG("--failover-only",
opt_set_bool, &opt_fail_only, opt_set_bool, &opt_fail_only,
"Don't leak work to backup pools when primary pool is lagging"), "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", OPT_WITH_ARG("--gpu-threads|-g",
set_int_1_to_10, opt_show_intval, &opt_g_threads, set_int_1_to_10, opt_show_intval, &opt_g_threads,
"Number of threads per GPU (1 - 10)"), "Number of threads per GPU (1 - 10)"),
@ -938,7 +941,7 @@ static struct opt_table opt_cmdline_table[] = {
#ifdef HAVE_OPENCL #ifdef HAVE_OPENCL
OPT_WITHOUT_ARG("--ndevs|-n", OPT_WITHOUT_ARG("--ndevs|-n",
print_ndevs_and_exit, &nDevs, 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 #endif
OPT_WITHOUT_ARG("--version|-V", OPT_WITHOUT_ARG("--version|-V",
opt_version_and_exit, packagename, opt_version_and_exit, packagename,

33
ocl.c

@ -29,6 +29,7 @@
extern int opt_vectors; extern int opt_vectors;
extern int opt_worksize; extern int opt_worksize;
int opt_platform_id;
char *file_contents(const char *filename, int *length) 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); status = clGetPlatformInfo( platforms[i], CL_PLATFORM_VENDOR, sizeof(pbuff), pbuff, NULL);
if (status != CL_SUCCESS) { if (status != CL_SUCCESS) {
applog(LOG_ERR, "Error: Getting Platform Info. (clGetPlatformInfo)"); applog(LOG_ERR, "Error: Getting Platform Info. (clGetPlatformInfo)");
free(platforms);
return -1; return -1;
} }
platform = platforms[i]; 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); status = clGetPlatformInfo(platform, CL_PLATFORM_NAME, sizeof(pbuff), pbuff, NULL);
if (status == CL_SUCCESS) 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); status = clGetPlatformInfo(platform, CL_PLATFORM_VERSION, sizeof(pbuff), pbuff, NULL);
if (status == CL_SUCCESS) 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); status = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 0, NULL, &numDevices);
if (status != CL_SUCCESS) { if (status != CL_SUCCESS) {
applog(LOG_ERR, "Error: Getting Device IDs (num)"); applog(LOG_ERR, "Error: Getting Device IDs (num)");
return -1; return -1;
} }
applog(LOG_INFO, "Platform devices: %d", numDevices); applog(LOG_INFO, "Platform %d devices: %d", i, numDevices);
if (numDevices > most_devices) if (numDevices > most_devices)
most_devices = numDevices; most_devices = numDevices;
} }
@ -189,11 +189,11 @@ _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;
cl_platform_id platform = NULL; cl_platform_id platform = NULL;
cl_platform_id* platforms;
cl_device_id *devices; cl_device_id *devices;
cl_uint numPlatforms; cl_uint numPlatforms;
cl_uint numDevices; cl_uint numDevices;
char pbuff[256]; char pbuff[256];
unsigned int i;
cl_int status; cl_int status;
status = clGetPlatformIDs(0, NULL, &numPlatforms); status = clGetPlatformIDs(0, NULL, &numPlatforms);
@ -202,29 +202,24 @@ _clState *initCl(unsigned int gpu, char *name, size_t nameSize)
return NULL; return NULL;
} }
if (numPlatforms > 0) { platforms = (cl_platform_id *)alloca(numPlatforms*sizeof(cl_platform_id));
cl_platform_id* platforms = (cl_platform_id *)malloc(numPlatforms*sizeof(cl_platform_id));
status = clGetPlatformIDs(numPlatforms, platforms, NULL); status = clGetPlatformIDs(numPlatforms, platforms, NULL);
if (status != CL_SUCCESS) { if (status != CL_SUCCESS) {
applog(LOG_ERR, "Error: Getting Platform Ids. (clGetPlatformsIDs)"); applog(LOG_ERR, "Error: Getting Platform Ids. (clGetPlatformsIDs)");
return NULL; return NULL;
} }
for(i = 0; i < numPlatforms; ++i) { if (opt_platform_id >= numPlatforms) {
status = clGetPlatformInfo( platforms[i], CL_PLATFORM_VENDOR, sizeof(pbuff), pbuff, NULL); applog(LOG_ERR, "Specified platform that does not exist");
return NULL;
}
status = clGetPlatformInfo(platforms[opt_platform_id], CL_PLATFORM_VENDOR, sizeof(pbuff), pbuff, NULL);
if (status != CL_SUCCESS) { if (status != CL_SUCCESS) {
applog(LOG_ERR, "Error: Getting Platform Info. (clGetPlatformInfo)"); applog(LOG_ERR, "Error: Getting Platform Info. (clGetPlatformInfo)");
free(platforms);
return NULL; return NULL;
} }
platform = platforms[i]; platform = platforms[opt_platform_id];
if (!strcmp(pbuff, "Advanced Micro Devices, Inc.") ||
!strcmp(pbuff, "NVIDIA Corporation"))
break;
}
free(platforms);
}
if (platform == NULL) { if (platform == NULL) {
perror("NULL platform found!\n"); perror("NULL platform found!\n");

1
ocl.h

@ -26,5 +26,6 @@ typedef struct {
extern char *file_contents(const char *filename, int *length); extern char *file_contents(const char *filename, int *length);
extern int clDevicesNum(void); extern int clDevicesNum(void);
extern _clState *initCl(unsigned int gpu, char *name, size_t nameSize); extern _clState *initCl(unsigned int gpu, char *name, size_t nameSize);
extern int opt_platform_id;
#endif /* HAVE_OPENCL */ #endif /* HAVE_OPENCL */
#endif /* __OCL_H__ */ #endif /* __OCL_H__ */

Loading…
Cancel
Save