小编Tec*_*Guy的帖子

cuda 的向量化,一个以复数作为输入,一个复数作为输出的函数在 numba 中失败

我使用了一个程序来绘制曼德布罗图,并使用 njit 让它在 CPU 线程上运行。现在我想生成一个 32k 的图像,但即使是整个线程也太慢了。所以我试图让代码在 GPU 上运行。这是代码:

from numba import njit, cuda, vectorize
from PIL import Image, ImageDraw


@vectorize(['complex128(complex128)'], target='cuda')
def mandelbrot(c):

    z = 0
    n = 0
    while abs(z) <= 2 and n < 80:
        z = z*z + c
        n += 1
    return n


def vari(WIDTH, HEIGHT, RE_START, RE_END, IM_START, IM_END, draw):

    for x in range(0, WIDTH):

        for y in range(0, HEIGHT):

            print(x)
            # Convert pixel coordinate to complex number
            c = complex(RE_START + (x / …
Run Code Online (Sandbox Code Playgroud)

cuda cpython vectorization numba

7
推荐指数
2
解决办法
654
查看次数

标签 统计

cpython ×1

cuda ×1

numba ×1

vectorization ×1