external_benchmark_schedule.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. from extra.models.resnet import ResNet50
  2. from tinygrad import Tensor
  3. from tinygrad.helpers import Profiling, Timing, getenv, dedup
  4. from tinygrad.ops import MetaOps
  5. from tinygrad.codegen.kernel import Kernel
  6. if __name__ == "__main__":
  7. mdl = ResNet50()
  8. img = Tensor.empty(64, 3, 224, 224)
  9. PROFILE = getenv("PROFILE", 1)
  10. FORWARD_ONLY = getenv("FORWARD_ONLY", 0)
  11. with Profiling(PROFILE):
  12. with Timing("***** model forward in "):
  13. out = mdl(img)
  14. if not FORWARD_ONLY:
  15. with Profiling(PROFILE):
  16. with Timing("***** model schedule in "):
  17. sched = out.schedule()
  18. asts = dedup([x.ast for x in sched if x.ast.op is MetaOps.KERNEL])
  19. uops = []
  20. with Profiling(PROFILE):
  21. with Timing("***** model uops in "):
  22. for ast in asts:
  23. k = Kernel(ast)
  24. k.hand_coded_optimizations()
  25. k.linearize()
  26. uops.append((k.name, k.uops))
  27. with Profiling(PROFILE, fn="/tmp/schedule.prof"):
  28. with Timing("***** model linearize in "):
  29. for _,u in uops: u.linearize()
  30. #renderer = Device[Device.DEFAULT].renderer
  31. #with Profiling(PROFILE, fn="/tmp/schedule.prof"):
  32. # with Timing("***** model render in "):
  33. # for n,u in uops: renderer.render(n, u)
  34. # snakeviz /tmp/schedule.prof
  35. #with Profiling(PROFILE, fn="/tmp/schedule.prof"):
  36. # with Timing("***** model lower in "):
  37. # eis = list(lower_schedule(sched))
  38. # random makes this slow
  39. #with Profiling(PROFILE):
  40. # with Timing("***** model run in "):
  41. # for ei in eis: ei.run()
  42. # this is all wait
  43. #with Profiling(PROFILE):
  44. # with Timing("***** model finish in "):
  45. # out.data()