簡體   English   中英

如何在GPU中計算對數(python3.5 + numba + CUDA8.0)

[英]How to calculate logarithm in GPU(python3.5+numba+CUDA8.0)

我使用math.log在GPU中計算了對數,這是CUDA Python中支持的Python功能之一 但是失敗了。

我的代碼:

import os,sys,time,math
import pandas as pd
import numpy as np

from numba import cuda, float32

import os

bpg = (3,1) 
tpb = (2,3) 

@cuda.jit
def calcu_T(D,T):


    bx = cuda.blockIdx.x

    tx = cuda.threadIdx.x
    ty = cuda.threadIdx.y

    c_num = D.shape[1]

    ml = math.log(D[tx,ty],2)

D = np.array([[ 0.42487645,0.41607881,0.42027071,0.43751907,0.43512794,0.43656972,0.43940639,0.43864551,0.43447691,0.43120232],
              [2.989578,2.834707,2.942902,3.294948,2.868170,2.975180,3.066900,2.712719,2.835360,2.607334]], dtype=np.float32)
T = np.empty([1,1])

dD = cuda.to_device(D)
dT = cuda.device_array_like(T)
calcu_T[bpg, tpb](dD,dT)

錯誤報告:

Traceback (most recent call last):
  File "G:\myworkspace\python3.5\forte\forte170327\test7.py", line 104, in <module>
    calcu_T[bpg, tpb](dD,dT)
  File "D:\python3.5.3\lib\site-packages\numba\cuda\compiler.py", line 701, in __call__
    kernel = self.specialize(*args)
  File "D:\python3.5.3\lib\site-packages\numba\cuda\compiler.py", line 712, in specialize
    kernel = self.compile(argtypes)
  File "D:\python3.5.3\lib\site-packages\numba\cuda\compiler.py", line 727, in compile
    **self.targetoptions)
  File "D:\python3.5.3\lib\site-packages\numba\cuda\compiler.py", line 36, in core
    return fn(*args, **kwargs)
  File "D:\python3.5.3\lib\site-packages\numba\cuda\compiler.py", line 75, in compile_kernel
    cres = compile_cuda(pyfunc, types.void, args, debug=debug, inline=inline)
  File "D:\python3.5.3\lib\site-packages\numba\cuda\compiler.py", line 36, in core
    return fn(*args, **kwargs)
  File "D:\python3.5.3\lib\site-packages\numba\cuda\compiler.py", line 64, in compile_cuda
    locals={})
  File "D:\python3.5.3\lib\site-packages\numba\compiler.py", line 699, in compile_extra
    return pipeline.compile_extra(func)
  File "D:\python3.5.3\lib\site-packages\numba\compiler.py", line 352, in compile_extra
    return self._compile_bytecode()
  File "D:\python3.5.3\lib\site-packages\numba\compiler.py", line 660, in _compile_bytecode
    return self._compile_core()
  File "D:\python3.5.3\lib\site-packages\numba\compiler.py", line 647, in _compile_core
    res = pm.run(self.status)
  File "D:\python3.5.3\lib\site-packages\numba\compiler.py", line 238, in run
    raise patched_exception
  File "D:\python3.5.3\lib\site-packages\numba\compiler.py", line 230, in run
    stage()
  File "D:\python3.5.3\lib\site-packages\numba\compiler.py", line 444, in stage_nopython_frontend
    self.locals)
  File "D:\python3.5.3\lib\site-packages\numba\compiler.py", line 800, in type_inference_stage
    infer.propagate()
  File "D:\python3.5.3\lib\site-packages\numba\typeinfer.py", line 767, in propagate
    raise errors[0]
  File "D:\python3.5.3\lib\site-packages\numba\typeinfer.py", line 128, in propagate
    constraint(typeinfer)
  File "D:\python3.5.3\lib\site-packages\numba\typeinfer.py", line 379, in __call__
    self.resolve(typeinfer, typevars, fnty)
  File "D:\python3.5.3\lib\site-packages\numba\typeinfer.py", line 401, in resolve
    raise TypingError(msg, loc=self.loc)
numba.errors.TypingError: Failed at nopython (nopython frontend)
Invalid usage of Function(<built-in function log>) with parameters (float32, int64)
Known signatures:
 * (int64,) -> float64
 * (uint64,) -> float64
 * (float32,) -> float32
 * (float64,) -> float64
File "G:\myworkspace\python3.5\forte\forte170327\test7.py", line 28
[1] During: resolving callee type: Function(<built-in function log>)
[2] During: typing of call at G:\myworkspace\python3.5\forte\forte170327\test7.py (28)

這是TypingError嗎? 我該如何糾正?

我使用CUDA Simulator運行這些代碼( 此處顯示為詳細信息),它沒有錯誤。 為什么?

numba運行時告訴您問題

Invalid usage of Function(<built-in function log>) with parameters (float32, int64)
Known signatures:
 * (int64,) -> float64
 * (uint64,) -> float64
 * (float32,) -> float32
 * (float64,) -> float64

即唯一可用的簽名只有一個參數。 基本參數未實現。 如果您在此處查看源代碼 ,則可以看到math.log似乎直接綁定到CUDA log函數,該函數僅計算自然對數。

我的猜測是這是Numba中的一個文檔錯誤 如果它困擾您,我建議您舉報。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM