浏览代码

drivers/opencl: enable OpenCL on CPU when environment variable STARPU_OPENCL_ON_CPUS is defined with a positive value

Nathalie Furmento 13 年之前
父节点
当前提交
0982aa560d
共有 2 个文件被更改,包括 20 次插入1 次删除
  1. 18 1
      src/drivers/opencl/driver_opencl.c
  2. 2 0
      src/drivers/opencl/driver_opencl.h

+ 18 - 1
src/drivers/opencl/driver_opencl.c

@@ -346,13 +346,15 @@ void _starpu_opencl_init(void)
 	{
                 cl_platform_id platform_id[_STARPU_OPENCL_PLATFORM_MAX];
                 cl_uint nb_platforms;
-                cl_device_type device_type = CL_DEVICE_TYPE_GPU|CL_DEVICE_TYPE_ACCELERATOR;
                 cl_int err;
                 unsigned int i;
+                cl_device_type device_type = CL_DEVICE_TYPE_GPU|CL_DEVICE_TYPE_ACCELERATOR;
 
                 _STARPU_DEBUG("Initialising OpenCL\n");
 
                 // Get Platforms
+		if (starpu_get_env_number("STARPU_OPENCL_ON_CPUS") > 0)
+		     device_type |= CL_DEVICE_TYPE_CPU;
                 err = clGetPlatformIDs(_STARPU_OPENCL_PLATFORM_MAX, platform_id, &nb_platforms);
                 if (err != CL_SUCCESS) nb_platforms=0;
                 _STARPU_DEBUG("Platforms detected: %d\n", nb_platforms);
@@ -571,6 +573,21 @@ unsigned _starpu_opencl_get_device_count(void)
 	return nb_devices;
 }
 
+cl_device_type _starpu_opencl_get_device_type(int devid)
+{
+	int err;
+	cl_device_type type;
+
+	if (!init_done)
+		_starpu_opencl_init();
+
+	err = clGetDeviceInfo(devices[devid], CL_DEVICE_TYPE, sizeof(cl_device_type), &type, NULL);
+	if (err != CL_SUCCESS)
+		STARPU_OPENCL_REPORT_ERROR(err);
+
+	return type;
+}
+
 static int _starpu_opencl_execute_job(struct _starpu_job *j, struct _starpu_worker *args)
 {
 	int ret;

+ 2 - 0
src/drivers/opencl/driver_opencl.h

@@ -39,6 +39,8 @@ int _starpu_opencl_deinit_context(int devid);
 extern
 unsigned _starpu_opencl_get_device_count(void);
 
+extern
+cl_device_type _starpu_opencl_get_device_type(int devid);
 
 #if 0
 extern