[clinfo] 47/148: Be more careful about handling cl_ types
Andreas Beckmann
anbe at moszumanska.debian.org
Mon Nov 17 14:09:44 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 3f07a087e76b5329a31fbb951afe4384f2623d96
Author: Giuseppe Bilotta <giuseppe.bilotta at gmail.com>
Date: Tue Apr 29 23:03:07 2014 +0200
Be more careful about handling cl_ types
Particularly, cl_ulong might not be a (host) long, since cl_ulong
is guaranteed to be 64-bit wide, while on some 32-bit architectures
the long type is only 32-bit wide. So rely on the inttypes.h definitions
and macros on the assumption that cl_ulong is an uint64_t.
While we're at it, use the correct printf format macros for other
types.
---
src/clinfo.c | 23 +++++++++++++++--------
1 file changed, 15 insertions(+), 8 deletions(-)
diff --git a/src/clinfo.c b/src/clinfo.c
index 765e8c6..40e4a65 100644
--- a/src/clinfo.c
+++ b/src/clinfo.c
@@ -2,6 +2,13 @@
* on all available OpenCL platforms present in the system
*/
+/* cl_ulong is always a 64bit integer, so in a few places
+ we want to use its shadow type uint64_t, and print the
+ values using PRIu64
+ */
+#define __STDC_FORMAT_MACROS
+#include <inttypes.h>
+
#include <time.h>
#include <string.h>
@@ -210,7 +217,7 @@ printDeviceInfo(cl_uint d)
cl_bool is_12 = CL_FALSE;
cl_bool is_gpu = CL_FALSE;
-#define KB 1024UL
+#define KB UINT64_C(1024)
#define MB (KB*KB)
#define GB (MB*KB)
#define TB (GB*KB)
@@ -248,7 +255,7 @@ printDeviceInfo(cl_uint d)
MEM_PFX(doubleval)); \
strbuf[bufsz-1] = '\0'; \
} else strbuf[0] = '\0'; \
- printf(I1_STR "%lu%s\n", \
+ printf(I1_STR "%" PRIu64 "%s\n", \
name, ulongval, strbuf); \
} while (0)
#define BOOL_PARAM(param, name) do { \
@@ -362,7 +369,7 @@ printDeviceInfo(cl_uint d)
case CL_DEVICE_PARTITION_BY_NAMES_INTEL:
printf("by name (Intel extension)"); break;
default:
- printf("by <unknown> (0x%lX)", partprop[cursor]); break;
+ printf("by <unknown> (0x%" PRIXPTR ")", partprop[cursor]); break;
}
if (cursor < numpartprop - 1)
printf(", ");
@@ -406,7 +413,7 @@ printDeviceInfo(cl_uint d)
case CL_DEVICE_PARTITION_BY_AFFINITY_DOMAIN_EXT:
printf("by affinity domain"); break;
default:
- printf("by <unknown> (0x%lX)", partprop_ext[cursor]); break;
+ printf("by <unknown> (0x%" PRIX64 ")", partprop_ext[cursor]); break;
}
if (cursor < numpartprop_ext - 1)
printf(", ");
@@ -430,7 +437,7 @@ printDeviceInfo(cl_uint d)
case CL_AFFINITY_DOMAIN_NEXT_FISSIONABLE_EXT:
printf("next fissionable"); break;
default:
- printf("<unknown> (0x%lX)", partdom_ext[cursor]);
+ printf("<unknown> (0x%" PRIX64 ")", partdom_ext[cursor]);
break;
}
if (cursor < numpartdom_ext - 1)
@@ -536,7 +543,7 @@ printDeviceInfo(cl_uint d)
MEM_PFX(doubleval));
strbuf[bufsz-1] = '\0';
} else strbuf[0] = '\0';
- printf(I1_STR "%lu%s\n", "Free global memory (AMD)", szvals[cursor], strbuf);
+ printf(I1_STR "%zu%s\n", "Free global memory (AMD)", szvals[cursor], strbuf);
}
INT_PARAM(GLOBAL_MEM_CHANNELS_AMD, "Global memory channels (AMD)",);
@@ -626,12 +633,12 @@ printDeviceInfo(cl_uint d)
time_t time;
char *nl;
GET_PARAM(PROFILING_TIMER_OFFSET_AMD, ulongval);
- time = ulongval/(1000000000UL);
+ time = ulongval/UINT64_C(1000000000);
strncpy(strbuf, ctime(&time), bufsz);
nl = strstr(strbuf, "\n");
if (nl) *nl = '\0'; // kill the newline generated by ctime
- printf(I1_STR "%luns (%s)\n", "Profiling timer offset since Epoch (AMD)",
+ printf(I1_STR "%" PRIu64 "ns (%s)\n", "Profiling timer offset since Epoch (AMD)",
ulongval, strbuf);
}
--
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