简体   繁体   English

如何使用Dask在GPU上运行python代码?

[英]How to use Dask to run python code on the GPU?

I have some code that uses Numba cuda.jit in order for me to run on the gpu, and I would like to layer dask on top of it if possible. 我有一些使用Numba cuda.jit的代码,以便在gpu上运行,如果可能的话,我希望在其上添加dask。

Example Code 范例程式码

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from numba import cuda, njit
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))

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

If my function addingNumbersCUDA didn't use any CUDA I would just put client.submit in front of my function (along with gather after) and it would work. 如果我的功能addingNumbersCUDA没有用,我只想把任何CUDA client.submit在我的函数前(连同后收集),它会工作。 But, since I'm using CUDA putting submit in front of the function doesn't work. 但是,由于我使用的是CUDA,因此无法在函数之前放置Submit。 The dask documentation says that you can target the gpu, but it's unclear as to how to actually set it up in practice. 简短的文档说,您可以针对gpu,但是尚不清楚如何在实践中进行实际设置。 How would I set up my function to use dask with the gpu targeted and with cuda.jit if possible? 如何设置目标gpu和cuda.jit的dask功能?

You may want to look through Dask's documentation on GPUs 您可能需要阅读有关GPU的Dask文档

But, since I'm using CUDA putting submit in front of the function doesn't work. 但是,由于我使用的是CUDA,因此无法在函数之前放置Submit。

There is no particular reason why this should be the case. 没有特别的原因可以说明这种情况。 All Dask does it run your function on a different computer. 所有Dask都会在另一台计算机上运行您的功能。 It doesn't change or modify your function in any way. 它不会以任何方式更改或修改您的功能。

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

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