为什么 dask 在 CUDA 函数上不返回任何内容?

布莱斯酒

我正在尝试将 dask 放在我的 cuda 函数之上,但是当 dask 返回时,我得到一个 NoneType 对象。

from numba import cuda
import numpy as np
from dask.distributed import Client, LocalCluster


@cuda.jit()
def addingNumbersCUDA (big_array, big_array2, save_array):
    i = cuda.grid(1)
    if i < big_array.shape[0]:
        for j in range (big_array.shape[1]):
            save_array[i][j] = big_array[i][j] * big_array2[i][j]


if __name__ == "__main__":
    cluster = LocalCluster()
    client = Client(cluster)


    big_array = np.random.random_sample((100, 3000))
    big_array2  = np.random.random_sample((100, 3000))
    save_array = np.zeros(shape=(100, 3000))


    arraysize = 100
    threadsperblock = 64
    blockspergrid = (arraysize + (threadsperblock - 1))

    x = client.submit(addingNumbersCUDA[blockspergrid, threadsperblock], big_array, big_array2, save_array)


    y = client.gather(x)
    print(y)

我知道您实际上并没有在 cuda 函数中返回,并且结果被推回到您调用的数组中。这就是我得到 noneType 的原因,还是因为我对 cuda 使用了 dask 错误?

布莱斯酒

正如这个问题所指出的:How to use Dask to run python code on the GPU? 作者:Matthew Rocklin,dask 无法处理就地操作。为了解决这个问题,最好添加一个处理 gpu 代码的附加函数。

from numba import cuda
import numpy as np
from dask.distributed import Client, LocalCluster


@cuda.jit()
def addingNumbersCUDA (big_array, big_array2, save_array):
    i = cuda.grid(1)
    if i < big_array.shape[0]:
        for j in range (big_array.shape[1]):
            save_array[i][j] = big_array[i][j] * big_array2[i][j]

def toCUDA (big_array, big_array2, save_array):
    arraysize = 100
    threadsperblock = 64
    blockspergrid = (arraysize + (threadsperblock - 1))

    d_big_array = cuda.to_device(big_array)
    d_big_array2 = cuda.to_device(big_array2)
    d_save_array = cuda.to_device(save_array)

    addingNumbersCUDA[blockspergrid, threadsperblock](d_big_array, d_big_array2, d_save_array)

    save_array = d_save_array.copy_to_host()
    return save_array

if __name__ == "__main__":
    cluster = LocalCluster()
    client = Client(cluster)

    big_array = np.random.random_sample((100, 3000))
    big_array2  = np.random.random_sample((100, 3000))
    save_array = np.zeros(shape=(100, 3000))

    x = client.submit(toCUDA, big_array, big_array2, save_array)


    y = client.gather(x)
    print(y)

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

main函数不返回任何内容。为什么?

为什么 .map 函数在反应中不返回任何内容

如果javascript中的函数不返回任何内容,为什么?

为什么类中的函数不返回任何内容?

为什么.map()不返回任何内容?

CUDA内核不返回任何内容

为什么在我的lambda函数上使用filter()和map()之类的函数时不返回任何值?

为什么在成员函数上为* this指定左值引用不同于不指定任何内容?

为什么Swift的类型检查系统允许返回类型的函数不返回任何内容?

torch.cuda.is_available() 返回 False 为什么?

为什么套接字中的recv()函数不返回任何内容?

为什么我的递归二进制搜索函数不返回任何内容?

Python:在不返回任何内容的函数上

为什么即使在使用cuda安装pytorch之后,`torch.cuda.is_available()`仍返回False?

Mongoose.findOne不返回任何内容,为什么?

Ajax请求不返回任何内容。为什么?

为什么PIG FILTER不返回任何内容?

为什么scanf()总是不返回任何内容?

为什么我的内部联接查询不返回任何内容?

为什么在搜索存在的类时不返回任何内容?

为什么此处理程序不返回任何内容?

为什么python在计算后不返回任何内容?

为什么此提取请求不返回任何内容

FutureBuilder 快照数据不返回任何内容,为什么?

为什么OpenGL方法不返回任何内容?

为什么mycourses [i] .getGrade()不返回任何内容(C ++)?

为什么调用存储过程不返回任何内容?

为什么我的 for 循环不返回任何内容?

为什么 dask 延迟什么都不做?