Skip to content

Commit 299fa8f

Browse files
authored
am: unset high clocks for sleep (tinygrad#8775)
1 parent c99ae81 commit 299fa8f

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

tinygrad/runtime/support/am/amdev.py

+2
Original file line numberDiff line numberDiff line change
@@ -290,11 +290,13 @@ def __init__(self, devfmt, vram_bar:memoryview, doorbell_bar:memoryview, mmio_ba
290290
ip.init()
291291
if DEBUG >= 2: print(f"am {self.devfmt}: {ip.__class__.__name__} initialized")
292292

293+
self.smu.set_clocks(perf=True)
293294
self.gfx.set_clockgating_state()
294295
self.reg("regSCRATCH_REG7").write(am_version)
295296
if DEBUG >= 2: print(f"am {self.devfmt}: boot done")
296297

297298
def fini(self):
299+
self.smu.set_clocks(perf=False)
298300
for ip in [self.sdma, self.gfx]: ip.fini()
299301

300302
def paddr2cpu(self, paddr:int) -> int: return mv_address(self.vram) + paddr

tinygrad/runtime/support/am/ip.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,6 @@ def init(self):
111111
self._smu_cmn_send_smc_msg_with_param(smu_v13_0_0.PPSMC_MSG_SetDriverDramAddrLow, lo32(self.adev.paddr2mc(self.driver_table_paddr)), poll=True)
112112
self._smu_cmn_send_smc_msg_with_param(smu_v13_0_0.PPSMC_MSG_EnableAllSmuFeatures, 0, poll=True)
113113

114-
for clck in [0x00000C94, 0x000204E1, 0x000105DC, 0x00050B76, 0x00070B76, 0x00040898, 0x00060898, 0x000308FD]:
115-
self._smu_cmn_send_smc_msg_with_param(smu_v13_0_0.PPSMC_MSG_SetSoftMinByFreq, clck, poll=True)
116-
self._smu_cmn_send_smc_msg_with_param(smu_v13_0_0.PPSMC_MSG_SetSoftMaxByFreq, clck, poll=True)
117-
118114
def is_smu_alive(self):
119115
with contextlib.suppress(RuntimeError): self._smu_cmn_send_smc_msg_with_param(smu_v13_0_0.PPSMC_MSG_GetSmuVersion, 0, timeout=100)
120116
return self.adev.mmMP1_SMN_C2PMSG_90.read() != 0
@@ -129,6 +125,12 @@ def read_table(self, table_t, cmd):
129125
return table_t.from_buffer(to_mv(self.adev.paddr2cpu(self.driver_table_paddr), ctypes.sizeof(table_t)))
130126
def read_metrics(self): return self.read_table(smu_v13_0_0.SmuMetricsExternal_t, smu_v13_0_0.TABLE_SMU_METRICS)
131127

128+
def set_clocks(self, perf):
129+
# TODO: Parse from bios.
130+
for clck, (mn, mx) in {smu_v13_0_0.PPCLK_GFXCLK: (0, 3220), smu_v13_0_0.PPCLK_UCLK: (0, 1249), smu_v13_0_0.PPCLK_FCLK: (0, 2301)}.items():
131+
self._smu_cmn_send_smc_msg_with_param(smu_v13_0_0.PPSMC_MSG_SetSoftMinByFreq, clck << 16 | (mx if perf else mn), poll=True)
132+
self._smu_cmn_send_smc_msg_with_param(smu_v13_0_0.PPSMC_MSG_SetSoftMaxByFreq, clck << 16 | (mx if perf else mn), poll=True)
133+
132134
def _smu_cmn_poll_stat(self, timeout=10000): self.adev.wait_reg(self.adev.mmMP1_SMN_C2PMSG_90, mask=0xFFFFFFFF, value=1, timeout=timeout)
133135
def _smu_cmn_send_msg(self, msg, param=0):
134136
self.adev.mmMP1_SMN_C2PMSG_90.write(0) # resp reg

0 commit comments

Comments
 (0)