forked from tinygrad/tinygrad
perf: cache const UOp creation [run_process_replay] (#5156)
This commit is contained in:
@@ -60,6 +60,7 @@ class UOp:
|
||||
def max(self, x): return UOp.alu(BinaryOps.MAX, self, x)
|
||||
def min(self, x): return -UOp.alu(BinaryOps.MAX, -self, -x)
|
||||
@staticmethod
|
||||
@functools.lru_cache(maxsize=None)
|
||||
def const(dtype:Optional[DType], b:ConstType|Variable):
|
||||
if isinstance(b, Variable): return UOp(UOps.DEFINE_VAR, dtype, (), b)
|
||||
return UOp(UOps.CONST, dtype, arg=dtypes.as_const(b, dtype) if dtype is not None else b)
|
||||
|
||||
Reference in New Issue
Block a user