英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论