add time sum
MODIFY
tinygrad/helpers.py
tinygrad/helpers.py
@@ -36,6 +36,6 @@ def get_available_llops():
name = op[len("ops_"):].upper()
DEFAULT = name if os.environ.get(name, 0) == "1" else DEFAULT
try: _buffers[name] = [cls for cname, cls in inspect.getmembers(importlib.import_module('tinygrad.llops.'+op), inspect.isclass) if (cname.upper() == name + "BUFFER")][0]
- except ImportError as e:
+ except ImportError as e: # NOTE: this can't be put on one line due to mypy issue
print(op, "not available", e)
return _buffers, DEFAULT
\ No newline at end of file

MODIFY
tinygrad/llops/ops_gpu.py
tinygrad/llops/ops_gpu.py
@@ -22,7 +22,7 @@ class CLBuffer:
else: CL.mem_used -= self.cl.size
class CL:
- CACHE, kernel_count, mem_used, ops_sum = None, -1, 0, 0.0
+ CACHE, kernel_count, mem_used, time_sum, ops_sum = None, -1, 0, 0.0, 0.0
BUFFER_CACHE : Dict[int, List[cl.Buffer]] = defaultdict(list)
cl_ctx : Optional[cl.Context] = None
cl_queue : Optional[cl.CommandQueue] = None
@@ -56,9 +56,10 @@ class CLProgram:
else: e = self.clprg(CL().cl_queue, *args)
if DEBUG >= 2: CL.cl_queue.finish()
if DEBUG >= 1:
+ CL.time_sum += 0 if DEBUG <= 1 or CL.CACHE is not None else (e.profile.end - e.profile.start)
CL.ops_sum += op_estimate
print(f"**CL** {CL.kernel_count:6d} {self.name:20s} args {len(args[2:]):5d} size {prod(args[0]):8d} kernels {str(args[0]):18s} {str(args[1]):12s} OPs {op_estimate/1e6:5.1f}M/{CL.ops_sum/1e9:7.2f}G " + \
- ("" if DEBUG <= 1 or CL.CACHE is not None else f"runtime {(e.profile.end - e.profile.start)/1e3:9.2f} us ({op_estimate/(e.profile.end - e.profile.start):8.2f} GFLOPS)"))
+ ("" if DEBUG <= 1 or CL.CACHE is not None else f"tm {(e.profile.end - e.profile.start)/1e3:9.2f}us/{CL.time_sum/1e6:9.2f}ms ({op_estimate/(e.profile.end - e.profile.start):8.2f} GFLOPS)"))
if DEBUG >= 4: print(self.prg)
# **** end CL wrappers ****

MODIFY
tinygrad/shapetracker.py
tinygrad/shapetracker.py
@@ -13,10 +13,8 @@ def to_shape_strides(shape:Tuple[int, ...], strides:Tuple[int, ...]) -> List[Tup
assert len(shape) == len(strides)
ret = [(shape[0], strides[0])]
for i in range(1, len(shape)):
- if (strides[i] != 0 and ret[-1][1] == shape[i]*strides[i]) or (strides[i] == 0 and ret[-1][1] == 0):
- ret[-1] = (ret[-1][0] * shape[i], strides[i])
- else:
- ret.append((shape[i], strides[i]))
+ if (strides[i] != 0 and ret[-1][1] == shape[i]*strides[i]) or (strides[i] == 0 and ret[-1][1] == 0): ret[-1] = (ret[-1][0] * shape[i], strides[i])
+ else: ret.append((shape[i], strides[i]))
return ret
class View:

add time sum