[clinfo] 94/148: Convert platform info to traits mechanism
Andreas Beckmann
anbe at moszumanska.debian.org
Mon Nov 17 14:09:50 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 8bdc95af78f251889dc127d3104d9f49f34e743f
Author: Giuseppe Bilotta <giuseppe.bilotta at gmail.com>
Date: Mon Nov 3 20:05:56 2014 +0100
Convert platform info to traits mechanism
---
src/clinfo.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++--------------
src/error.h | 21 +++++++++++++--
2 files changed, 86 insertions(+), 22 deletions(-)
diff --git a/src/clinfo.c b/src/clinfo.c
index 3929e8a..0ea3052 100644
--- a/src/clinfo.c
+++ b/src/clinfo.c
@@ -71,33 +71,82 @@ size_t wgm[NUM_KERNELS];
STR_PRINT(name, strbuf); \
} while (0)
+int had_error = 0;
+
+int
+platform_info_str(cl_platform_id pid, cl_platform_info param, const char* pname)
+{
+ error = clGetPlatformInfo(pid, param, 0, NULL, &nusz);
+ if (nusz > bufsz) {
+ REALLOC(strbuf, nusz, current_param);
+ bufsz = nusz;
+ }
+ had_error = REPORT_ERROR2("get %s size");
+ if (!had_error) {
+ error = clGetPlatformInfo(pid, param, bufsz, strbuf, 0);
+ had_error = REPORT_ERROR2("get %s");
+ }
+ printf(I1_STR "%s\n", pname, skip_leading_ws(strbuf));
+ return had_error;
+}
+
+struct platform_info_traits {
+ cl_platform_info param; // CL_PLATFORM_*
+ const char *sname; // "CL_PLATFORM_*"
+ const char *pname; // "Platform *"
+};
+
+#define PINFO(symbol, name) { symbol, #symbol, "Platform " name }
+struct platform_info_traits pinfo_traits[] = {
+ PINFO(CL_PLATFORM_NAME, "Name"),
+ PINFO(CL_PLATFORM_VENDOR, "Vendor"),
+ PINFO(CL_PLATFORM_VERSION, "Version"),
+ PINFO(CL_PLATFORM_PROFILE, "Profile"),
+ PINFO(CL_PLATFORM_EXTENSIONS, "Extensions"),
+ PINFO(CL_PLATFORM_ICD_SUFFIX_KHR, "Extensions function suffix")
+};
+
/* Print platform info and prepare arrays for device info */
void
printPlatformInfo(cl_uint p)
{
cl_platform_id pid = platform[p];
size_t len = 0;
+ int had_error = 0;
+ int has_khr_icd = 0;
-#define PARAM(param, str) \
- SHOW_STRING(clGetPlatformInfo, CL_PLATFORM_##param, "Platform " str, pid)
+ current_function = __func__;
- PARAM(NAME, "Name");
+ for (current_line = 0; current_line < ARRAY_SIZE(pinfo_traits); ++current_line) {
+ const struct platform_info_traits *traits = pinfo_traits + current_line;
+ current_param = traits->sname;
- /* Store name for future reference */
- len = strlen(strbuf);
- platform_name[p] = malloc(len + 1);
- /* memcpy instead of strncpy since we already have the len
- * and memcpy is possibly more optimized */
- memcpy(platform_name[p], strbuf, len);
- platform_name[p][len] = '\0';
-
- PARAM(VENDOR, "Vendor");
- PARAM(VERSION, "Version");
- PARAM(PROFILE, "Profile");
- PARAM(EXTENSIONS, "Extensions");
- if (strstr(strbuf, "cl_khr_icd"))
- PARAM(ICD_SUFFIX_KHR, "Extensions function suffix");
-#undef PARAM
+ had_error = platform_info_str(pid, traits->param, traits->pname);
+
+ if (had_error)
+ continue;
+
+ /* post-processing */
+
+ switch (traits->param) {
+ case CL_PLATFORM_NAME:
+ /* Store name for future reference */
+ len = strlen(strbuf);
+ platform_name[p] = malloc(len + 1);
+ /* memcpy instead of strncpy since we already have the len
+ * and memcpy is possibly more optimized */
+ memcpy(platform_name[p], strbuf, len);
+ platform_name[p][len] = '\0';
+ break;
+ case CL_PLATFORM_EXTENSIONS:
+ has_khr_icd = !!strstr(strbuf, "cl_khr_icd");
+ break;
+ default:
+ /* do nothing */
+ break;
+ }
+
+ }
error = clGetDeviceIDs(pid, CL_DEVICE_TYPE_ALL, 0, NULL, num_devs + p);
if (error != CL_DEVICE_NOT_FOUND)
@@ -105,8 +154,6 @@ printPlatformInfo(cl_uint p)
num_devs_all += num_devs[p];
}
-int had_error = 0;
-
#define GET_PARAM(param, var) do { \
error = clGetDeviceInfo(dev, CL_DEVICE_##param, sizeof(var), &var, 0); \
had_error = REPORT_ERROR("get " #param); \
diff --git a/src/error.h b/src/error.h
index 741342c..893a874 100644
--- a/src/error.h
+++ b/src/error.h
@@ -17,8 +17,24 @@ check_ocl_error(cl_int err, const char *what, const char *func, int line)
return err != CL_SUCCESS;
}
+const char *current_function;
+int current_line;
+const char *current_param;
+
+int
+report_ocl_error(char *dstbuf, size_t sz, cl_int err, const char *fmt)
+{
+ static char full_fmt[1024];
+ if (err != CL_SUCCESS) {
+ snprintf(full_fmt, 1024, "<%s:%d: %s : error %d>",
+ current_function, current_line, fmt, err);
+ snprintf(dstbuf, sz, full_fmt, current_param);
+ }
+ return err != CL_SUCCESS;
+}
+
int
-report_ocl_error(char *where, size_t sz, cl_int err, const char *what, const char *func, int line)
+report_ocl_error_old(char *where, size_t sz, cl_int err, const char *what, const char *func, int line)
{
if (err != CL_SUCCESS) {
snprintf(where, sz, "<%s:%d: %s : error %d>",
@@ -29,5 +45,6 @@ report_ocl_error(char *where, size_t sz, cl_int err, const char *what, const cha
#define CHECK_ERROR(what) if (check_ocl_error(error, what, __func__, __LINE__)) exit(1)
-#define REPORT_ERROR(what) report_ocl_error(strbuf, bufsz, error, what, __func__, __LINE__)
+#define REPORT_ERROR(what) report_ocl_error_old(strbuf, bufsz, error, what, __func__, __LINE__)
+#define REPORT_ERROR2(what) report_ocl_error(strbuf, bufsz, error, what)
--
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