How to do it...

In the following example, we will use a function of PyOpenCL that allows us to enumerate the features of the GPU on which it will operate.

The code we implement is very simple and logical:

  1. In the first step, we import the pyopencl library:
import pyopencl as cl
  1. We build a function whose output will provide us with the characteristics of the GPU hardware in use:
def print_device_info() :
print(' ' + '=' * 60 + ' OpenCL Platforms and Devices')
for platform in cl.get_platforms():
print('=' * 60)
print('Platform - Name: ' + platform.name)
print('Platform - Vendor: ' + platform.vendor)
print('Platform - Version: ' + platform.version)
print('Platform - Profile: ' + platform.profile)

for device in platform.get_devices():
print(' ' + '-' * 56)
print(' Device - Name: '
+ device.name)
print(' Device - Type: '
+ cl.device_type.to_string(device.type))
print(' Device - Max Clock Speed: {0} Mhz'
.format(device.max_clock_frequency))
print(' Device - Compute Units: {0}'
.format(device.max_compute_units))
print(' Device - Local Memory: {0:.0f} KB'
.format(device.local_mem_size/1024.0))
print(' Device - Constant Memory: {0:.0f} KB'
.format(device.max_constant_buffer_size/1024.0))
print(' Device - Global Memory: {0:.0f} GB'
.format(device.global_mem_size/1073741824.0))
print(' Device - Max Buffer/Image Size: {0:.0f} MB'
.format(device.max_mem_alloc_size/1048576.0))
print(' Device - Max Work Group Size: {0:.0f}'
.format(device.max_work_group_size))
print(' ')
  1. So, we implement the main function, which calls the previously implemented print_device_info function:
if __name__ == "__main__":
print_device_info()
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset