from typing import Any, Optional


class dtype:
  def __init__(self, name: str):
    self.name = name

  def __repr__(self):
    return f"tl.{self.name}"


float16 = dtype("float16")
float32 = dtype("float32")
float64 = dtype("float64")
int8 = dtype("int8")
int16 = dtype("int16")
int32 = dtype("int32")
int64 = dtype("int64")
uint8 = dtype("uint8")
uint16 = dtype("uint16")
uint32 = dtype("uint32")
uint64 = dtype("uint64")
bool = dtype("bool")


class constexpr:
  def __init__(self, value: Any):
    self.value = value

  def __repr__(self):
    return f"constexpr({self.value!r})"

  def __index__(self):
    return int(self.value)

  def __int__(self):
    return int(self.value)

  def __add__(self, other):
    return constexpr(self.value + (other.value if isinstance(other, constexpr) else other))

  def __radd__(self, other):
    return constexpr((other.value if isinstance(other, constexpr) else other) + self.value)

  def __mul__(self, other):
    return constexpr(self.value * (other.value if isinstance(other, constexpr) else other))

  def __rmul__(self, other):
    return constexpr((other.value if isinstance(other, constexpr) else other) * self.value)

  def __floordiv__(self, other):
    v = other.value if isinstance(other, constexpr) else other
    return constexpr(self.value // v)

  def __mod__(self, other):
    v = other.value if isinstance(other, constexpr) else other
    return constexpr(self.value % v)

  def __eq__(self, other):
    v = other.value if isinstance(other, constexpr) else other
    return self.value == v

  def __lt__(self, other):
    v = other.value if isinstance(other, constexpr) else other
    return self.value < v

  def __le__(self, other):
    v = other.value if isinstance(other, constexpr) else other
    return self.value <= v

  def __gt__(self, other):
    v = other.value if isinstance(other, constexpr) else other
    return self.value > v

  def __ge__(self, other):
    v = other.value if isinstance(other, constexpr) else other
    return self.value >= v


def program_id(axis: int) -> int:
  raise RuntimeError("tl.program_id is only valid inside a @tritoncu.jit kernel")


def arange(start: int, end: int):
  raise RuntimeError("tl.arange is only valid inside a @tritoncu.jit kernel")


def load(ptr, mask=None, other=0.0, cache_modifier="", eviction_policy="", volatile=False):
  raise RuntimeError("tl.load is only valid inside a @tritoncu.jit kernel")


def store(ptr, value, mask=None, cache_modifier="", eviction_policy=""):
  raise RuntimeError("tl.store is only valid inside a @tritoncu.jit kernel")


def dot(a, b, acc=None, allow_tf32=True, out_dtype=float32):
  raise RuntimeError("tl.dot is only valid inside a @tritoncu.jit kernel")


def zeros(shape, dtype=float32):
  raise RuntimeError("tl.zeros is only valid inside a @tritoncu.jit kernel")


def full(shape, value, dtype=float32):
  raise RuntimeError("tl.full is only valid inside a @tritoncu.jit kernel")


def where(condition, x, y):
  raise RuntimeError("tl.where is only valid inside a @tritoncu.jit kernel")


def sum(input, axis=0):
  raise RuntimeError("tl.sum is only valid inside a @tritoncu.jit kernel")


def max(input, axis=0):
  raise RuntimeError("tl.max is only valid inside a @tritoncu.jit kernel")


def min(input, axis=0):
  raise RuntimeError("tl.min is only valid inside a @tritoncu.jit kernel")


def reshape(input, shape):
  raise RuntimeError("tl.reshape is only valid inside a @tritoncu.jit kernel")


def trans(input):
  raise RuntimeError("tl.trans is only valid inside a @tritoncu.jit kernel")


def expand_dims(input, axis):
  raise RuntimeError("tl.expand_dims is only valid inside a @tritoncu.jit kernel")


def broadcast_to(input, shape):
  raise RuntimeError("tl.broadcast_to is only valid inside a @tritoncu.jit kernel")


def cast(input, dtype):
  raise RuntimeError("tl.cast is only valid inside a @tritoncu.jit kernel")


def multiple_of(input, values):
  return input


def max_contiguous(input, values):
  return input


def sqrt(x):
  raise RuntimeError("tl.sqrt is only valid inside a @tritoncu.jit kernel")


def exp(x):
  raise RuntimeError("tl.exp is only valid inside a @tritoncu.jit kernel")


def log(x):
  raise RuntimeError("tl.log is only valid inside a @tritoncu.jit kernel")


def sigmoid(x):
  raise RuntimeError("tl.sigmoid is only valid inside a @tritoncu.jit kernel")


def abs(x):
  raise RuntimeError("tl.abs is only valid inside a @tritoncu.jit kernel")


def atomic_add(ptr, val, mask=None, sem="relaxed"):
  raise RuntimeError("tl.atomic_add is only valid inside a @tritoncu.jit kernel")


def atomic_max(ptr, val, mask=None, sem="relaxed"):
  raise RuntimeError("tl.atomic_max is only valid inside a @tritoncu.jit kernel")


def atomic_min(ptr, val, mask=None, sem="relaxed"):
  raise RuntimeError("tl.atomic_min is only valid inside a @tritoncu.jit kernel")


def atomic_and(ptr, val, mask=None, sem="relaxed"):
  raise RuntimeError("tl.atomic_and is only valid inside a @tritoncu.jit kernel")


def atomic_or(ptr, val, mask=None, sem="relaxed"):
  raise RuntimeError("tl.atomic_or is only valid inside a @tritoncu.jit kernel")


def atomic_xor(ptr, val, mask=None, sem="relaxed"):
  raise RuntimeError("tl.atomic_xor is only valid inside a @tritoncu.jit kernel")


def debug_barrier():
  raise RuntimeError("tl.debug_barrier is only valid inside a @tritoncu.jit kernel")
