forked from tinygrad/tinygrad
fix cast in cstyle (#18070)
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user