Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1# -*- coding: utf-8 -*- 

2""" 

3@file 

4@brief A few functions about GPU. 

5""" 

6 

7 

8def pyopencl_status(): 

9 """ 

10 Looks into GPU and CPU to see which card is available. 

11 Returns a string. 

12 

13 .. index:: GPU 

14 

15 .. runpython:: 

16 :showcode: 

17 

18 from ensae_teaching_cs.faq.faq_gpu import pyopencl_status 

19 print(pyopencl_status()) 

20 """ 

21 rows = [] 

22 try: 

23 import pyopencl as cl 

24 except ImportError as e: 

25 rows.append("pyopencl is not available due to {}".format(e)) 

26 return "\n".join(rows) 

27 

28 def catch(fct): 

29 try: 

30 return fct() 

31 except Exception as e: 

32 return "Unable to retrieve that information due to {}".format(str(e).replace("\n", " ")) 

33 

34 rows.append('=' * 60) 

35 rows.append('OpenCL plats and Devices') 

36 for plat in cl.get_platforms(): 

37 rows.append('=' * 60) 

38 rows.append('plat - Name: ' + plat.name) 

39 rows.append('plat - Vendor: ' + plat.vendor) 

40 rows.append('plat - Version: ' + plat.version) 

41 rows.append('plat - Profile: ' + plat.profile) 

42 # rows.append each device per-plat 

43 for device in plat.get_devices(): 

44 rows.append('-' * 56) 

45 rows.append('Device - Name: ' + catch(lambda: device.name)) 

46 rows.append('Device - Type: {}'.format( 

47 catch(lambda: cl.device_type.to_string(device.type)))) 

48 rows.append('Device - Max Clock Speed: {0} Mhz'.format( 

49 catch(lambda: device.max_clock_frequency))) 

50 rows.append('Device - Compute Units: {0}'.format( 

51 catch(lambda: device.max_compute_units))) 

52 rows.append('Device - Local Memory: {0:.0f} KB'.format( 

53 catch(lambda: device.local_mem_size / 1024.0))) 

54 rows.append('Device - Constant Memory: {0:.0f} KB'.format( 

55 catch(lambda: device.max_constant_buffer_size / 1024.0))) 

56 rows.append('Device - Global Memory: {0:.0f} GB'.format( 

57 catch(lambda: device.global_mem_size / 1073741824.0))) 

58 rows.append('Device - Max Buffer/Image Size: {0:.0f} MB'.format( 

59 catch(lambda: device.max_mem_alloc_size / 1048576.0))) 

60 rows.append('Device - Max Work Group Size: {0:.0f}'.format( 

61 catch(lambda: device.max_work_group_size))) 

62 rows.append('=' * 60) 

63 return "\n".join(rows)