Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Option] Add option to set class Var id attribute to 0 by default #393

Merged
merged 4 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion python/hidet/ir/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import string
import operator
import numpy as np
import hidet.option
from .node import Node
from .type import BaseType, TensorType, DataType, TensorPointerType, PointerType, FuncType, StringType, ArrayType
from .type import tensor_pointer_type, string_type, tensor_type, data_type
Expand Down Expand Up @@ -561,7 +562,7 @@ def __init__(self, hint: Optional[str], type: BaseType, name: Optional[str] = No
self.hint: Optional[str] = hint
self.name: Optional[str] = name
self.type: Union[BaseType, TensorType, TensorPointerType, FuncType] = type
self.id: int = self.new_id()
self.id: int = self.new_id() if hidet.option.get_option('debug_show_var_id') else 0
destefy marked this conversation as resolved.
Show resolved Hide resolved

@staticmethod
def new_id():
Expand Down
26 changes: 25 additions & 1 deletion python/hidet/option.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,19 @@ def register_hidet_options():
description='Whether to cache the generated kernels during tuning.',
choices=[True, False],
)
register_option(
name='debug_enable_var_id',
type_hint='bool',
default_value=False,
description='Assign a variable id to each variable in the IR. If set to false, all variable IDs will be 0',
choices=[True, False],
)
register_option(
name='debug_show_var_id',
type_hint='bool',
default_value=False,
description='Whether to show the variable id in the IR.',
description='Whether to show the variable id in the IR.\
Hint: all variable ids will be 0 unless the debug_enable_var_id option is set to True.',
choices=[True, False],
)
register_option(
Expand Down Expand Up @@ -701,12 +709,28 @@ def debug_cache_tuning(enabled: bool = True):
OptionContext.current().set_option('debug_cache_tuning', enabled)


def debug_enable_var_id(enable: bool = True):
"""
Whether to enable var id in the IR.

When this option is enabled, each variable (i.e., hidet.ir.Var) will have a unique id.
Otherwise, each variable's ID will be 0.

Parameters
----------
enable: bool
Whether to enable var id in the IR.
"""
OptionContext.current().set_option('debug_enable_var_id', enable)


def debug_show_var_id(enable: bool = True):
"""
Whether to show the var id in the IR.

When this option is enabled, the IR will show the var id with the format `var@id`, like `x@1` and `d_1@1732`.
Variable (i.e., hidet.ir.Var) a and b is the same var if and only if `a is b` evaluates to True in Python).
Hint: all variable ids will always be 0 unless the debug_enable_var_id option is set to True.',
destefy marked this conversation as resolved.
Show resolved Hide resolved

Parameters
----------
Expand Down