diff --git a/accel/triton/ops_triton.py b/accel/triton/ops_triton.py index ebb5028e19..e7fd4f036a 100644 --- a/accel/triton/ops_triton.py +++ b/accel/triton/ops_triton.py @@ -10,9 +10,9 @@ import triton # type: ignore # noqa: F401 import triton.language as tl # type: ignore # noqa: F401 from typing import Union, Tuple, Optional, Dict -from tinygrad.ops import UnaryOps, BinaryOps, ReduceOps, LazyOp, Op, ExplicitExecAST, DEBUG, GlobalCounters +from tinygrad.ops import UnaryOps, BinaryOps, ReduceOps, LazyOp, Op, ExplicitExecAST, GlobalCounters from tinygrad.shape import ShapeTracker -from tinygrad.helpers import prod +from tinygrad.helpers import prod, DEBUG from tinygrad.runtime.cuda import CLBuffer from tinygrad.ast import ASTKernel diff --git a/extra/jit.py b/extra/jit.py index 9cebf0f567..ee3d6355eb 100644 --- a/extra/jit.py +++ b/extra/jit.py @@ -2,7 +2,8 @@ from typing import Callable, List, Tuple import itertools from tinygrad.lazy import Device from tinygrad.tensor import Tensor -from tinygrad.ops import DEBUG, GlobalCounters +from tinygrad.helpers import DEBUG +from tinygrad.ops import GlobalCounters class TinyJit: def __init__(self, fxn): diff --git a/extra/kernel_search.py b/extra/kernel_search.py index f9fefbada5..a6cc38ceda 100644 --- a/extra/kernel_search.py +++ b/extra/kernel_search.py @@ -8,8 +8,7 @@ from tinygrad.ops import LazyOp, ReduceOps, BinaryOps, UnaryOps, MovementOps from tinygrad.shape import ShapeTracker, View, ZeroView from tinygrad.llops.ops_gpu import GPUBuffer, CLASTKernel from tinygrad.runtime.opencl import OSX_TIMING_RATIO -from tinygrad.ops import DEBUG -from tinygrad.helpers import getenv +from tinygrad.helpers import getenv, DEBUG from extra.lib_test_ast import test_ast import pickle, dbm diff --git a/extra/onnx.py b/extra/onnx.py index 6b1825941d..7af4e7c8ea 100644 --- a/extra/onnx.py +++ b/extra/onnx.py @@ -1,8 +1,7 @@ import numpy as np from tinygrad.tensor import Tensor from tinygrad.helpers import prod -from tinygrad.ops import DEBUG -from tinygrad.helpers import getenv +from tinygrad.helpers import getenv, DEBUG from onnx.mapping import TENSOR_TYPE_TO_NP_TYPE ONNXLIMIT = getenv("ONNXLIMIT", -1) diff --git a/tinygrad/graph.py b/tinygrad/graph.py index c418ee3e4c..6bcaf635d7 100644 --- a/tinygrad/graph.py +++ b/tinygrad/graph.py @@ -7,8 +7,8 @@ except ImportError: nx = None # graph won't work from collections import defaultdict from typing import Dict, List, Optional -from tinygrad.ops import DeviceBuffer, DEBUG, UnaryOps, BinaryOps, ReduceOps, MovementOps, ProcessingOps, LoadOps, Op, OpType, LazyOp, get_buffers, get_lazyops -from tinygrad.helpers import getenv +from tinygrad.ops import DeviceBuffer, UnaryOps, BinaryOps, ReduceOps, MovementOps, ProcessingOps, LoadOps, Op, OpType, LazyOp, get_buffers, get_lazyops +from tinygrad.helpers import getenv, DEBUG GRAPH, PRUNEGRAPH, GRAPHPATH = getenv("GRAPH", 0), getenv("PRUNEGRAPH", 0), getenv("GRAPHPATH", "/tmp/net") diff --git a/tinygrad/helpers.py b/tinygrad/helpers.py index 3e3a9a8ee5..b4412e2ce7 100644 --- a/tinygrad/helpers.py +++ b/tinygrad/helpers.py @@ -17,6 +17,7 @@ class Timing(object): @functools.lru_cache(maxsize=None) def getenv(key, default=0): return type(default)(os.getenv(key, default)) +DEBUG = getenv("DEBUG", 0) def reduce_shape(shape, axis): return tuple(1 if i in axis else shape[i] for i in range(len(shape))) def shape_to_axis(old_shape, new_shape): diff --git a/tinygrad/lazy.py b/tinygrad/lazy.py index a55a82f24b..f162333327 100644 --- a/tinygrad/lazy.py +++ b/tinygrad/lazy.py @@ -2,9 +2,9 @@ from __future__ import annotations from typing import Optional, Tuple, Union, List, Dict, Any, ClassVar, Type import sys, weakref, os, importlib, inspect from weakref import WeakValueDictionary -from tinygrad.helpers import ConvArgs, prod +from tinygrad.helpers import ConvArgs, prod, DEBUG from tinygrad.shape import ShapeTracker -from tinygrad.ops import DeviceBuffer, UnaryOps, BinaryOps, ReduceOps, MovementOps, ProcessingOps, LoadOps, OpType, LazyOp, get_buffers, map_buffers, DEBUG, GenericExecAST +from tinygrad.ops import DeviceBuffer, UnaryOps, BinaryOps, ReduceOps, MovementOps, ProcessingOps, LoadOps, OpType, LazyOp, get_buffers, map_buffers, GenericExecAST from tinygrad.graph import log_op from tinygrad.helpers import getenv diff --git a/tinygrad/llops/ops_gpu.py b/tinygrad/llops/ops_gpu.py index a2ffe1c214..12f93476eb 100644 --- a/tinygrad/llops/ops_gpu.py +++ b/tinygrad/llops/ops_gpu.py @@ -1,8 +1,8 @@ from __future__ import annotations import numpy as np from typing import List, Tuple, Optional, Dict, Union, Set, Final, Callable -from tinygrad.helpers import prod -from tinygrad.ops import DEBUG, UnaryOps, BinaryOps, ReduceOps, MovementOps, LazyOp, Op, ExplicitExecAST, GlobalCounters +from tinygrad.helpers import prod, DEBUG +from tinygrad.ops import UnaryOps, BinaryOps, ReduceOps, MovementOps, LazyOp, Op, ExplicitExecAST, GlobalCounters from tinygrad.ast import ASTKernel, Token, Types from tinygrad.lazy import IMAGE from tinygrad.shape import ShapeTracker diff --git a/tinygrad/llops/ops_llvm.py b/tinygrad/llops/ops_llvm.py index 638bb39d4b..641fc48a5c 100644 --- a/tinygrad/llops/ops_llvm.py +++ b/tinygrad/llops/ops_llvm.py @@ -2,13 +2,13 @@ from __future__ import annotations import math import functools from typing import Tuple, Union, Dict, Any, List, ClassVar, Optional -from tinygrad.helpers import prod +from tinygrad.helpers import prod, DEBUG from tinygrad.shape import ShapeTracker from tinygrad.ops import LazyOp from tinygrad.ast import ASTKernel import ctypes import numpy as np -from tinygrad.ops import DEBUG, UnaryOps, BinaryOps, ReduceOps, ExplicitExecAST +from tinygrad.ops import UnaryOps, BinaryOps, ReduceOps, ExplicitExecAST from tinygrad.runtime.llvm import LLVM, ir from tinygrad.shape.symbolic import Variable, NumNode, MulNode, DivNode, ModNode, GeNode, LtNode, SumNode, AndNode diff --git a/tinygrad/ops.py b/tinygrad/ops.py index 26882ab6fe..15e681be7b 100644 --- a/tinygrad/ops.py +++ b/tinygrad/ops.py @@ -5,9 +5,6 @@ from typing import Union, Type, NamedTuple, Tuple, Any, List, ClassVar, Optional import functools, operator from tinygrad.helpers import prod from tinygrad.shape import ShapeTracker -from tinygrad.helpers import getenv - -DEBUG = getenv("DEBUG", 0) # these are the llops your accelerator must implement, along with toCpu # the Enum class doesn't work with mypy, this is static. sorry it's ugly diff --git a/tinygrad/runtime/clang.py b/tinygrad/runtime/clang.py index 20726184f1..d185e95047 100644 --- a/tinygrad/runtime/clang.py +++ b/tinygrad/runtime/clang.py @@ -5,7 +5,7 @@ import hashlib import subprocess from collections import defaultdict from typing import List, Final, Dict -from tinygrad.ops import DEBUG +from tinygrad.helpers import DEBUG import platform OSX = platform.system() == "Darwin" diff --git a/tinygrad/runtime/cuda.py b/tinygrad/runtime/cuda.py index 9924030451..097f085cb5 100644 --- a/tinygrad/runtime/cuda.py +++ b/tinygrad/runtime/cuda.py @@ -3,7 +3,8 @@ import pycuda.autoprimaryctx # type: ignore # pylint: disable=unused-import # no import pycuda.driver as cuda # type: ignore from pycuda.compiler import compile # type: ignore import numpy as np -from tinygrad.ops import DEBUG, GlobalCounters +from tinygrad.helpers import DEBUG +from tinygrad.ops import GlobalCounters class CLBuffer: def __init__(self, size): self._cl = cuda.mem_alloc(size) diff --git a/tinygrad/runtime/llvm.py b/tinygrad/runtime/llvm.py index 9206b69bce..2ff70d301f 100644 --- a/tinygrad/runtime/llvm.py +++ b/tinygrad/runtime/llvm.py @@ -1,6 +1,6 @@ from typing import ClassVar -from tinygrad.helpers import getenv -from tinygrad.ops import DEBUG, GlobalCounters +from tinygrad.helpers import getenv, DEBUG +from tinygrad.ops import GlobalCounters import hashlib import time import ctypes diff --git a/tinygrad/runtime/metal.py b/tinygrad/runtime/metal.py index 78c9dcfbd9..d62a13d482 100644 --- a/tinygrad/runtime/metal.py +++ b/tinygrad/runtime/metal.py @@ -2,8 +2,8 @@ import Metal, Cocoa, libdispatch # type: ignore import numpy as np from typing import List, Any -from tinygrad.ops import DEBUG, GlobalCounters -from tinygrad.helpers import prod, getenv +from tinygrad.ops import GlobalCounters +from tinygrad.helpers import prod, getenv, DEBUG import subprocess METAL_XCODE = getenv("METAL_XCODE") diff --git a/tinygrad/runtime/opencl.py b/tinygrad/runtime/opencl.py index 31cf2fdc3a..574ec1dcde 100644 --- a/tinygrad/runtime/opencl.py +++ b/tinygrad/runtime/opencl.py @@ -3,8 +3,8 @@ import numpy as np import pyopencl as cl # type: ignore from typing import Dict, Optional, Tuple, List, ClassVar, Final from collections import defaultdict -from tinygrad.ops import DEBUG, GlobalCounters -from tinygrad.helpers import getenv +from tinygrad.ops import GlobalCounters +from tinygrad.helpers import getenv, DEBUG OSX = platform.system() == "Darwin" OSX_TIMING_RATIO = (125/3) if OSX else 1.0 # see test/external_osx_profiling.py to determine this ratio. it's in like GPU clocks or something diff --git a/tinygrad/shape/__init__.py b/tinygrad/shape/__init__.py index 72e70dc8bc..32aca8fd58 100644 --- a/tinygrad/shape/__init__.py +++ b/tinygrad/shape/__init__.py @@ -2,12 +2,9 @@ from __future__ import annotations import functools from typing import Tuple, Union, List, Optional -from tinygrad.helpers import prod, getenv +from tinygrad.helpers import prod, DEBUG from tinygrad.shape.symbolic import Variable -# TODO: fix DEBUG import -DEBUG = getenv("DEBUG", 0) - @functools.lru_cache(maxsize=None) def to_shape_strides(shape:Tuple[int, ...], strides:Tuple[int, ...]) -> List[Tuple[int, int]]: assert len(shape) == len(strides) diff --git a/tinygrad/tensor.py b/tinygrad/tensor.py index 6ef058103f..b16e578950 100644 --- a/tinygrad/tensor.py +++ b/tinygrad/tensor.py @@ -5,7 +5,7 @@ import numpy as np from tinygrad.helpers import prod, argfix, make_pair, getenv from typing import List, Tuple, Callable, Optional, ClassVar, Type, Union from tinygrad.lazy import Device, LazyBuffer -from tinygrad.ops import DEBUG +from tinygrad.helpers import DEBUG # An instantiation of the Function is the Context class Function: