4 Print information on all OpenCL platforms available and all its devices. 6 :license: GPLv3 --- Copyright (C) 2018 Olivier Pirson 7 :author: Olivier Pirson --- http://www.opimedia.be/ 8 :version: September 10, 2018 11 from __future__
import division
12 from __future__
import print_function
18 if sys.version_info[0] >= 3:
24 Print the help message on stderr 25 and exit with the error code. 27 :param error: 0 <= int < 256 29 assert isinstance(error, int), type(error)
30 assert 0 <= error < 256, error
32 print(
"""Usage: opencl_infos.py [--complete] 33 Print information on all OpenCL platforms available and all its devices. 36 --complete all information about device, else only main information""",
43 Print information about the device. 45 :param device: pyopencl.Device 48 assert isinstance(device, cl.Device), type(device)
49 assert isinstance(complete, bool), type(complete)
51 print(
' Device name: "{}"'.format(device.name))
53 attributes = (tuple(sorted(dir(device)))
if complete
54 else (
'global_mem_cache_size',
'global_mem_size',
56 'max_clock_frequency',
58 'max_constant_buffer_size',
60 'max_work_group_size',
'max_work_item_sizes',
62 for attribute
in attributes:
63 if (attribute[:1] !=
'_')
and (attribute !=
'name'):
65 value = getattr(device, attribute)
69 attribute = attribute.replace(
'_',
' ')
70 if isinstance(value, int)
or isinstance(value, long):
75 elif isinstance(value, list)
or isinstance(value, tuple):
77 .format(attribute,
' '.join(str(v)
for v
in value)))
78 elif isinstance(value, str):
79 print(
' {}: "{}"'.format(attribute, value))
84 Print information about the platform and its devices. 86 :param platform: pyopencl.Platform 87 :param platform_id: int >= 0 90 assert isinstance(platform, cl.Platform), type(platform)
92 assert isinstance(platform_id, int), type(platform_id)
93 assert platform_id >= 0, platform_id
95 assert isinstance(complete, bool), type(complete)
97 print(
'Platform name: "{}"'.format(platform.name))
98 print(
' vendor: "{}"'.format(platform.vendor))
99 print(
' version: "{}"'.format(platform.version))
100 print(
' profile: "{}"'.format(platform.profile))
101 print(
' extensions: "{}"'.format(platform.extensions))
103 devices = platform.get_devices()
104 nb_device = len(devices)
105 print(
' {} device{}'.format(nb_device,
s(nb_device)))
107 for device_id, device
in enumerate(devices):
108 print(
' ',
'{}:{}'.format(platform_id, device_id),
'-' * 30)
114 If x >= 2 then return 's', 117 :param x: int or long or float 121 assert isinstance(x, int)
or isinstance(x, long)
or isinstance(x, float), type(x)
123 return (
's' if x >= 2
129 Return a string with the size n expressed in several units. 131 :param: (int or long) >= 0 135 assert isinstance(n, int)
or isinstance(n, long), type(n)
138 seq = [
'{} o'.format(n)]
143 unit, units = units[0], units[1:]
147 seq.append(
'{} {}io'.format(n, unit))
149 return ' = '.join(seq)
157 Print information on all OpenCL platforms 161 for arg
in sys.argv[1:]:
162 if arg ==
'--complete':
164 elif arg ==
'--help':
169 print(
'Python version:', sys.version.replace(
'\n',
' '))
170 print(
'PyOpenCL version:', cl.VERSION_TEXT)
172 platforms = cl.get_platforms()
174 nb_platform = len(platforms)
175 print(
'{} OpenCL platform{}'.format(nb_platform,
s(nb_platform)))
177 for platform_id, platform
in enumerate(platforms):
181 if __name__ ==
'__main__':
def print_platform(platform, platform_id, complete)
def print_device(device, complete)