python程序gpu运行时间_如何使用Dask在GPU上运行python代码?

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.

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. But, since I'm using CUDA putting submit in front of the function doesn't work. The dask documentation says that you can target the gpu, but it's unclear as to how to actually set it up in practice. How would I set up my function to use dask with the gpu targeted and with cuda.jit if possible?

解决方案

You may want to look through Dask's documentation on GPUs

But, since I'm using CUDA putting submit in front of the function doesn't work.

There is no particular reason why this should be the case. All Dask does it run your function on a different computer. It doesn't change or modify your function in any way.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值