2016-06-19 48 views
0

我想用numbapro來運行對象交互的基本模擬。但我得到這個錯誤,我不知道什麼問題。我非常新,試圖做GPU加速:( 這裏是我的代碼:Python NumbaPro GPU向量化與錯誤:TypingError:在nopython(nopython前端)失敗

from turtle import * 
import numpy as np 
from numbapro import vectorize 

setup(width = 1920, height = 1080, startx = None, starty = None) 
colormode(255) 

G = 1 #6.67428*10**(-11) 
AU = 1 #149597871 * 1000  # 1 AU in meters 

dt = 0.1 
dt = np.float64(dt) 

SCALE = 1 #150/Au 
bodiesVx = np.random.randint(1,11,10) 
bodiesVy = np.random.randint(1,11,10) 
bodiesM = np.random.randint(1,11,10) 
bodiesPx = np.random.randint(760,1060,10) 
bodiesPy = np.random.randint(440,640,10) 

bodiesM = bodiesM.astype('float64') 
bodiesPx = bodiesPx.astype('float64') 
bodiesPy = bodiesPy.astype('float64') 
bodiesVx = bodiesVx.astype('float64') 
bodiesVy = bodiesVy.astype('float64') 

@vectorize(['float64(float64)'],target="gpu") 
def UpdateX(i): 
    print (i) 
    global bodiesM, bodiesPx, bodiesVx, dt, G 
    PX = bodiesPx[bodiesPx-i == 0][0] 
    MArr = bodiesM[bodiesPx-bodiesPx[i] != 0] 
    PxArr = bodiesPx[bodiesPx != PX] 

    AccArrX = MArr*G/(PxArr-PX)**2 

    Vx = dt * np.sum(AccArrX) + bodiesVx[bodiesPx == PX][0] 

    return Vx * dt 

@vectorize(['float64(float64)'],target="gpu") 
def UpdateY(i): 
    global bodiesM, bodiesPy, bodiesVy, dt, G 
    PY = bodiesPy[bodiesPy-i == 0][0] 
    MArr = bodiesM[bodiesPy-bodiesPy[i] != 0] 
    PyArr = bodiesPy[bodiesPy != PY] 

    AccArrY = MArr*G/(PyArr-PY)**2 

    Vy = dt * np.sum(AccArrY) + bodiesVy[bodiesPy == PY][0] 

    return Vy * dt 


def move(i): 
    Turtle.goto(bodiesPx[i], bodiesPy[i]) 


def main(): 
    global bodiesPx, bodiesPy 
    while True: 
     bodiesPx += UpdateX 
     bodiesPy += UpdateY 
     for i in range(len(bodiesPx)): 
      move(i) 


main() 

這裏是錯誤:!

--------------------------------------------------------------------------- 
TypingError        Traceback (most recent call last) 
<ipython-input-29-03f769017233> in <module>() 
    27 bodiesVy = bodiesVy.astype('float64') 
    28 
---> 29 @vectorize(['float64(float64)'],target="gpu") 
    30 def UpdateX(i): 
    31  print (i) 

C:\Users\Gavin\Anaconda3\lib\site-packages\numba\npyufunc\decorators.py in wrap(func) 
    108   vec = Vectorize(func, **kws) 
    109   for sig in ftylist: 
--> 110    vec.add(sig) 
    111   if len(ftylist) > 0: 
    112    vec.disable_compile() 

C:\Users\Gavin\Anaconda3\lib\site-packages\numba\npyufunc\deviceufunc.py in add(***failed resolving arguments***) 
    388   kernelsource = self._get_kernel_source(self._kernel_template, 
    389            devfnsig, funcname) 
--> 390   corefn, return_type = self._compile_core(devfnsig) 
    391   glbl = self._get_globals(corefn) 
    392   sig = signature(types.void, *([a[:] for a in args] + [return_type[:]])) 

C:\Users\Gavin\Anaconda3\lib\site-packages\numba\cuda\vectorizers.py in _compile_core(self, sig) 
    15 class CUDAVectorize(deviceufunc.DeviceVectorize): 
    16  def _compile_core(self, sig): 
---> 17   cudevfn = cuda.jit(sig, device=True, inline=True)(self.pyfunc) 
    18   return cudevfn, cudevfn.cres.signature.return_type 
    19 

C:\Users\Gavin\Anaconda3\lib\site-packages\numba\cuda\decorators.py in device_jit(func) 
    96   def device_jit(func): 
    97    return compile_device(func, restype, argtypes, inline=inline, 
---> 98         debug=debug) 
    99 
    100   if device: 

C:\Users\Gavin\Anaconda3\lib\site-packages\numba\cuda\compiler.py in compile_device(pyfunc, return_type, args, inline, debug) 
    120 
    121 def compile_device(pyfunc, return_type, args, inline=True, debug=False): 
--> 122  cres = compile_cuda(pyfunc, return_type, args, debug=debug, inline=inline) 
    123  devfn = DeviceFunction(cres) 
    124 

C:\Users\Gavin\Anaconda3\lib\site-packages\numba\cuda\compiler.py in compile_cuda(pyfunc, return_type, args, debug, inline) 
    38         return_type=return_type, 
    39         flags=flags, 
---> 40         locals={}) 
    41 
    42  library = cres.library 

C:\Users\Gavin\Anaconda3\lib\site-packages\numba\compiler.py in compile_extra(typingctx, targetctx, func, args, return_type, flags, locals, library) 
    663  pipeline = Pipeline(typingctx, targetctx, library, 
    664       args, return_type, flags, locals) 
--> 665  return pipeline.compile_extra(func) 
    666 
    667 

C:\Users\Gavin\Anaconda3\lib\site-packages\numba\compiler.py in compile_extra(self, func) 
    364     raise e 
    365 
--> 366   return self.compile_bytecode(bc, func_attr=self.func_attr) 
    367 
    368  def compile_bytecode(self, bc, lifted=(), lifted_from=None, 

C:\Users\Gavin\Anaconda3\lib\site-packages\numba\compiler.py in compile_bytecode(self, bc, lifted, lifted_from, func_attr) 
    373   self.lifted_from = lifted_from 
    374   self.func_attr = func_attr 
--> 375   return self._compile_bytecode() 
    376 
    377  def compile_internal(self, bc, func_attr=DEFAULT_FUNCTION_ATTRIBUTES): 

C:\Users\Gavin\Anaconda3\lib\site-packages\numba\compiler.py in _compile_bytecode(self) 
    650 
    651   pm.finalize() 
--> 652   return pm.run(self.status) 
    653 
    654 

C:\Users\Gavin\Anaconda3\lib\site-packages\numba\compiler.py in run(self, status) 
    249      # No more fallback pipelines? 
    250      if is_final_pipeline: 
--> 251       raise patched_exception 
    252      # Go to next fallback pipeline 
    253      else: 

C:\Users\Gavin\Anaconda3\lib\site-packages\numba\compiler.py in run(self, status) 
    241    for stage, stage_name in self.pipeline_stages[pipeline_name]: 
    242     try: 
--> 243      res = stage() 
    244     except _EarlyPipelineCompletion as e: 
    245      return e.result 

C:\Users\Gavin\Anaconda3\lib\site-packages\numba\compiler.py in stage_nopython_frontend(self) 
    461     self.args, 
    462     self.return_type, 
--> 463     self.locals) 
    464 
    465   with self.fallback_context('Function "%s" has invalid return type' 

C:\Users\Gavin\Anaconda3\lib\site-packages\numba\compiler.py in type_inference_stage(typingctx, interp, args, return_type, locals) 
    778 
    779  infer.build_constraint() 
--> 780  infer.propagate() 
    781  typemap, restype, calltypes = infer.unify() 
    782 

C:\Users\Gavin\Anaconda3\lib\site-packages\numba\typeinfer.py in propagate(self) 
    563    self.debug.propagate_finished() 
    564   if errors: 
--> 565    raise errors[0] 
    566 
    567  def add_type(self, var, tp, unless_locked=False): 

C:\Users\Gavin\Anaconda3\lib\site-packages\numba\typeinfer.py in propagate(self, typeinfer) 
    109   for constraint in self.constraints: 
    110    try: 
--> 111     constraint(typeinfer) 
    112    except TypingError as e: 
    113     errors.append(e) 

C:\Users\Gavin\Anaconda3\lib\site-packages\numba\typeinfer.py in __call__(self, typeinfer) 
    335 class IntrinsicCallConstraint(CallConstraint): 
    336  def __call__(self, typeinfer): 
--> 337   self.resolve(typeinfer, typeinfer.typevars, fnty=self.func) 
    338 
    339 

C:\Users\Gavin\Anaconda3\lib\site-packages\numba\typeinfer.py in resolve(self, typeinfer, typevars, fnty) 
    315    head = headtemp.format(fnty, ', '.join(map(str, args))) 
    316    msg = '\n'.join([head, desc]) 
--> 317    raise TypingError(msg, loc=self.loc) 
    318   typeinfer.add_type(self.target, sig.return_type) 
    319   # If the function is a bound function and its receiver type 

TypingError: Failed at nopython (nopython frontend) 
Invalid usage of - with parameters (readonly array(float64, 1d, C), float64) 
Known signatures: 
* (int64, int64) -> int64 
* (int64, uint64) -> int64 
* (uint64, int64) -> int64 
* (uint64, uint64) -> uint64 
* (float32, float32) -> float32 
* (float64, float64) -> float64 
* (complex64, complex64) -> complex64 
* (complex128, complex128) -> complex128 
* (uint32,) -> uint64 
* (uint16,) -> uint64 
* (uint8,) -> uint64 
* (uint64,) -> uint64 
* (int16,) -> int64 
* (int32,) -> int64 
* (int64,) -> int64 
* (int8,) -> int64 
* (float32,) -> float32 
* (float64,) -> float64 
* (complex64,) -> complex64 
* (complex128,) -> complex128 
* parameterized 
File "<ipython-input-29-03f769017233>", line 33 

任何想法,將不勝感激 感謝

+0

這是建立在工作代碼,或者可能是一個文檔的例子嗎?如果是這樣如何延伸?您是否嘗試過使用更簡單的功能?舉個例子,沒有全局變量?我認爲你需要採取一些基本的調試步驟。我不認爲這裏有足夠的'numba'專業知識來幫助你閱讀代碼和錯誤。並添加一個numba標籤。 – hpaulj

回答

0

從檢查代碼中可以看到很多問題:

相關問題