From f52ea9428f37b0e2caeedcf16307efd16fc78758 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner <inform@tiker.net> Date: Mon, 8 Aug 2011 02:22:23 +0200 Subject: [PATCH] Image format printing in dump-properties. --- examples/dump-properties.py | 33 ++++++++++++++++++++++++++++++++- pyopencl/__init__.py | 4 ++-- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/examples/dump-properties.py b/examples/dump-properties.py index 92ce7dcb..8732c4cc 100644 --- a/examples/dump-properties.py +++ b/examples/dump-properties.py @@ -11,7 +11,6 @@ def print_info(obj, info_cls): if (info_cls == cl.device_info and info_name == "PARTITION_TYPES_EXT" and isinstance(info_value, list)): - print info_value print("%s: %s" % (info_name, [ cl.device_partition_property_ext.to_string(v) for v in info_value])) else: @@ -28,3 +27,35 @@ for platform in cl.get_platforms(): print(device) print(75*"-") print_info(device, cl.device_info) + ctx = cl.Context([device]) + #for mf in [cl.mem_flags.READ_ONLY, cl.mem_flags.READ_WRITE, cl.mem_flags.WRITE_ONLY]: + for mf in [cl.mem_flags.READ_ONLY]: + for itype in [cl.mem_object_type.IMAGE2D, cl.mem_object_type.IMAGE3D]: + try: + formats = cl.get_supported_image_formats(ctx, mf, itype) + except: + formats = "<error>" + else: + def str_chd_type(chdtype): + result = cl.channel_type.to_string(chdtype, + "<unknown channel data type %d>") + + result = result.replace("_INT", "") + result = result.replace("UNSIGNED", "U") + result = result.replace("SIGNED", "S") + result = result.replace("NORM", "N") + result = result.replace("FLOAT", "F") + return result + + formats = ", ".join( + "%s-%s" % ( + cl.channel_order.to_string(iform.channel_order, + "<unknown channel order 0x%x>"), + str_chd_type(iform.channel_data_type)) + for iform in formats) + + print "%s %s FORMATS: %s\n" % ( + cl.mem_object_type.to_string(itype), + cl.mem_flags.to_string(mf), + formats) + del ctx diff --git a/pyopencl/__init__.py b/pyopencl/__init__.py index 8c12e36b..4b329c49 100644 --- a/pyopencl/__init__.py +++ b/pyopencl/__init__.py @@ -275,9 +275,9 @@ def _add_functionality(): def image_format_repr(self): return "ImageFormat(%s, %s)" % ( channel_order.to_string(self.channel_order, - "<unknown channel order %d>"), + "<unknown channel order 0x%x>"), channel_type.to_string(self.channel_data_type, - "<unknown channel data type %d>")) + "<unknown channel data type 0x%x>")) ImageFormat.__repr__ = image_format_repr -- GitLab