Iterate over all platforms displaying their information and number of devices when --ndevs is called.
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
diff --git a/device-gpu.c b/device-gpu.c
index f8813b2..8dfe92d 100644
--- a/device-gpu.c
+++ b/device-gpu.c
@@ -425,7 +425,7 @@ char *print_ndevs_and_exit(int *ndevs)
opt_log_output = true;
opencl_api.api_detect();
clear_adl(*ndevs);
- applog(LOG_INFO, "%i GPU devices detected", *ndevs);
+ applog(LOG_INFO, "%i GPU devices max detected", *ndevs);
exit(*ndevs);
}
#endif
diff --git a/ocl.c b/ocl.c
index d976ef7..7b5f901 100644
--- a/ocl.c
+++ b/ocl.c
@@ -68,65 +68,60 @@ char *file_contents(const char *filename, int *length)
return (char*)buffer;
}
-int clDevicesNum() {
+int clDevicesNum(void) {
cl_int status;
char pbuff[256];
cl_uint numDevices;
cl_uint numPlatforms;
+ cl_platform_id *platforms;
cl_platform_id platform = NULL;
+ unsigned int most_devices = 0, i;
status = clGetPlatformIDs(0, NULL, &numPlatforms);
/* If this fails, assume no GPUs. */
if (status != CL_SUCCESS) {
- applog(LOG_INFO, "clGetPlatformsIDs failed (no GPU?)");
- return 0;
- }
-
- if (numPlatforms > 0) {
- cl_platform_id* platforms = (cl_platform_id *)malloc(numPlatforms*sizeof(cl_platform_id));
- unsigned int i;
-
- status = clGetPlatformIDs(numPlatforms, platforms, NULL);
- if (status != CL_SUCCESS) {
- applog(LOG_ERR, "Error: Getting Platform Ids. (clGetPlatformsIDs)");
- return -1;
- }
-
- 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 -1;
- }
- platform = platforms[i];
- if (!strcmp(pbuff, "Advanced Micro Devices, Inc.") ||
- !strcmp(pbuff, "NVIDIA Corporation"))
- break;
- }
- free(platforms);
+ applog(LOG_ERR, "clGetPlatformsIDs failed (no OpenCL SDK installed?)");
+ return -1;
}
- if (platform == NULL) {
- perror("NULL platform found!\n");
+ if (numPlatforms == 0) {
+ applog(LOG_ERR, "clGetPlatformsIDs returned no platforms (no OpenCL SDK installed?)");
return -1;
}
- applog(LOG_INFO, "CL Platform vendor: %s", pbuff);
- status = clGetPlatformInfo(platform, CL_PLATFORM_NAME, sizeof(pbuff), pbuff, NULL);
- if (status == CL_SUCCESS)
- applog(LOG_INFO, "CL Platform name: %s", pbuff);
- status = clGetPlatformInfo(platform, CL_PLATFORM_VERSION, sizeof(pbuff), pbuff, NULL);
- if (status == CL_SUCCESS)
- applog(LOG_INFO, "CL Platform version: %s", pbuff);
-
- status = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 0, NULL, &numDevices);
+ platforms = (cl_platform_id *)alloca(numPlatforms*sizeof(cl_platform_id));
+ status = clGetPlatformIDs(numPlatforms, platforms, NULL);
if (status != CL_SUCCESS) {
- applog(LOG_ERR, "Error: Getting Device IDs (num)");
+ applog(LOG_ERR, "Error: Getting Platform Ids. (clGetPlatformsIDs)");
return -1;
}
- return numDevices;
+ 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 -1;
+ }
+ platform = platforms[i];
+ applog(LOG_INFO, "CL Platform vendor: %s", pbuff);
+ status = clGetPlatformInfo(platform, CL_PLATFORM_NAME, sizeof(pbuff), pbuff, NULL);
+ if (status == CL_SUCCESS)
+ applog(LOG_INFO, "CL Platform name: %s", pbuff);
+ status = clGetPlatformInfo(platform, CL_PLATFORM_VERSION, sizeof(pbuff), pbuff, NULL);
+ if (status == CL_SUCCESS)
+ applog(LOG_INFO, "CL Platform version: %s", 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);
+ if (numDevices > most_devices)
+ most_devices = numDevices;
+ }
+
+ return most_devices;
}
static int advance(char **area, unsigned *remaining, const char *marker)
diff --git a/ocl.h b/ocl.h
index 22c0d83..171af1b 100644
--- a/ocl.h
+++ b/ocl.h
@@ -24,7 +24,7 @@ typedef struct {
} _clState;
extern char *file_contents(const char *filename, int *length);
-extern int clDevicesNum();
+extern int clDevicesNum(void);
extern _clState *initCl(unsigned int gpu, char *name, size_t nameSize);
#endif /* HAVE_OPENCL */
#endif /* __OCL_H__ */