将Cupy转换为Numpy非常慢

huangapple go评论72阅读模式
英文:

convert cupy to numpy is very slow

问题

条件

  • CuPy 版本
    7.0.0
  • 操作系统/平台
    Ubuntu 18.04
  • CUDA 版本
    10.1

重现代码

import cupy as np
import time
size = 60000000
tag = np.zeros(size)
#np.random.shuffle(tag)
value = np.random.random(size)
starttime = time.perf_counter()
for i in range(100):
    tag += (value > 0.3) * 100
print(time.perf_counter() - starttime)
starttime = time.perf_counter()
cpu_value = np.asnumpy(value)
print(time.perf_counter() - starttime)
  • 将 CuPy 转换为 NumPy 非常慢
    结果是

0.02095769099832978
6.170492547998947

英文:

#Condition

  • CuPy version
    7.0.0
  • OS/Platform
    Ubuntu 18.04
  • CUDA version
    10.1

Code to reproduce

import cupy as np
import time
size = 60000000
tag = np.zeros(size)
#np.random.shuffle(tag)
value = np.random.random(size)
starttime = time.perf_counter()
for i in range(100):
    tag +=(value> 0.3)*100
print (time.perf_counter() - starttime)
starttime = time.perf_counter()
cpu_value = np.asnumpy(value)
print (time.perf_counter() - starttime)
  • convert cupy to numpy is very slow
    The result is
    > 0.02095769099832978
    > 6.170492547998947

答案1

得分: 1

从CuPy转换到NumPy涉及将数据从GPU内存复制到CPU。
这个操作很昂贵,预计会很慢。理想情况下,您希望数据在GPU上尽可能长时间地存在,只有在绝对必要时才将其移动到CPU。

英文:

Converting from CuPy to NumPy involves doing a copy from the GPU memory to the CPU.
This operation is expensive and is expected to be slow. Ideally, you want your data to live in the GPU as long as possible and only move it to the CPU when it is strictly necessary.

huangapple
  • 本文由 发表于 2020年1月3日 20:40:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/59578835.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定