Advertisement
Guest User

Untitled

a guest
Sep 19th, 2012
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.29 KB | None | 0 0
  1. #!/usr/bin/python
  2. import sys
  3. import os
  4. import time
  5. from platform import architecture
  6. from imp import find_module
  7.  
  8. timeformat = '%H:%M:%S'
  9. def getTimestamp():
  10.     return '[%s] ' % time.strftime(timeformat, time.localtime(time.time()))
  11.  
  12. def log(message):
  13.     print getTimestamp() + str(message)
  14.  
  15. def getPythonVersion():
  16.     info = sys.version_info
  17.     return str(info[0]) + '.' + str(info[1]) + '.' + str(info[2])
  18.  
  19. def getPyOpenCLPath():
  20.     try:
  21.         file, pathname, descr = find_module('pyopencl')
  22.     except:
  23.         pathname = 'Not found'
  24.     return str(pathname)
  25.  
  26. def getBoostVersion(input):
  27.     try:
  28.         contents = os.listdir(input)
  29.     except:
  30.         return 'Not Found'
  31.     for i in range(len(contents)):
  32.         if 'boost_python' in contents[i].lower():
  33.             return contents[i]
  34.     return 'Not Found'
  35.  
  36. path = getPyOpenCLPath()
  37.  
  38. #Display global information
  39. log('Python OpenCL Info v0.1')
  40. log('Python Version: ' + getPythonVersion() + ' ' + architecture()[0])
  41. log('PyOpenCL Path: ' + path)
  42. log('Boost Python Version: ' + getBoostVersion(path))
  43.  
  44. #Check for PyOpenCL not found
  45. if path == 'Not Found':
  46.     log('Exiting')
  47.     sys.exit()
  48.  
  49. #Now we try to import PyOpenCL
  50. # THIS IS WHERE THE FAILURE OCCURS !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  51. import pyopencl
  52. import pyopencl.version
  53.  
  54. #Continue printing
  55. log('PyOpenCL Version: ' + pyopencl.VERSION_TEXT)
  56.  
  57. #get platfroms
  58. try:
  59.     platforms = pyopencl.get_platforms()
  60. except:
  61.     log('Stupid bug')
  62.  
  63. # If no platforms exist then no OpenCL supporting devices are present
  64. if len(platforms) == 0:
  65.     log('No OpenCL platforms found!')
  66.     sys.exit()
  67.  
  68. log('Listing platforms and devices:')
  69. count = 0
  70.  
  71. # Iterate through platforms
  72. for i,p in enumerate(platforms):
  73.  
  74.     # Display platform
  75.     log('')
  76.     log('[cl:' + str(i) + '] ' + p.name.replace('\x00','').strip())
  77.  
  78.     # Get devices
  79.     devices = platforms[i].get_devices()
  80.  
  81.     # Make sure we don't callback for a platform if no devices found
  82.     if len(devices) > 0:
  83.         # Iterate through devices
  84.         for j,d in enumerate(devices):
  85.             count += 1
  86.             log('       [cl:' + str(i) + ':' + str(j) + '] ' + d.name.replace('\x00','').strip())
  87.  
  88.  
  89. log('')
  90. log('This program will exit in 300 seconds...')
  91. time.sleep(300)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement