summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Vogelgesang <matthias.vogelgesang@kit.edu>2015-03-05 16:50:43 +0100
committerMatthias Vogelgesang <matthias.vogelgesang@kit.edu>2015-03-06 09:48:43 +0100
commit433b209ab899e49aa962f7e02312dd6d7d2d323d (patch)
tree7cb42f15af839f520f86c143bbde244739593341
parentbf5af68c152b0bfa3fe373c8836daa32b707ff24 (diff)
Fix #80: add ufo_gpu_node_get_info()
This API call queries the underlying OpenCL device. To get the global memory size in Python, you would write something like: resources = Ufo.Resources() node = resources.get_gpu_nodes()[0] print(node.get_info(Ufo.GpuNodeInfo.GLOBAL_MEM_SIZE))
-rw-r--r--python/tests/test_infrastructure.py9
-rw-r--r--ufo/ufo-gpu-node.c38
-rw-r--r--ufo/ufo-gpu-node.h21
3 files changed, 65 insertions, 3 deletions
diff --git a/python/tests/test_infrastructure.py b/python/tests/test_infrastructure.py
index 34081e1..43e6515 100644
--- a/python/tests/test_infrastructure.py
+++ b/python/tests/test_infrastructure.py
@@ -60,3 +60,12 @@ def test_broadcast():
bars = glob.glob(d.path('bar-*'))
assert(len(foos) == 5)
assert(len(bars) == 5)
+
+
+def test_resource_info():
+ resources = Ufo.Resources()
+ nodes = resources.get_gpu_nodes()
+ assert(nodes)
+ node = nodes[0]
+ assert(node.get_info(Ufo.GpuNodeInfo.LOCAL_MEM_SIZE) > 0)
+ assert(node.get_info(Ufo.GpuNodeInfo.GLOBAL_MEM_SIZE) > node.get_info(Ufo.GpuNodeInfo.LOCAL_MEM_SIZE))
diff --git a/ufo/ufo-gpu-node.c b/ufo/ufo-gpu-node.c
index 0ceaa31..c34f4e9 100644
--- a/ufo/ufo-gpu-node.c
+++ b/ufo/ufo-gpu-node.c
@@ -18,6 +18,7 @@
*/
#include <CL/cl.h>
+#include <string.h>
#include <ufo/ufo-resources.h>
#include <ufo/ufo-gpu-node.h>
@@ -69,6 +70,43 @@ ufo_gpu_node_get_cmd_queue (UfoGpuNode *node)
return node->priv->cmd_queue;
}
+/**
+ * ufo_gpu_node_get_info:
+ * @node: A #UfoGpuNodeInfo
+ * @info: Information to be queried
+ *
+ * Return information about the associated OpenCL device.
+ *
+ * Returns: (transfer full): Information about @info.
+ */
+GValue *
+ufo_gpu_node_get_info (UfoGpuNode *node,
+ UfoGpuNodeInfo info)
+{
+ UfoGpuNodePrivate *priv;
+ GValue *value;
+ cl_ulong ulong_value;
+
+ priv = UFO_GPU_NODE_GET_PRIVATE (node);
+ value = g_new0 (GValue, 1);
+ memset (value, 0, sizeof (GValue));
+
+ g_value_init (value, G_TYPE_ULONG);
+
+ switch (info) {
+ case UFO_GPU_NODE_INFO_GLOBAL_MEM_SIZE:
+ UFO_RESOURCES_CHECK_CLERR (clGetDeviceInfo (priv->device, CL_DEVICE_GLOBAL_MEM_SIZE, sizeof (cl_ulong), &ulong_value, NULL));
+ break;
+
+ case UFO_GPU_NODE_INFO_LOCAL_MEM_SIZE:
+ UFO_RESOURCES_CHECK_CLERR (clGetDeviceInfo (priv->device, CL_DEVICE_LOCAL_MEM_SIZE, sizeof (cl_ulong), &ulong_value, NULL));
+ break;
+ }
+
+ g_value_set_ulong (value, ulong_value);
+ return value;
+}
+
static UfoNode *
ufo_gpu_node_copy_real (UfoNode *node,
GError **error)
diff --git a/ufo/ufo-gpu-node.h b/ufo/ufo-gpu-node.h
index 0c52ebb..f6e5e6b 100644
--- a/ufo/ufo-gpu-node.h
+++ b/ufo/ufo-gpu-node.h
@@ -62,9 +62,24 @@ struct _UfoGpuNodeClass {
UfoNodeClass parent_class;
};
-UfoNode *ufo_gpu_node_new (gpointer context,
- gpointer device);
-gpointer ufo_gpu_node_get_cmd_queue (UfoGpuNode *node);
+/**
+ * UfoGpuNodeInfo:
+ * @UFO_GPU_NODE_INFO_GLOBAL_MEM_SIZE: Global memory size
+ * @UFO_GPU_NODE_INFO_LOCAL_MEM_SIZE: Local memory size
+ *
+ * OpenCL device info types. Refer to the OpenCL standard for complete details
+ * about each information.
+ */
+typedef enum {
+ UFO_GPU_NODE_INFO_GLOBAL_MEM_SIZE = 0,
+ UFO_GPU_NODE_INFO_LOCAL_MEM_SIZE,
+} UfoGpuNodeInfo;
+
+UfoNode *ufo_gpu_node_new (gpointer context,
+ gpointer device);
+gpointer ufo_gpu_node_get_cmd_queue (UfoGpuNode *node);
+GValue *ufo_gpu_node_get_info (UfoGpuNode *node,
+ UfoGpuNodeInfo info);
GType ufo_gpu_node_get_type (void);
G_END_DECLS