|
| 1 | +import pyopencl as cl |
| 2 | +from optparse import OptionParser |
| 3 | + |
| 4 | +parser = OptionParser() |
| 5 | +parser.add_option("-s", "--short", action="store_true", |
| 6 | + help="don't print all device properties") |
| 7 | + |
| 8 | +(options, args) = parser.parse_args() |
| 9 | + |
| 10 | + |
| 11 | +def print_info(obj, info_cls): |
| 12 | + for info_name in sorted(dir(info_cls)): |
| 13 | + if not info_name.startswith("_") and info_name != "to_string": |
| 14 | + info = getattr(info_cls, info_name) |
| 15 | + try: |
| 16 | + info_value = obj.get_info(info) |
| 17 | + except Exception: |
| 18 | + info_value = "<error>" |
| 19 | + |
| 20 | + if (info_cls == cl.device_info and info_name == "PARTITION_TYPES_EXT" |
| 21 | + and isinstance(info_value, list)): |
| 22 | + print("{}: {}".format(info_name, [ |
| 23 | + cl.device_partition_property_ext.to_string(v, |
| 24 | + "<unknown device partition property %d>") |
| 25 | + for v in info_value])) |
| 26 | + else: |
| 27 | + try: |
| 28 | + print(f"{info_name}: {info_value}") |
| 29 | + except Exception: |
| 30 | + print("%s: <error>" % info_name) |
| 31 | + |
| 32 | + |
| 33 | +for platform in cl.get_platforms(): |
| 34 | + print(75*"=") |
| 35 | + print(platform) |
| 36 | + print(75*"=") |
| 37 | + if not options.short: |
| 38 | + print_info(platform, cl.platform_info) |
| 39 | + |
| 40 | + for device in platform.get_devices(): |
| 41 | + if not options.short: |
| 42 | + print(75*"-") |
| 43 | + print(device) |
| 44 | + if not options.short: |
| 45 | + print(75*"-") |
| 46 | + print_info(device, cl.device_info) |
| 47 | + ctx = cl.Context([device]) |
| 48 | + for mf in [ |
| 49 | + cl.mem_flags.READ_ONLY, |
| 50 | + #cl.mem_flags.READ_WRITE, |
| 51 | + #cl.mem_flags.WRITE_ONLY |
| 52 | + ]: |
| 53 | + for itype in [ |
| 54 | + cl.mem_object_type.IMAGE2D, |
| 55 | + cl.mem_object_type.IMAGE3D |
| 56 | + ]: |
| 57 | + try: |
| 58 | + formats = cl.get_supported_image_formats(ctx, mf, itype) |
| 59 | + except Exception: |
| 60 | + formats = "<error>" |
| 61 | + else: |
| 62 | + def str_chd_type(chdtype): |
| 63 | + result = cl.channel_type.to_string(chdtype, |
| 64 | + "<unknown channel data type %d>") |
| 65 | + |
| 66 | + result = result.replace("_INT", "") |
| 67 | + result = result.replace("UNSIGNED", "U") |
| 68 | + result = result.replace("SIGNED", "S") |
| 69 | + result = result.replace("NORM", "N") |
| 70 | + result = result.replace("FLOAT", "F") |
| 71 | + return result |
| 72 | + |
| 73 | + formats = ", ".join( |
| 74 | + "{}-{}".format( |
| 75 | + cl.channel_order.to_string(iform.channel_order, |
| 76 | + "<unknown channel order 0x%x>"), |
| 77 | + str_chd_type(iform.channel_data_type)) |
| 78 | + for iform in formats) |
| 79 | + |
| 80 | + print("{} {} FORMATS: {}\n".format( |
| 81 | + cl.mem_object_type.to_string(itype), |
| 82 | + cl.mem_flags.to_string(mf), |
| 83 | + formats)) |
| 84 | + del ctx |
0 commit comments