Let's look at the steps, as follows:
- With the first instruction, we import the Python driver (that is, pycuda.driver) to the CUDA library installed on our PC:
import pycuda.driver as drv
- Initialize CUDA. Note also that the following instruction must be called before any other instruction in the pycuda.driver module:
drv.init()
- Enumerate the number of GPU cards on the PC:
print ("%d device(s) found." % drv.Device.count())
- For each of the GPU cards present, print the model name, the computing capability, and the total amount of memory on the device in kilobytes:
for ordinal i n range(drv.Device.count()): dev = drv.Device(ordinal) print ("Device #%d: %s" % (ordinal, dev.name()) print ("Compute Capability: %d.%d"% dev.compute_capability()) print ("Total Memory: %s KB" % (dev.total_memory()//(1024)))