List and select devices#

pyclesperanto relies on sending computing instructions to compute devices. Here, devices are Computational Units (CUs) compatible with OpenCL. This can be GPUs and CPUs although we would prefer to use GPUs for their speed capacities.

Before starting to use pyclesperanto, it is important to know which devices are available on your system and which one you want to use based on their performances.

import pyclesperanto_prototype as cle

Exercice 1: List devices and select a device#

Using the method available_device_names() and select_device() from the pyclesperanto_prototype package, list the available devices on your machine and select one.

# TODO
2 devices found:
['pthread-Intel(R) Core(TM) i7-7820X CPU @ 3.60GHz', 'NVIDIA GeForce RTX 2080 SUPER']
# TODO
<pthread-Intel(R) Core(TM) i7-7820X CPU @ 3.60GHz on Platform: Portable Computing Language (2 refs)>

Tips: Devices are defined by a name and a dev_type (gpu, cpu, all). You can use the select_device arguments to precisely select the device you want to use. This can be useful if you have multiple devices of the same type but not the same type (Hello Macbook Pro with M1 and M2 chips !).

Exercice 2: Which device to choose?#

For the lucky of you who have access to multiple devices, you might wonder which one to choose. Here are some hints:

  • Prefer GPU over CPU for speed

  • Prefer GPU with more memory over GPU with less memory (GLOBAL_MEM_SIZE, MAX_MEM_ALLOC_SIZE)

  • Prefer GPU with more or faster compute units (MAX_COMPUTE_UNITS, MAX_CLOCK_FREQUENCY)

Those information can be retrieve using the cl_info method to print the full information of all the devices available.

Print them and tell us which one, in your opinion, is the most adapted.

# TODO

Tips: you may want to save this into a text file

with open("cl_info.txt", "w") as f:
    f.write( ... )