Commit: 28f798f86ef965b22743bcefb94e8b9f9162c10a
Author: Sergey Sharybin
Date:   Fri Jun 5 14:13:59 2015 +0200
Branches: master
https://developer.blender.org/rB28f798f86ef965b22743bcefb94e8b9f9162c10a

Cycles: Initial support for OpenCL capabilities reports

For now it's just generic information, still need to expose memory, workgorup
sizes and so on.

===================================================================

M       intern/cycles/device/device.cpp
M       intern/cycles/device/device_cuda.cpp
M       intern/cycles/device/device_opencl.cpp

===================================================================

diff --git a/intern/cycles/device/device.cpp b/intern/cycles/device/device.cpp
index 0a4802c..5cad8e1 100644
--- a/intern/cycles/device/device.cpp
+++ b/intern/cycles/device/device.cpp
@@ -327,13 +327,10 @@ string Device::device_capabilities()
 #endif
 
 #ifdef WITH_OPENCL
-       /* TODO(sergey): Needs proper usable implementation. */
-       /*
        if(device_opencl_init()) {
                capabilities += "\nOpenCL device capabilities:\n";
                capabilities += device_opencl_capabilities();
        }
-       */
 #endif
 
        return capabilities;
diff --git a/intern/cycles/device/device_cuda.cpp 
b/intern/cycles/device/device_cuda.cpp
index 80a2dda..eb861d7 100644
--- a/intern/cycles/device/device_cuda.cpp
+++ b/intern/cycles/device/device_cuda.cpp
@@ -1163,7 +1163,7 @@ string device_cuda_capabilities(void)
                if(result != CUDA_ERROR_NO_DEVICE) {
                        return string("Error initializing CUDA: ") + 
cuewErrorString(result);
                }
-               return "No CUDA device found";
+               return "No CUDA device found\n";
        }
 
        int count;
diff --git a/intern/cycles/device/device_opencl.cpp 
b/intern/cycles/device/device_opencl.cpp
index 87d4ee9..6cda617 100644
--- a/intern/cycles/device/device_opencl.cpp
+++ b/intern/cycles/device/device_opencl.cpp
@@ -3437,8 +3437,77 @@ void device_opencl_info(vector<DeviceInfo>& devices)
 
 string device_opencl_capabilities(void)
 {
-       /* TODO(sergey): Not implemented yet. */
-       return "";
+       string result = "";
+       string error_msg = "";  /* Only used by opencl_assert(), but in the 
future
+                                * it could also be nicely reported to the 
console.
+                                */
+       cl_uint num_platforms = 0;
+       opencl_assert(clGetPlatformIDs(0, NULL, &num_platforms));
+       if(num_platforms == 0) {
+               return "No OpenCL platforms found\n";
+       }
+       result += string_printf("Number of platforms: %d\n", num_platforms);
+
+       vector<cl_platform_id> platform_ids;
+       platform_ids.resize(num_platforms);
+       opencl_assert(clGetPlatformIDs(num_platforms, &platform_ids[0], NULL));
+
+#define APPEND_STRING_INFO(func, id, name, what) \
+       do { \
+               char data[1024] = "\0"; \
+               opencl_assert(func(id, what, sizeof(data), &data, NULL)); \
+               result += string_printf("%s: %s\n", name, data); \
+       } while(false)
+#define APPEND_PLATFORM_STRING_INFO(id, name, what) \
+       APPEND_STRING_INFO(clGetPlatformInfo, id, "\tPlatform " name, what)
+#define APPEND_DEVICE_STRING_INFO(id, name, what) \
+       APPEND_STRING_INFO(clGetDeviceInfo, id, "\t\t\tDevice " name, what)
+
+       vector<cl_device_id> device_ids;
+       for (cl_uint platform = 0; platform < num_platforms; ++platform) {
+               cl_platform_id platform_id = platform_ids[platform];
+
+               result += string_printf("Platform #%d\n", platform);
+
+               APPEND_PLATFORM_STRING_INFO(platform_id, "Name", 
CL_PLATFORM_NAME);
+               APPEND_PLATFORM_STRING_INFO(platform_id, "Vendor", 
CL_PLATFORM_VENDOR);
+               APPEND_PLATFORM_STRING_INFO(platform_id, "Version", 
CL_PLATFORM_VERSION);
+               APPEND_PLATFORM_STRING_INFO(platform_id, "Profile", 
CL_PLATFORM_PROFILE);
+               APPEND_PLATFORM_STRING_INFO(platform_id, "Extensions", 
CL_PLATFORM_EXTENSIONS);
+
+               cl_uint num_devices = 0;
+               opencl_assert(clGetDeviceIDs(platform_ids[platform],
+                                            CL_DEVICE_TYPE_ALL,
+                                            0,
+                                            NULL,
+                                            &num_devices));
+               result += string_printf("\tNumber of devices: %d\n", 
num_devices);
+
+               device_ids.resize(num_devices);
+               opencl_assert(clGetDeviceIDs(platform_ids[platform],
+                                            CL_DEVICE_TYPE_ALL,
+                                            num_devices,
+                                            &device_ids[0],
+                                            NULL));
+               for (cl_uint device = 0; device < num_devices; ++device) {
+                       cl_device_id device_id = device_ids[device];
+
+                       result += string_printf("\t\tDevice: #%d\n", device);
+
+                       APPEND_DEVICE_STRING_INFO(device_id, "Name", 
CL_DEVICE_NAME);
+                       APPEND_DEVICE_STRING_INFO(device_id, "Vendor", 
CL_DEVICE_VENDOR);
+                       APPEND_DEVICE_STRING_INFO(device_id, "OpenCL C 
Version", CL_DEVICE_OPENCL_C_VERSION);
+                       APPEND_DEVICE_STRING_INFO(device_id, "Profile", 
CL_DEVICE_PROFILE);
+                       APPEND_DEVICE_STRING_INFO(device_id, "Version", 
CL_DEVICE_VERSION);
+                       APPEND_DEVICE_STRING_INFO(device_id, "Extensions", 
CL_DEVICE_EXTENSIONS);
+               }
+       }
+
+#undef APPEND_STRING_INFO
+#undef APPEND_PLATFORM_STRING_INFO
+#undef APPEND_DEVICE_STRING_INFO
+
+       return result;
 }
 
 CCL_NAMESPACE_END

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to