[clinfo] 01/148: Initial commit, get platform info

Andreas Beckmann anbe at moszumanska.debian.org
Mon Nov 17 14:09:38 UTC 2014


This is an automated email from the git hooks/post-receive script.

anbe pushed a commit to branch clinfo
in repository clinfo.

commit 765f90ff52891abb23d0d288fd1e0379c5a9e21c
Author: Giuseppe Bilotta <giuseppe.bilotta at gmail.com>
Date:   Wed Jun 5 21:10:34 2013 +0200

    Initial commit, get platform info
---
 .gitignore   |   2 ++
 Makefile     |   8 +++++
 src/clinfo.c | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 111 insertions(+)

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..f7f305a
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+clinfo
+.*.swp
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..79105f1
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,8 @@
+LDLIBS=-lOpenCL
+
+vpath %.c src/
+
+clinfo: clinfo.c
+
+clean:
+	$(RM) clinfo
diff --git a/src/clinfo.c b/src/clinfo.c
new file mode 100644
index 0000000..2315a61
--- /dev/null
+++ b/src/clinfo.c
@@ -0,0 +1,101 @@
+/* Collect all available information on all available devices
+ * on all available OpenCL platforms present in the system
+ */
+
+#include <stdio.h>
+
+#ifdef __APPLE__
+#include <OpenCL/cl.h>
+#else
+#include <CL/cl.h>
+#endif
+
+void
+check_ocl_error(cl_int err, const char *what, const char *func, int line)
+{
+	if (err != CL_SUCCESS) {
+		fprintf(stderr, "%s:%s: %s : error %d\n",
+			func, line, what, err);
+		exit(1);
+	}
+}
+
+cl_int error;
+#define CHECK_ERROR(what) check_ocl_error(error, what, __func__, __LINE__)
+
+
+#define ALLOC(var, num, what) do { \
+	var = malloc(num*sizeof(*var)); \
+	if (!var) { \
+		fprintf(stderr, "%s:%s: %s : Out of memory\n", \
+			__func__, __LINE__, what); \
+		exit(1); \
+	} \
+} while (0);
+
+#define REALLOC(var, num, what) do { \
+	var = realloc(var, num*sizeof(*var)); \
+	if (!var) { \
+		fprintf(stderr, "%s:%s: %s : Out of memory\n", \
+			__func__, __LINE__, what); \
+		exit(1); \
+	} \
+} while (0);
+
+
+char *buffer;
+size_t bufsz, nusz;
+
+#define SHOW_STRING(cmd, id, param, str) do { \
+	error = cmd(id, param, 0, NULL, &nusz); \
+	CHECK_ERROR("get " #param " size"); \
+	if (nusz > bufsz) { \
+		REALLOC(buffer, nusz, #param); \
+		bufsz = nusz; \
+	} \
+	error = cmd(id, param, bufsz, buffer, 0); \
+	CHECK_ERROR("get " #param); \
+	printf("  %-46s: %s\n", str, buffer); \
+} while (0);
+
+void
+printPlatformInfo(cl_platform_id pid)
+{
+#define PARAM(param, str) \
+	SHOW_STRING(clGetPlatformInfo, pid, CL_PLATFORM_##param, "Platform " str)
+
+	PARAM(NAME, "Name");
+	PARAM(VENDOR, "Vendor");
+	PARAM(VERSION, "Version");
+	PARAM(PROFILE, "Profile");
+	PARAM(EXTENSIONS, "Extensions");
+#undef PARAM
+}
+
+void
+printDeviceInfo(cl_device_id *dev)
+{
+}
+
+int main(void)
+{
+	cl_uint num_entries;
+	cl_platform_id *platforms;
+	cl_device_id *devices;
+	uint i;
+
+	error = clGetPlatformIDs(0, NULL, &num_entries);
+	CHECK_ERROR("number of platforms");
+
+	printf("%-48s: %u\n", "Number of platforms", num_entries);
+	if (!num_entries)
+		return 0;
+
+	ALLOC(platforms, num_entries, "platform IDs");
+	error = clGetPlatformIDs(num_entries, platforms, NULL);
+	CHECK_ERROR("platform IDs");
+
+	for (i = 0; i < num_entries; ++i)
+		printPlatformInfo(platforms[i]);
+
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-opencl/clinfo.git



More information about the Pkg-opencl-commits mailing list