简体   繁体   English

使用带有numba和CUDA的Python解决线性系统

[英]Solving linear system using Python with numba and CUDA

I am trying to solve a linear system using numba with GPU processing using CUDA. 我正在尝试使用使用CUDA的GPU处理使用numba来解决线性系统。

I have installed all the relevant packages and tested it so it seems that my GPU and CUDA etc is set up properly. 我已经安装了所有相关软件包并对其进行了测试,因此我的GPU和CUDA等设置似乎已正确设置。

My code is: 我的代码是:

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

Commenting the @vectorize... line, the code runs fine. 在评论@vectorize...行时,代码运行正常。 However, when I try to do it with numba and cuda, I get a long list of errors, where I think he most relevant one is: 然而,当我尝试使用numba和cuda时,我会得到一长串错误,我认为他最相关的是:

raise TypingError(msg)
numba.errors.TypingError: Failed at nopython (nopython frontend)
np.linalg.solve() only supported for array types

I assume the problem is that numpy.linalg.solve does not accept the data types required by cuda. 我假设问题是numpy.linalg.solve不接受cuda所需的数据类型。

Am I correct in assuming this? 我假设这是正确的吗? Are there other data types that will work? 是否有其他数据类型可行?

In this example problem, the same data type is passed to the function, so I think the problem lies with numpy.linalg. 这个示例问题中,相同的数据类型被传递给函数,所以我认为问题在于numpy.linalg。

Am I correct in assuming this? 我假设这是正确的吗?

No 没有

Are there other data types that will work? 是否有其他数据类型可行?

No 没有

The problem here is that you cannot use numpy.linalg in code which is targeted to run on the numba GPU backend. 这里的问题是你不能在numba GPU后端运行的代码中使用numpy.linalg

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM