[Pkg-opencl-devel] [PATCH 5/6] Count GPU, CPU and ALL devices on newly inserted platforms

Giuseppe Bilotta giuseppe.bilotta at gmail.com
Tue May 19 06:00:44 UTC 2015


---
 icd_generator.rb |  8 ++++++--
 ocl_icd_loader.c | 27 +++++++++++++++++++++++++++
 2 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/icd_generator.rb b/icd_generator.rb
index 97f6fd1..8d536c9 100644
--- a/icd_generator.rb
+++ b/icd_generator.rb
@@ -366,11 +366,15 @@ struct vendor_icd {
   void *	dl_handle;
   clGetExtensionFunctionAddress_fn ext_fn_ptr;
 };
+
 struct platform_icd {
-  char *	 extension_suffix;
-  char *	 version;
+  char *	extension_suffix;
+  char *	version;
   struct vendor_icd *vicd;
   cl_platform_id pid;
+  cl_uint	ngpus; /* number of GPU devices */
+  cl_uint	ncpus; /* number of CPU devices */
+  cl_uint	ndevs; /* total number of devices, of all types */
 };
 
 EOF
diff --git a/ocl_icd_loader.c b/ocl_icd_loader.c
index 2fbb381..0d050d7 100644
--- a/ocl_icd_loader.c
+++ b/ocl_icd_loader.c
@@ -319,6 +319,32 @@ static char* _malloc_clGetPlatformInfo(clGetPlatformInfo_fn plt_info_ptr,
   RETURN_STR(param_value);
 }
 
+static void _count_devices(struct platform_icd *p) {
+  cl_int error;
+
+  /* Ensure they are 0 in case of errors */
+  p->ngpus = p->ncpus = p->ndevs = 0;
+
+  error = clGetDeviceIDs(p->pid, CL_DEVICE_TYPE_GPU, 0, NULL, &(p->ngpus));
+  if (error != CL_SUCCESS && error != CL_DEVICE_NOT_FOUND){
+    debug(D_WARN, "Error %s while counting GPU devices in platform %p",
+	  _clerror2string(error), p->pid);
+  }
+
+  error = clGetDeviceIDs(p->pid, CL_DEVICE_TYPE_CPU, 0, NULL, &(p->ncpus));
+  if (error != CL_SUCCESS && error != CL_DEVICE_NOT_FOUND){
+    debug(D_WARN, "Error %s while counting CPU devices in platform %p",
+	  _clerror2string(error), p->pid);
+  }
+
+  error = clGetDeviceIDs(p->pid, CL_DEVICE_TYPE_ALL, 0, NULL, &(p->ndevs));
+  if (error != CL_SUCCESS && error != CL_DEVICE_NOT_FOUND){
+    debug(D_WARN, "Error %s while counting ALL devices in platform %p",
+	  _clerror2string(error), p->pid);
+  }
+
+}
+
 static inline void _find_and_check_platforms(cl_uint num_icds) {
   cl_uint i;
   _num_icds = 0;
@@ -425,6 +451,7 @@ static inline void _find_and_check_platforms(cl_uint num_icds) {
 	free(param_value);
       }
 #endif
+      _count_devices(p);
       num_valid_platforms++;
       _num_picds++;
     }
-- 
2.1.2.766.gaa23a90




More information about the Pkg-opencl-devel mailing list