fix cast in cstyle (#18070)

This commit is contained in:
nimlgen
2026-09-08 23:24:24 +03:00
committed by GitHub
parent d53f06b099
commit 3076916fc3
2 changed files with 10 additions and 2 deletions
+8 -1
View File
@@ -1,7 +1,8 @@
import unittest, ctypes
from tinygrad import Tensor, UOp
from tinygrad.device import Device
from tinygrad.dtype import dtypes
from tinygrad.dtype import dtypes, AddrSpace
from tinygrad.codegen import to_program
from tinygrad.renderer.cstyle import CStyleLanguage
from tinygrad.uop.ops import KernelInfo
@@ -37,4 +38,10 @@ class TestCall(unittest.TestCase):
c.realize()
self.assertEqual(c.item(), 44)
def test_call_stack_pointer(self):
slot = UOp.placeholder((1,), dtypes.uint32, addrspace=AddrSpace.REG)
call = UOp.custom_function("callback", UOp.const(0, dtypes.uint64)).call(slot[0], ret_dtype=dtypes.void)
prg = to_program(call.sink(arg=KernelInfo("call_stack")), Device["CPU"].renderer)
self.assertIn("(unsigned int*)((buf", prg.src[2].arg)
if __name__ == "__main__": unittest.main()
+2 -1
View File
@@ -187,7 +187,8 @@ class CStyleLanguage(Renderer):
return prefix + self.type_map.get(dtype, dtype.name).replace(" ", "_") + str(sz) + suffix
return prefix + self.type_map.get(dtype, dtype.name) + suffix
def render_type(self, u:UOp): return self._render_dtype(u.dtype, u.max_numel(), u.addrspace, shape=u._shape)
def render_type(self, u:UOp):
return self._render_dtype(u.dtype, u.max_numel(), u.addrspace, shape=u._shape, override_ptr=u.op is Ops.INDEX and u.addrspace is AddrSpace.REG)
def render_ptr(self, u:UOp):
# the address of an access, vector-cast if the access reads/writes more lanes than the pointer's scalar type
if u.max_numel() > 1 or u.dtype != u.src[0].dtype: