You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

sgemv.py 946 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/usr/bin/python
  2. import os
  3. import sys
  4. import time
  5. import numpy
  6. from numpy.random import randn
  7. def run_sgemv(N,l):
  8. A = randn(N,N).astype('float32')
  9. B = randn(N).astype('float32')
  10. start = time.time();
  11. for i in range(0,l):
  12. ref = numpy.dot(A,B)
  13. end = time.time()
  14. timediff = (end -start)
  15. mflops = ( 2*N*N) *l / timediff
  16. mflops *= 1e-6
  17. size = "%dx%d" % (N,N)
  18. print("%14s :\t%20f MFlops\t%20f sec" % (size,mflops,timediff))
  19. if __name__ == "__main__":
  20. N=128
  21. NMAX=2048
  22. NINC=128
  23. LOOPS=1
  24. z=0
  25. for arg in sys.argv:
  26. if z == 1:
  27. N = int(arg)
  28. elif z == 2:
  29. NMAX = int(arg)
  30. elif z == 3:
  31. NINC = int(arg)
  32. elif z == 4:
  33. LOOPS = int(arg)
  34. z = z + 1
  35. if 'OPENBLAS_LOOPS' in os.environ:
  36. p = os.environ['OPENBLAS_LOOPS']
  37. if p:
  38. LOOPS = int(p);
  39. print("From: %d To: %d Step=%d Loops=%d" % (N, NMAX, NINC, LOOPS))
  40. print("\tSIZE\t\t\tFlops\t\t\t\t\tTime")
  41. for i in range (N,NMAX+NINC,NINC):
  42. run_sgemv(i,LOOPS)