Closed xichaoqiang closed 4 years ago
I compare the compute speed with arrayfire,cupy,and numpy.
The resuts show cupy is a bit faster than arrayfire.
Is there another way to conver af.array to np.array?
Is the speed of convert of af.array to np.array slow?
import arrayfire as af import numpy as np import cupy as cp from array import array from time import time import numpy.random_intel as rndi N=2000 ru=rndi.random_sample((N,N)).astype(np.float32) x_af=af.np_to_af_array(ru) x_np=ru.copy() x_cp=cp.array(ru) print("N=",N) t0=time();r1=af.matmul(x_af,x_af);r1=np.array(r1);t1=time()-t0 print("af t1=",t1) t0=time();r2=af.matmul(x_af+1.0,x_af+1.0);r2=np.array(r2);t2=time()-t0 print("af t2=",t2) t0=time();r3=cp.matmul(x_cp,x_cp);r3=cp.asnumpy(r3);t3=time()-t0 print("cp t3=",t3) t0=time();r4=cp.matmul(x_cp+1.0,x_cp+1.0);r4=cp.asnumpy(r4);t4=time()-t0 print("cp t4=",t4) t0=time();r5=np.matmul(x_np,x_np);t5=time()-t0 print("np t5=",t5) t0=time();r6=np.matmul(x_np+1.0,x_np+1.0);t6=time()-t0 print("np t6=",t6)
Resut shows that.
N= 2000 af t1= 0.030921220779418945 af t2= 0.03490591049194336 cp t3= 0.016954898834228516 cp t4= 0.01795172691345215 np t5= 0.10272407531738281 np t6= 0.11370682716369629
N= 3000 af t1= 0.2603302001953125 af t2= 0.19445013999938965 cp t3= 0.061836957931518555 cp t4= 0.05884242057800293 np t5= 0.27725768089294434 np t6= 0.3281223773956299
N= 5000 af t1= 0.5754146575927734 af t2= 0.3031926155090332 cp t3= 0.20644783973693848 cp t4= 0.19946646690368652 np t5= 1.2706019878387451 np t6= 1.3493928909301758
N= 8000 af t1= 0.9365062713623047 af t2= 0.7700843811035156 cp t3= 0.5515463352203369 cp t4= 0.5555505752563477 np t5= 5.050236940383911 np t6= 5.4347453117370605
N= 10000 af t1= 1.2895522117614746 af t2= 1.3114979267120361 cp t3= 0.9285182952880859 cp t4= 0.9394872188568115 np t5= 9.278713941574097 np t6= 9.743171691894531
When I try the .to_ndarray() function,the speed of arrarfire is faster than before.
I compare the compute speed with arrayfire,cupy,and numpy.
The resuts show cupy is a bit faster than arrayfire.
Is there another way to conver af.array to np.array?
Is the speed of convert of af.array to np.array slow?
Resut shows that.