如何使python脚本在GPU上运行

如何使python脚本在GPU上运行,python,gpu,Python,Gpu,我创建了一个脚本来查找pi中的数字: from math import pi from mpmath import mp from time import sleep as sleep def loop(find): #Breaks the find string into a list findList = [] print('Finding ' + str(find)) num = 1000 while True: m

我创建了一个脚本来查找pi中的数字:

from math import pi
from mpmath import mp
from time import sleep as sleep


def loop(find):

    #Breaks the find string into a list

    findList = []


    print('Finding ' + str(find))

    num = 1000

    while True:

        mp.dps = num

        string = str(mp.pi)

        result = string.find(str(find))

        if result == -1:

            print("Couldn't find " + str(find) + " within the first " + str(num) + " of Pi. Looking moving into the first " + str(num * 10) + " digits instead")

            num = num * 10

            continue

            pass

        else:

            print(str(find )+ ' was found at character: ' + str(result))
            break

        pass

    pass

def main():

    find = input("What do you want to find: ")


    find = int(find)
    character = loop(find)

    
    


if True:

    main()

    input = ()
当输入一个很长的数字时,由于明显的原因,它需要很长的时间来处理。我正在运行Intel i5-9300h和GTX 1650。我想知道1)我是否可以让这段代码在我的GPU而不是CPU上运行2)如果可以,我该怎么做?3) 它甚至会对性能有好处吗

非常感谢您的任何帮助。

我想这会对您的需求有所帮助。它可以运行python代码(即图形卡)。使用CUDA进行数学运算通常比使用CPU更快,因为它具有更好的多线程处理能力,然而,您是否能从中获益取决于实现。在您的示例中,我认为您必须编写一个可以以多线程方式近似pi的函数,以便利用CUDA提供的功能