test_device_speed.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import unittest
  2. from tinygrad import Device
  3. from tinygrad.codegen.uopgraph import UOpGraph
  4. from tinygrad.helpers import Timing, Profiling
  5. class TestDeviceSpeed(unittest.TestCase):
  6. @classmethod
  7. def setUpClass(cls):
  8. cls.dev = Device[Device.DEFAULT]
  9. cls.empty = Device[Device.DEFAULT].renderer.render("test", UOpGraph([]))
  10. def test_empty_compile(self):
  11. with Timing("compiler "):
  12. self.dev.compiler.compile(self.empty)
  13. def test_empty_compile_twice(self):
  14. self.dev.compiler.compile(self.empty)
  15. with Timing("compiler "):
  16. self.dev.compiler.compile(self.empty)
  17. def test_launch_speed(self):
  18. prg_bin = self.dev.compiler.compile(self.empty)
  19. prg = self.dev.runtime("test", prg_bin)
  20. for _ in range(10): prg() # ignore first launches
  21. with Timing("launch 1000x "):
  22. for _ in range(1000): prg()
  23. with Timing("launch 1000x with wait "):
  24. for _ in range(1000): prg(wait=True)
  25. def test_profile_launch_speed(self):
  26. prg_bin = self.dev.compiler.compile(self.empty)
  27. prg = self.dev.runtime("test", prg_bin)
  28. for _ in range(10): prg() # ignore first launches
  29. with Profiling():
  30. for _ in range(1000): prg()
  31. if __name__ == '__main__':
  32. unittest.main()