from typing import Dict, Optional

from hidet.ir.expr import Var
from hidet.ir.type import ScalarType

_primitive_variables: Dict[str, Var] = {}


def attach_pool(var):
    if '_primitive_variables' not in var.__dict__:
        var.__dict__['_primitive_variables'] = _primitive_variables
    return var


def thread_idx(dim='x') -> Var:
    assert dim in ['x', 'y', 'z']
    name = 'threadIdx.{}'.format(dim)
    if name not in _primitive_variables:
        _primitive_variables[name] = attach_pool(Var(hint=name, type=ScalarType('int32'), name=name))
    return _primitive_variables[name]


def block_idx(dim='x') -> Var:
    assert dim in ['x', 'y', 'z']
    name = 'blockIdx.{}'.format(dim)
    if name not in _primitive_variables:
        _primitive_variables[name] = attach_pool(Var(hint=name, type=ScalarType('int32'), name=name))
    return _primitive_variables[name]


def is_primitive_variable(name: str) -> bool:
    return name in _primitive_variables


def get_primitive_variable(name: str) -> Optional[Var]:
    if name in _primitive_variables:
        return _primitive_variables[name]
    else:
        return None

dfe461bb6043067be580b06aee510a88c74d9b59
<mask token>


def is_primitive_variable(name: str) ->bool:
    return name in _primitive_variables


<mask token>

<mask token>


def thread_idx(dim='x') ->Var:
    assert dim in ['x', 'y', 'z']
    name = 'threadIdx.{}'.format(dim)
    if name not in _primitive_variables:
        _primitive_variables[name] = attach_pool(Var(hint=name, type=
            ScalarType('int32'), name=name))
    return _primitive_variables[name]


def block_idx(dim='x') ->Var:
    assert dim in ['x', 'y', 'z']
    name = 'blockIdx.{}'.format(dim)
    if name not in _primitive_variables:
        _primitive_variables[name] = attach_pool(Var(hint=name, type=
            ScalarType('int32'), name=name))
    return _primitive_variables[name]


def is_primitive_variable(name: str) ->bool:
    return name in _primitive_variables


def get_primitive_variable(name: str) ->Optional[Var]:
    if name in _primitive_variables:
        return _primitive_variables[name]
    else:
        return None

<mask token>


def attach_pool(var):
    if '_primitive_variables' not in var.__dict__:
        var.__dict__['_primitive_variables'] = _primitive_variables
    return var


def thread_idx(dim='x') ->Var:
    assert dim in ['x', 'y', 'z']
    name = 'threadIdx.{}'.format(dim)
    if name not in _primitive_variables:
        _primitive_variables[name] = attach_pool(Var(hint=name, type=
            ScalarType('int32'), name=name))
    return _primitive_variables[name]


def block_idx(dim='x') ->Var:
    assert dim in ['x', 'y', 'z']
    name = 'blockIdx.{}'.format(dim)
    if name not in _primitive_variables:
        _primitive_variables[name] = attach_pool(Var(hint=name, type=
            ScalarType('int32'), name=name))
    return _primitive_variables[name]


def is_primitive_variable(name: str) ->bool:
    return name in _primitive_variables


def get_primitive_variable(name: str) ->Optional[Var]:
    if name in _primitive_variables:
        return _primitive_variables[name]
    else:
        return None

<mask token>
_primitive_variables: Dict[str, Var] = {}


def attach_pool(var):
    if '_primitive_variables' not in var.__dict__:
        var.__dict__['_primitive_variables'] = _primitive_variables
    return var


def thread_idx(dim='x') ->Var:
    assert dim in ['x', 'y', 'z']
    name = 'threadIdx.{}'.format(dim)
    if name not in _primitive_variables:
        _primitive_variables[name] = attach_pool(Var(hint=name, type=
            ScalarType('int32'), name=name))
    return _primitive_variables[name]


def block_idx(dim='x') ->Var:
    assert dim in ['x', 'y', 'z']
    name = 'blockIdx.{}'.format(dim)
    if name not in _primitive_variables:
        _primitive_variables[name] = attach_pool(Var(hint=name, type=
            ScalarType('int32'), name=name))
    return _primitive_variables[name]


def is_primitive_variable(name: str) ->bool:
    return name in _primitive_variables


def get_primitive_variable(name: str) ->Optional[Var]:
    if name in _primitive_variables:
        return _primitive_variables[name]
    else:
        return None

from typing import Dict, Optional

from hidet.ir.expr import Var
from hidet.ir.type import ScalarType

_primitive_variables: Dict[str, Var] = {}


def attach_pool(var):
    if '_primitive_variables' not in var.__dict__:
        var.__dict__['_primitive_variables'] = _primitive_variables
    return var


def thread_idx(dim='x') -> Var:
    assert dim in ['x', 'y', 'z']
    name = 'threadIdx.{}'.format(dim)
    if name not in _primitive_variables:
        _primitive_variables[name] = attach_pool(Var(hint=name, type=ScalarType('int32'), name=name))
    return _primitive_variables[name]


def block_idx(dim='x') -> Var:
    assert dim in ['x', 'y', 'z']
    name = 'blockIdx.{}'.format(dim)
    if name not in _primitive_variables:
        _primitive_variables[name] = attach_pool(Var(hint=name, type=ScalarType('int32'), name=name))
    return _primitive_variables[name]


def is_primitive_variable(name: str) -> bool:
    return name in _primitive_variables


def get_primitive_variable(name: str) -> Optional[Var]:
    if name in _primitive_variables:
        return _primitive_variables[name]
    else:
        return None
