bandwidth.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import tensorflow as tf
  2. from tensorflow import nn
  3. import numpy as np
  4. import time
  5. import sys
  6. sys.path.append('../hostLib/')
  7. from hostLib.layers.conv2d import Conv2D as Conv2DFPGA
  8. from hostLib import load_op
  9. def run(inputShape, filterShape, n):
  10. input = tf.random.uniform(shape=inputShape)
  11. filter = tf.random.uniform(shape=filterShape)
  12. start = time.time()
  13. for i in range(n):
  14. nn.convolution(input, filter)
  15. elapsed_time = time.time() - start
  16. print("shapes: {:22s} {:22s}, count: {:6d}, CPU Conv2D OP time: {:.6f} s".format(str(inputShape), str(filterShape), n, elapsed_time))
  17. start = time.time()
  18. for i in range(n):
  19. load_op.op_lib.MyConv2D_1(input=input, filter=filter)
  20. elapsed_time = time.time() - start
  21. print("shapes: {:22s} {:22s}, count: {:6d}, FPGA Conv2D OP time: {:.6f} s".format(str(inputShape), str(filterShape), n, elapsed_time))
  22. input = tf.random.uniform(shape=[1,228,228,1])
  23. filter = tf.random.uniform(shape=[5,5,1,1])
  24. nn.convolution(input, filter)
  25. load_op.op_lib.MyConv2D_1(input=input, filter=filter)
  26. run((1,228,228,1), (5,5,1,1), 10000)
  27. run((10,228,228,1), (5,5,1,1), 1000)
  28. run((100,228,228,1), (5,5,1,1), 100)
  29. run((1000,228,228,1), (5,5,1,1), 10)
  30. run((1,228,228,1), (5,5,1,1), 10000)
  31. run((1,228,228,10), (5,5,10,1), 1000)
  32. run((1,228,228,100), (5,5,100,1), 100)
  33. run((1,228,228,1000), (5,5,1000,1), 10)
  34. run((1,228,228,1), (5,5,1,1), 10000)
  35. run((1,228,228,1), (5,5,1,10), 1000)
  36. run((1,228,228,1), (5,5,1,100), 100)
  37. run((1,228,228,1), (5,5,1,1000), 10)
  38. run((1,228,228,1), (5,5,1,1000), 10)
  39. run((1,228,228,10), (5,5,10,100), 10)
  40. run((1,228,228,100), (5,5,100,10), 10)
  41. run((1,228,228,1000), (5,5,1000,1), 10)