2012-09-16 2 views
0

Mac OSX에서 Python으로 OpenCL을로드하려면 어떻게합니까?OSX에서 PyOpenCL을 가져올 수 없습니다 (예외 발생).

출력

Chriss-MacBook-Pro:phoenix2-phoenix-2c83ee6 chris$ python opencl.py 
[22:17:15] Python OpenCL Info v0.1 
[22:17:15] Python Version: 2.7.2 64bit 
[22:17:15] PyOpenCL Path: /Library/Python/2.7/site-packages/pyopencl-2012.1-py2.7-macosx-10.8-intel.egg/pyopencl 
[22:17:15] Boost Python Version: Not Found 
[22:17:15] Unable to load PyOpenCL! OpenCL not supported? 

소스 코드 스크립트를 테스트합니다.

#!/usr/bin/python 
import sys 
import os 
import time 
from platform import architecture 
from imp import find_module 

timeformat = '%H:%M:%S' 
def getTimestamp(): 
    return '[%s] ' % time.strftime(timeformat, time.localtime(time.time())) 

def log(message): 
    print getTimestamp() + str(message) 

def getPythonVersion(): 
    info = sys.version_info 
    return str(info[0]) + '.' + str(info[1]) + '.' + str(info[2]) 

def getPyOpenCLPath(): 
    try: 
     file, pathname, descr = find_module('pyopencl') 
    except: 
     pathname = 'Not found' 
    return str(pathname) 

def getBoostVersion(input): 
    try: 
     contents = os.listdir(input) 
    except: 
     return 'Not Found' 
    for i in range(len(contents)): 
     if 'boost_python' in contents[i].lower(): 
      return contents[i] 
    return 'Not Found' 

path = getPyOpenCLPath() 

#Display global information 
log('Python OpenCL Info v0.1') 
log('Python Version: ' + getPythonVersion() + ' ' + architecture()[0]) 
log('PyOpenCL Path: ' + path) 
log('Boost Python Version: ' + getBoostVersion(path)) 

#Check for PyOpenCL not found 
if path == 'Not Found': 
    log('Exiting') 
    sys.exit() 

#Now we try to import PyOpenCL 
# THIS IS WHERE THE FAILURE OCCURS !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 
try: 
    import pyopencl 
    import pyopencl.version 
except: 
    log('Unable to load PyOpenCL! OpenCL not supported?') 
    sys.exit() 

#Continue printing 
log('PyOpenCL Version: ' + pyopencl.VERSION_TEXT) 

#get platfroms 
try: 
    platforms = pyopencl.get_platforms() 
except: 
    log('Stupid bug') 

# If no platforms exist then no OpenCL supporting devices are present 
if len(platforms) == 0: 
    log('No OpenCL platforms found!') 
    sys.exit() 

log('Listing platforms and devices:') 
count = 0 

# Iterate through platforms 
for i,p in enumerate(platforms): 

    # Display platform 
    log('') 
    log('[cl:' + str(i) + '] ' + p.name.replace('\x00','').strip()) 

    # Get devices 
    devices = platforms[i].get_devices() 

    # Make sure we don't callback for a platform if no devices found 
    if len(devices) > 0: 
     # Iterate through devices 
     for j,d in enumerate(devices): 
      count += 1 
      log('  [cl:' + str(i) + ':' + str(j) + '] ' + d.name.replace('\x00','').strip()) 


log('') 
log('This program will exit in 300 seconds...') 
time.sleep(300) 
+0

시도를 토글하고 효과적인 예외를 게시하십시오. 좀 더 재미있는 정보 (누락 된 라이브러리 등)를 가질 수 있습니다. – pr0gg3d

+0

@ pr0gg3d 저는 파이썬을 처음 사용합니다 ... 시도를 제거한다는 의미입니까? – LamonteCristo

+0

http://pastebin.com/KvHzpcwG에서와 같이 실제 예외가 인쇄됩니다. – pr0gg3d

답변

1

은 하드웨어 지원 OpenCL을합니까 (실패 라인이 표시되어 있습니다)? 경우에 따라 빌드를 실행하고 예제 C 프로그램을 실행하여 유사한 문제를 쉽게 디버깅 할 수 있습니다.

+0

저는 MacBook Pro Retna에 있습니다. BitMinter 클라이언트를 실행했고 OpenCL을로드 할 수 있다고 말합니다 (OpenCL은 구형 Mac에서는 전혀 작동하지 않지만). 나는 이것에 아주 새롭다 그래서 어떤 원조든지 평가 될 것이다. – LamonteCristo

관련 문제