-
Notifications
You must be signed in to change notification settings - Fork 3.9k
[TVMScript] Support T.buffer_decl using data pointer from Let/Allocate #10099
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
Changes from 4 commits
fcab55e
0c589aa
1b70fa2
a18667c
2454682
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,6 +47,7 @@ | |
| from .tir.node import Slice, BufferSlice | ||
| from .tir.scope_handler import ScopeHandler, WithScopeHandler, ForScopeHandler | ||
| from .tir.special_stmt import SpecialStmt | ||
| from .tir import ty | ||
|
|
||
|
|
||
| class CallArgumentReader(object): | ||
|
|
@@ -447,7 +448,9 @@ def check_decorator(decorators: List[ast.Expr]) -> bool: | |
| # add parameters of function | ||
| for arg in node.params: | ||
| # Note that this case is for T.match_buffer syntax sugar | ||
| if isinstance(arg.ty, (ast.TypeCall, ast.TypeApply)): | ||
| if isinstance(arg.ty, (ast.TypeCall, ast.TypeApply)) and isinstance( | ||
| self.transform(arg.ty.func_name), ty.GenericBufferType | ||
| ): | ||
| result = self.handle_match_buffer_type(arg.ty, arg.name) | ||
| if not isinstance(result, buffer.Buffer): | ||
| self.report_error( | ||
|
|
@@ -1138,6 +1141,29 @@ def transform_TypeTuple(self, node): | |
| """ | ||
| return [self.transform(value) for value in node.values] | ||
|
|
||
| def transform_TypeApply(self, node): | ||
| """Visitor for Type[Type] expressions. | ||
|
|
||
| Mostly used for ``T.Ptr`` expressions. | ||
| """ | ||
| func = self.transform(node.func_name) | ||
|
|
||
| if not isinstance(func, ty.TypeGeneric): | ||
| self.report_error(f"Expected a type but found {type(func).__name__}", node.span) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to above, I'd like to avoid breaking any usage of |
||
|
|
||
| param_types = [] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there is a
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had looked at the |
||
| for param in node.params: | ||
| param_type = self.transform(param) | ||
| if not isinstance(param_type, ty.TypeGeneric): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this for-loop imply that all params of
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't, no. The parameters of At some point, I may see if there's support for renaming |
||
| self.report_error(f"Expected a type but found {type(param).__name__}", param.span) | ||
|
|
||
| param_types.append(param_type) | ||
|
|
||
| if len(param_types) == 1: | ||
| return func[param_types[0]] | ||
| else: | ||
| return func[param_types] | ||
|
|
||
| def handle_match_buffer_type(self, node, buffer_name): | ||
| """special function to handle syntax sugar for match buffer. | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,6 +44,9 @@ def __init__(self, vtype): | |
| self.type = vtype | ||
|
|
||
| def evaluate(self): | ||
| if isinstance(self.type, tvm.ir.Type): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought this change only impact
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This check gets hit when calling
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After thinking on it, I think that it would be cleaner if the type conversion happens during the call to |
||
| return self.type | ||
|
|
||
| return tvm.ir.PrimType(self.type) | ||
|
|
||
|
|
||
|
|
@@ -54,6 +57,8 @@ class GenericPtrType(TypeGeneric): # pylint: disable=abstract-method | |
| """ | ||
|
|
||
| def __getitem__(self, vtype): | ||
| if not isinstance(vtype, TypeGeneric): | ||
| raise TypeError(f"Ptr expects a type argument, but received {type(vtype).__name__}") | ||
| return ConcreteType(tvm.ir.PointerType(vtype.evaluate())) | ||
|
|
||
|
|
||
|
|
@@ -65,6 +70,8 @@ class GenericTupleType(TypeGeneric): # pylint: disable=abstract-method | |
| """ | ||
|
|
||
| def __getitem__(self, vtypes): | ||
| if isinstance(vtypes, TypeGeneric): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems to be a bug fix right?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's correct. If |
||
| vtypes = [vtypes] | ||
| return ConcreteType(tvm.ir.TupleType([vtype.evaluate() for vtype in vtypes])) | ||
|
|
||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use of
GenericPtrTypehere maybe more accurateUh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From my understanding, the
TypeApplyast node would also be used forT.Tuple[type1,type2]type annotations. While I couldn't find any usage ofT.Tupletype annotations,GenericTupleTypeexists intvm.script.tir.tyand would also useTypeApplyin the synr ast. I've added a check forhasattr(func, __getitem__), since that expresses the intent that this is a type that can accept type arguments, and would work for bothT.PtrandT.Tuple.