Ten*_*ero 5 python parallel-processing gpu self-organizing-maps
我正在使用Python的库somoclu
来训练使用Python的自组织地图.该库允许用户在CPU(Intel Core i7-8700)或GPU(GeForce GTX 1080 Ti)上执行培训.
我注意到CPU运行脚本的速度比GPU快,所以我进行了一次扫描,改变了数据点的数量和地图的大小,看看GPU在某些时候是否胜过CPU.这是脚本:
import numpy as np
import somoclu
import time
m = 3 # Number of dimensions
points = [5000, 30000, 80000, 150000, 300000] # Number of datapoints
iterMax = 200 # Max number of iterations
mapSize = [4, 32, 64, 128] # Dimensions of SOM
np.random.seed(0)
#%% SOM
for n in points:
for size in mapSize:
y = np.random.rand(n,m) # Input data
# With CPU
t = time.clock() # Start time
som = somoclu.Somoclu(size,
size,
compactsupport = False,
kerneltype = 0)
som.train(y.astype(np.float32), epochs = iterMax)
elapsedTime = time.clock() - t
# With GPU
t = time.clock() # Start time
som = somoclu.Somoclu(size,
size,
compactsupport = False,
kerneltype = 1)
som.train(y.astype(np.float32), epochs = iterMax)
elapsedTime = time.clock() - t
Run Code Online (Sandbox Code Playgroud)
我用CSV保存了时间,这就是我得到的:
CPU GPU
2.7632589999999997 5.935387999999999
60.340638 82.796062
228.292085 305.75625900000006
861.3243 1141.331934
11.692982999999913 24.568256999999903
330.17140100000006 443.82112400000005
1354.677431 1749.3110039999992
5559.308704 6990.034151000002
29.3726179999976 47.36881999999969
913.3250950000001 1163.5942189999987
3703.653313999999 4615.292857
14868.418703000003 18635.051464000004
37.40133600000263 68.64375999999902
1699.020611 2141.047305
6925.692426000009 8645.564134
27887.844171999997 illegal memory access was encountered
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,CPU在每种情况下都优于GPU(在其上面,当运行具有150000数据点和64x64映射的脚本时,GPU版本崩溃).这怎么可能?那么使用GPU训练SOM有什么好处呢?
编辑:
我在R中尝试了相同的库,在这种语言中,GPU优于CPU.所以显然只是一个Python问题,但我不是编程的专家,无法弄清楚发生了什么.我相信内核运行是一样的,所以它只是改变的界面.让我们看看这是否有助于某人在Python中找到为什么CPU比GPU更快.
根据somoclu 论文中的图 5 ,GPU 速度更快。然而,该论文没有显示广泛的基准测试。我只能建议你的机器,CPU能力更强一些。但你可以研究这篇论文来运行更类似的测试进行比较。
为了确保结果的可复制性,我们使用 Amazon Web Services 提供的公开可用的集群 GPU 实例进行了基准测试。实例类型为 cg1.4xlarge ( https://aws.amazon.com/ec2/instance-types/ ),配备 22 GiB 内存、两个 IntelXeon X5570 四核 CPU 和两个 NVIDIA Tesla M2050 GPU,运行 Ubuntu 12.04。
(16) Somoclu:用于自组织映射的高效并行库,可从: https ://www.researchgate.net/publication/236635216_Somoclu_An_Efficient_Parallel_Library_for_Self-Organizing_Maps
看来您的 CPU 和 GPU 都比 AWS 基准测试更强大。
归档时间: |
|
查看次数: |
220 次 |
最近记录: |