[Bf-blender-cvs] [f1d77737f54] temp-benchmark: Benchmark: Add executable to query number of compute units

Sergey Sharybin noreply at git.blender.org
Thu Aug 9 16:42:34 CEST 2018


Commit: f1d77737f54ed26af8bfe0fe2ffe5b350e115847
Author: Sergey Sharybin
Date:   Thu Aug 9 16:40:50 2018 +0200
Branches: temp-benchmark
https://developer.blender.org/rBf1d77737f54ed26af8bfe0fe2ffe5b350e115847

Benchmark: Add executable to query number of compute units

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

M	extern/CMakeLists.txt
M	extern/clew/CMakeLists.txt
A	extern/clew/src/cl_query.cc

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

diff --git a/extern/CMakeLists.txt b/extern/CMakeLists.txt
index 4f8f2ff2b54..3d59c59c10f 100644
--- a/extern/CMakeLists.txt
+++ b/extern/CMakeLists.txt
@@ -75,9 +75,9 @@ if(WITH_LZMA)
 	add_subdirectory(lzma)
 endif()
 
-if(WITH_CYCLES OR WITH_COMPOSITOR OR WITH_OPENSUBDIV)
+if(WITH_CYCLES OR WITH_COMPOSITOR OR WITH_OPENSUBDIV OR TRUE)
 	add_subdirectory(clew)
-	if(WITH_CUDA_DYNLOAD)
+	if(WITH_CUDA_DYNLOAD AND FALSE)
 		add_subdirectory(cuew)
 	endif()
 endif()
diff --git a/extern/clew/CMakeLists.txt b/extern/clew/CMakeLists.txt
index f75e933034f..0ab3a357d9e 100644
--- a/extern/clew/CMakeLists.txt
+++ b/extern/clew/CMakeLists.txt
@@ -40,3 +40,7 @@ set(SRC
 add_definitions(-DCL_USE_DEPRECATED_OPENCL_1_1_APIS)
 
 blender_add_lib(extern_clew "${SRC}" "${INC}" "${INC_SYS}")
+
+add_executable(cl_query src/cl_query.cc)
+target_link_libraries(cl_query extern_clew ${CMAKE_DL_LIBS})
+install(TARGETS cl_query DESTINATION "bin")
diff --git a/extern/clew/src/cl_query.cc b/extern/clew/src/cl_query.cc
new file mode 100644
index 00000000000..e16e59be240
--- /dev/null
+++ b/extern/clew/src/cl_query.cc
@@ -0,0 +1,99 @@
+/*
+ * Copyright 2011-2015 Blender Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <cstdlib>
+#include <cstdio>
+#include <vector>
+
+#include "clew.h"
+
+using std::vector;
+#define foreach(x, y) for(x : y)
+
+namespace {
+
+// Get all platform IDs.
+bool getPlatformIDs(vector<cl_platform_id>* platform_ids) {
+  cl_uint num_platforms = 0;
+  if (clGetPlatformIDs(0, NULL, &num_platforms) != CL_SUCCESS) {
+    return false;
+  }
+  platform_ids->resize(num_platforms);
+  if (clGetPlatformIDs(
+      num_platforms, &(*platform_ids)[0], NULL) != CL_SUCCESS) {
+    return false;
+  }
+  return true;
+}
+
+// Get device IDs for the given platform.
+bool getPlatformDeviceIDs(cl_platform_id platform_id,
+                          vector<cl_device_id>* device_ids) {
+  cl_uint num_devices = 0;
+  if (clGetDeviceIDs(
+      platform_id, CL_DEVICE_TYPE_GPU, 0, NULL, &num_devices) != CL_SUCCESS) {
+    return false;
+  }
+  device_ids->resize(num_devices);
+  if (num_devices == 0) {
+    return true;
+  }
+  if (clGetDeviceIDs(platform_id,
+                     CL_DEVICE_TYPE_ALL,
+                     num_devices,
+                     &(*device_ids)[0],
+                     NULL) != CL_SUCCESS) {
+    return false;
+  }
+  return true;
+}
+
+}  // namespace
+
+int main(int argc, char **argv) {
+  int result = clewInit();
+  if (result != CLEW_SUCCESS) {
+    return EXIT_FAILURE;
+  }
+  // Get all platform IDs.
+  vector<cl_platform_id> platform_ids;
+  if (!getPlatformIDs(&platform_ids)) {
+    return EXIT_FAILURE;
+  }
+  foreach (cl_platform_id platform_id, platform_ids) {
+    vector<cl_device_id> device_ids;
+    if (!getPlatformDeviceIDs(platform_id, &device_ids)) {
+      continue;
+    }
+    foreach (cl_device_id device_id, device_ids) {
+      char name[1024] = "\0";
+      if (clGetDeviceInfo(
+          device_id, CL_DEVICE_NAME, sizeof(name), name, NULL) != CL_SUCCESS) {
+        continue;
+      }
+      cl_int max_compute_units = 0;
+      if (clGetDeviceInfo(device_id,
+                          CL_DEVICE_MAX_COMPUTE_UNITS,
+                          sizeof(max_compute_units),
+                          &max_compute_units,
+                          NULL) != CL_SUCCESS) {
+        continue;
+      }
+      printf("%s:%d\n", name, max_compute_units);
+    }
+  }
+  return EXIT_SUCCESS;
+}



More information about the Bf-blender-cvs mailing list