mirror of
https://github.com/tinygrad/tinygrad.git
synced 2026-06-24 02:14:17 +00:00
perf: cache const UOp creation [run_process_replay] (#5156)
This commit is contained in:
parent
eda2824cd8
commit
2c80583e14
1 changed files with 1 additions and 0 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue