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)
0.02095769099832978 6.170492547998947
答案 0 :(得分:0)
从CuPy转换为NumPy涉及从GPU内存复制到CPU。 该操作很昂贵,并且预计会很慢。理想情况下,您希望数据尽可能长时间地存在于GPU中,并且仅在严格必要时才将其移至CPU。