简体   繁体   English

Python NumbaPro GPU矢量化,出现错误:TypingError:在nopython失败(nopython前端)

[英]Python NumbaPro GPU vectorization with Error : TypingError: Failed at nopython (nopython frontend)

I am trying to use numbapro to run a basic simulation of object interactions. 我正在尝试使用numbapro来运行对象交互的基本模拟。 But I am getting this error and im not sure what the problem is. 但我收到此错误,我不确定是什么问题。 I am pretty new with trying to do GPU acceleration :( Here is my code: 我对尝试进行GPU加速非常陌生:(这是我的代码:

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()

And here is the Error: 这是错误:

    ---------------------------------------------------------------------------
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

Any ideas would be much appreciated! 任何想法将不胜感激! Thanks! 谢谢!

There are a number of issues that I see just from inspecting your code: 通过检查您的代码,我发现很多问题:

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TypingError:在 nopython 模式管道中失败(步骤:nopython 前端) - TypingError: Failed in nopython mode pipeline (step: nopython frontend) TypingError:numba 中的 nopython 模式管道失败(步骤:nopython 前端) - TypingError: Failed in nopython mode pipeline (step: nopython frontend) in numba numba.errors.TypingError:在 nopython 模式管道中失败(步骤:nopython 前端) - numba.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend) numba.errors.TypingError:在 nopython 模式管道中失败(步骤:nopython 前端)无法确定变量“argmax”的类型 - numba.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend) Type of variable 'argmax' cannot be determined TypingError:在 nopython 模式管道中失败(步骤:nopython 前端) float32 类型的未知属性“形状” - TypingError: Failed in nopython mode pipeline (step: nopython frontend) Unknown attribute 'shape' of type float32 Python Numba 问题(TypingError:在 nopython 模式管道中失败) - Python Numba issue (TypingError: Failed in nopython mode pipeline) 在 nopython 模式管道中失败(步骤:nopython 前端)没有实现 function Function - Failed in nopython mode pipeline (step: nopython frontend) No implementation of function Function 使用 jit nopython 理解 Numba TypingError - Understanding Numba TypingError with jit nopython 为什么它不工作 numba.core.errors.TypingError:在 nopython 模式管道中失败 - Why it's not working numba.core.errors.TypingError: Failed in nopython mode pipeline 无法在nopython上下文中与对象进行强制转换:python之后出现错误 - Cannot coerce to or from object in nopython context: Error after python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM