Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions python/tvm/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
# ----------------------------
# Python3 version.
# ----------------------------
if not (sys.version_info[0] >= 3 and sys.version_info[1] >= 8):
PY3STATEMENT = "The minimal Python requirement is Python 3.8"
if not (sys.version_info[0] >= 3 and sys.version_info[1] >= 9):
PY3STATEMENT = "The minimal Python requirement is Python 3.9"
raise Exception(PY3STATEMENT)

# ----------------------------
Expand All @@ -38,9 +38,8 @@
def _load_lib():
"""Load libary by searching possible path."""
lib_path = libinfo.find_lib_path()
# The dll search path need to be added explicitly in
# windows after python 3.8
if sys.platform.startswith("win32") and sys.version_info >= (3, 8):
# The dll search path need to be added explicitly in windows
if sys.platform.startswith("win32"):
for path in libinfo.get_dll_directories():
os.add_dll_directory(path)
lib = ctypes.CDLL(lib_path[0], ctypes.RTLD_GLOBAL)
Expand Down
8 changes: 4 additions & 4 deletions python/tvm/script/parser/core/diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,10 @@ def _emit(self, node: doc.AST, message: str, level: diagnostics.DiagnosticLevel)
level : diagnostics.DiagnosticLevel
The diagnostic level.
"""
lineno = node.lineno or 1
col_offset = node.col_offset or self.source.start_column
end_lineno = node.end_lineno or lineno
end_col_offset = node.end_col_offset or col_offset
lineno = getattr(node, "lineno", 1)
col_offset = getattr(node, "col_offset", self.source.start_column)
end_lineno = getattr(node, "end_lineno", lineno)
end_col_offset = getattr(node, "end_col_offset", col_offset)
lineno += self.source.start_line - 1
end_lineno += self.source.start_line - 1
col_offset += self.source.start_column + 1
Expand Down
146 changes: 0 additions & 146 deletions python/tvm/script/parser/core/doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import ast
import inspect
import sys
import typing
from collections import defaultdict

Expand Down Expand Up @@ -319,149 +318,4 @@ def __call__(self, node):
)


def _py_version() -> typing.Tuple[int, int]:
return (sys.version_info.major, sys.version_info.minor)


def _register_constant_handling():
if _py_version() not in [(3, 6), (3, 7)]:
return

def as_constant(f) -> doc.Constant:
def to_doc_func(x: ast.AST) -> doc.Constant:
return doc.Constant(
value=getattr(x, f) if isinstance(f, str) else f(x),
kind=None,
lineno=x.lineno,
col_offset=x.col_offset,
end_lineno=x.lineno,
end_col_offset=x.col_offset,
)

return to_doc_func

register_to_doc("Str")(as_constant("s"))
register_to_doc("NameConstant")(as_constant("value"))
register_to_doc("Num")(as_constant("n"))
register_to_doc("Bytes")(as_constant("s"))
register_to_doc("Ellipsis")(as_constant(lambda _: ...))


def _register_subscription_handling():
if _py_version() >= (3, 9):
return

def subscript_to_doc(x: ast.Subscript) -> doc.Subscript:
if isinstance(x.slice, ast.Slice):
return doc.Subscript(
value=to_doc(x.value),
slice=doc.Slice(
lower=to_doc(x.slice.lower),
upper=to_doc(x.slice.upper),
step=to_doc(x.slice.step),
lineno=getattr(x.slice, "lineno", None),
col_offset=getattr(x.slice, "col_offset", None),
end_lineno=getattr(x.slice, "end_lineno", None),
end_col_offset=getattr(x.slice, "end_col_offset", None),
),
ctx=to_doc(x.ctx),
lineno=getattr(x, "lineno", None),
col_offset=getattr(x, "col_offset", None),
end_lineno=getattr(x, "end_lineno", None),
end_col_offset=getattr(x, "end_col_offset", None),
)
if isinstance(x.slice, ast.ExtSlice):
return doc.Subscript(
value=to_doc(x.value),
slice=doc.Tuple(
elts=[to_doc(i) for i in x.slice.dims],
ctx=doc.Load(
lineno=None,
col_offset=None,
end_lineno=None,
end_col_offset=None,
),
lineno=getattr(x, "lineno", None),
col_offset=getattr(x, "col_offset", None),
end_lineno=getattr(x, "end_lineno", None),
end_col_offset=getattr(x, "end_col_offset", None),
),
ctx=to_doc(x.ctx),
lineno=getattr(x, "lineno", None),
col_offset=getattr(x, "col_offset", None),
end_lineno=getattr(x, "end_lineno", None),
end_col_offset=getattr(x, "end_col_offset", None),
)
if isinstance(x.slice, ast.Index):
return doc.Subscript(
value=to_doc(x.value),
slice=to_doc(x.slice.value),
ctx=to_doc(x.ctx),
lineno=getattr(x, "lineno", None),
col_offset=getattr(x, "col_offset", None),
end_lineno=getattr(x, "end_lineno", None),
end_col_offset=getattr(x, "end_col_offset", None),
)
raise TypeError(f"Unknown subscript type: {type(x.slice)}")

def subscript_from_doc(x: doc.Subscript) -> ast.Subscript:
if isinstance(x.slice, doc.Slice):
result = ast.Subscript(
value=from_doc(x.value),
slice=from_doc(x.slice),
ctx=from_doc(x.ctx),
)
elif isinstance(x.slice, doc.Tuple):

def remap_dim(doc_item: doc.Expr) -> ast.Expr:
ast_item = from_doc(doc_item)
if isinstance(ast_item, (ast.Index, ast.Slice)):
return ast_item
return ast.Index(value=ast_item)

# ast.ExtSlice requires a non-empty list of dims, and each dim must be either
# a Slice or an Index.
if x.slice.elts:
ast_slice = ast.ExtSlice(dims=[*map(remap_dim, x.slice.elts)])
else:
ast_slice = ast.Index(value=ast.Tuple(elts=[], ctx=from_doc(x.ctx)))
result = ast.Subscript(value=from_doc(x.value), slice=ast_slice, ctx=from_doc(x.ctx))
else:
result = ast.Subscript(
value=from_doc(x.value),
slice=ast.Index(value=from_doc(x.slice)),
ctx=from_doc(x.ctx),
)
result.lineno = x.lineno
result.col_offset = x.col_offset
result.end_lineno = x.end_lineno
result.end_col_offset = x.end_col_offset
return result

register_to_doc("Subscript")(subscript_to_doc)
register_from_doc("Subscript")(subscript_from_doc)


def _register_index_handling():
if _py_version() >= (3, 9):
return

def index_to_doc(x: ast.Index) -> doc.Expr:
return to_doc(x.value)

def index_from_doc(x: doc.Expr) -> ast.Index:
result = ast.Index(value=from_doc(x), ctx=from_doc(x.ctx))
result.lineno = x.lineno
result.col_offset = x.col_offset
result.end_lineno = x.end_lineno
result.end_col_offset = x.end_col_offset
return result

register_to_doc("Index")(index_to_doc)
register_from_doc("Index")(index_from_doc)


_register_default()
_register_constant_handling()
_register_subscription_handling()
_register_index_handling()
Loading
Loading