Documentation: Multiple GPUs
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 35/100
- Issue 类型
- 文档
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- python
调研方向
首先查看提供的 Python 示例和 repository 中现有的文档示例,以确定多 GPU 示例应放置在哪里。确认该示例正确且可复现,然后将其添加到适当的文档位置;当示例解释了多 GPU 设置并按描述正常工作时,即视为完成。
由索引模型根据 Issue 内容生成。
描述
I think it would be great to have an example for using multiple GPUs.
Here is what I tried. If thats the right way to do it, then you may add it as an example.
It seems to scale fine (tested up to 7 GPUs) and nvidia-smi reports 96% util.
import time
import numpy as np
import arrayfire as af
import argparse
af.set_backend('cuda')
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('gpus', type=int)
parser.add_argument('-runs', type=int, default=100)
args = parser.parse_args()
GPUS = args.gpus
N = 5000
runs = args.runs
# The simple task we want to solve:
# we have a huge list of vectors X and want to calculate the distance between all of them
# this will result in a huge distance matrix M
# the resulting matrix should be multiplied by a vector alpha
X = np.random.rand(100, N)
Alpha = np.random.rand(N,1)
#copy data once:
xGPU = []
alphaGPU = []
for i in range(GPUS):
af.set_device(i)
x = af.to_array(X)
xGPU.append(x)
alpha = af.to_array(Alpha)
alphaGPU.append(alpha)
sub = lambda a,b: a - b
print("init finished")
for _ in range(runs):
startTime = time.time()
splitSize = int(np.ceil(N / GPUS))
#print("Temp data will ocupy at least {:.2f} MB on the gpu.".format((X.shape[0] * splitSize * X.shape[1]) *8 /1024/1024))
result = []
for i in range(GPUS):
af.set_device(i)
x = xGPU[i]
alpha = alphaGPU[i]
start = i*splitSize
end = min((i+1)*splitSize, N)
diff = af.broadcast(sub, af.tile(x[:,start:end],1,1,x.shape[1]), af.moddims(x,x.shape[0],1,x.shape[1]))
diff = af.sqrt(af.sum(af.pow(diff,2),0) )
r = af.matmul(af.moddims(diff, diff.shape[1], diff.shape[2]), alpha)
result.append(r)
total = 0
for i in range(GPUS):
af.set_device(i)
total += af.sum(result[i])
print("Took {} sec".format(time.time() - startTime ))
- 主要语言
- Python
- 星标
- 422
- 派生
- 63
- PR 合并指标
- 30 天内没有已合并 PR
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
arrayfire/arrayfire-python 的其他 Issue
-
难度 5/5 一周以上 新手友好度 25/100
arrayfire/arrayfire-python#271 ·
-
难度 5/5 一周以上 新手友好度 25/100
arrayfire/arrayfire-python#270 ·
-
难度 4/5 3-5 天 新手友好度 35/100
arrayfire/arrayfire-python#269 ·
-
难度 4/5 3-5 天 新手友好度 38/100
arrayfire/arrayfire-python#268 · 1 条评论 ·
-
难度 3/5 1-2 天 新手友好度 48/100
arrayfire/arrayfire-python#267 · 1 条评论 · 1 个 reaction ·
查看 arrayfire/arrayfire-python 的全部 Issue
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 90/100
learningequality/ricecooker#747 ·
-
难度 2/5 1-3 小时 新手友好度 68/100
BSData/horus-heresy-3rd-edition#3171 ·
-
enhancement
难度 2/5 1-3 小时 新手友好度 72/100
-
难度 2/5 1-3 小时 新手友好度 76/100
run-llama/llama_index#23199 ·
-
难度 2/5 1-3 小时 新手友好度 84/100
KhronosGroup/glTF-Blender-IO#2769 ·