Files
tinygrad/test/test_device_speed.py
George Hotz 473935125a use comgr to compile (#3248)
* use comgr to compile

* fast

* bfloat16

* move comgr to it's own file

* cleaner style

* comgr in new place

* comgr free + dtype cleanup
2024-01-26 18:27:49 -08:00

39 lines
1.2 KiB
Python

import unittest
from tinygrad import Device
from tinygrad.helpers import Timing, Profiling
from tinygrad.device import Compiled
@unittest.skipIf(not isinstance(Device[Device.DEFAULT], Compiled), "only for compiled backend")
class TestDeviceSpeed(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.dev = Device[Device.DEFAULT]
cls.empty = Device[Device.DEFAULT].renderer("test", [])
def test_empty_compile(self):
with Timing("compiler "):
self.dev.compiler(self.empty)
def test_empty_compile_twice(self):
self.dev.compiler(self.empty)
with Timing("compiler "):
self.dev.compiler(self.empty)
def test_launch_speed(self):
prg_bin = self.dev.compiler(self.empty)
prg = self.dev.runtime("test", prg_bin)
for _ in range(10): prg() # ignore first launches
with Timing("launch 1000x "):
for _ in range(1000): prg()
with Timing("launch 1000x with wait "):
for _ in range(1000): prg(wait=True)
def test_profile_launch_speed(self):
prg_bin = self.dev.compiler(self.empty)
prg = self.dev.runtime("test", prg_bin)
for _ in range(10): prg() # ignore first launches
with Profiling():
for _ in range(1000): prg()
if __name__ == '__main__':
unittest.main()