我想解決一個使用numba和GPU處理使用CUDA的線性系統。用numba和CUDA解決使用Python的線性系統
我已經安裝了所有相關的軟件包並進行了測試,因此看起來我的GPU和CUDA等設置正確。
我的代碼是:
import numpy as np
import time
from numba import vectorize, cuda
@vectorize(['float64(float64, float64)'], target='cuda')
def solver(A, b):
return np.linalg.solve(A, b)
def main():
A = np.random.rand(100, 100).astype(np.float64)
b = np.random.rand(100, 1).astype(np.float64)
start = time.time()
C = solver(A, b)
vector_add_time = time.time() - start
print("Took " + str(vector_add_time) + " seconds to solve")
if __name__ == '__main__':
main()
談到了@vectorize...
線,代碼運行正常。然而,當我嘗試用numba和CUDA做到這一點,我得到的錯誤的一個長長的清單,在那裏我覺得他最相關的一個是:
raise TypingError(msg)
numba.errors.TypingError: Failed at nopython (nopython frontend)
np.linalg.solve() only supported for array types
我認爲問題是,numpy.linalg.solve
不接受的數據類型cuda要求。
我是否正確地承擔了這個?是否還有其他數據類型可以使用?
在this示例問題,相同的數據類型被傳遞給函數,所以我認爲問題在於numpy.linalg。
謝謝羅伯特。我剛剛使用'玩具'問題開始學習cuda工作流程。我想我沒有選擇一個好例子。 – Mike