-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Defined a common base class for TensorComputeOp and ComputeOp #2587
Conversation
This fixes #2583 . @ZihengJiang please take a look as you were the original developer of |
21a4457
to
621fc03
Compare
void GatherBound( | ||
const Operation& self, | ||
const std::unordered_map<Tensor, TensorDom>& tensor_dom, | ||
std::unordered_map<IterVar, Range>* out_dom_map) const final; |
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.
Since ComputeOpNode is an exposed structure, can we keep it as the original, but we have another BasicComputeOpNode; ComputeOpNode and TensorComputeOpNode inherit it. in this way, we can avoid so many modifications, also we can save modifications for those in-house projects based on tvm.
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.
The way I see it is that TVM has defined a Node
class, then derived OperationNode
, then derived <X>OpNode
, and so on. Therefore, before this PR, one can find out the class hierarchy only by looking at the names of the classes. I believe this was a good decision and I have seen it in other code bases. That's why I thought to keep it that way after this new class is introduced.
Regarding the amount of modifications needed both inside and outside TVM:
- inside TVM: I agree that quite a few files have been affected. However, the changes are trivial, and have already been done fairly quickly using automatic refactoring tools so no additional effort is needed.
- outside TVM: even if there are a lot of code out there using
ComputeOpNode
(which need to be renamed toScalarComputeOpNode
), I don't see why it's an inconvenient thing to do that. Maybe I missing something?
Moreover, I think keeping the consistency of class naming in TVM (which I hope strives for many years to come) is more important than that level of inconvenience in external projects that depend on it.
That's my two cents.
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.
The way I see it is that TVM has defined a
Node
class, then derivedOperationNode
, then derived<X>OpNode
, and so on. Therefore, before this PR, one can find out the class hierarchy only by looking at the names of the classes. I believe this was a good decision and I have seen it in other code bases. That's why I thought to keep it that way after this new class is introduced.
agree. what i'm suggesting has no conflicts with this point.
Regarding the amount of modifications needed both inside and outside TVM:
- inside TVM: I agree that quite a few files have been affected. However, the changes are trivial, and have already been done fairly quickly using automatic refactoring tools so no additional effort is needed.
- outside TVM: even if there are a lot of code out there using
ComputeOpNode
(which need to be renamed toScalarComputeOpNode
), I don't see why it's an inconvenient thing to do that. Maybe I missing something?
We do have some custmized pass(C++ and python) and costmized schedule template(python) , in which we referenced ComputeOpNode and the code is not in public, if this is merged, we need to replace them with ScalarComputeOpNode when sync with upstream. I believe other inhouse projects may have the similar issue with this.
Moreover, I think keeping the consistency of class naming in TVM (which I hope strives for many years to come) is more important than that level of inconvenience in external projects that depend on it.
I don't see much differences if we change ComputeOpNode to ScalarComputeOpNode, since everybody who uses ComputeOpNode
knew it's a scalar compute, for those who don't know, a comment on ComputeOpNode class will be enough.
That's my two cents.
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.
Thanks @xqdan. I followed the naming scheme you recommended. I used BaseComputeOpNode
for the base class.
621fc03
to
ca3d8d2
Compare
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.
thanks, @derisavi , looks good to me now
include/tvm/operation.h
Outdated
const Stmt& body) const final; | ||
virtual size_t num_schedulable_dims() const = 0; | ||
|
||
static constexpr const char* _type_key = "ComputeOp"; |
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.
BaseComputeOp
here
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.
done. thx.
@@ -185,21 +185,42 @@ class PlaceholderOpNode : public OperationNode { | |||
/*! | |||
* \brief A Compute op that compute a tensor on certain domain. |
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.
stressing that it is the base class of ComputeOp
and TensorComputeOp
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.
done.
Hi @derisavi , it would be better if you can provide a test case to demonstrate using |
ca3d8d2
to
c618e5c
Compare
That RFC (#2583) is only trying to motivate having a common base class and as one of the reasons I've mentioned tensorization. I think tensorization of |
@derisavi If tensorization of |
@ZihengJiang We have tried to tensorize |
@derisavi Then we can aim at supporting it in this PR, or make sure |
Now I'm thinking of how to write such a testcase. Does it make sense to test for correctness (i.e., if |
@derisavi sounds good, you can also check the testcase for |
…on TensorComputeOp ops.
@ZihengJiang I added a testcase that asserts that |
Merged, thanks @derisavi |
…#2587) * Defined a common base class for TensorComputeOp and ComputeOp * Made changes requested by @ZihengJiang * added a testcase to assert that `tensorize` does not have any effect on TensorComputeOp ops.
…#2587) * Defined a common base class for TensorComputeOp and ComputeOp * Made changes requested by @ZihengJiang * added a testcase to assert that `tensorize` does not have any effect on TensorComputeOp ops.
…#2587) * Defined a common base class for TensorComputeOp and ComputeOp * Made changes requested by @ZihengJiang * added a testcase to assert that `tensorize` does not have any effect on TensorComputeOp ops.
…#2587) * Defined a common base class for TensorComputeOp and ComputeOp * Made changes requested by @ZihengJiang * added a testcase to assert that `tensorize` does not have any effect on TensorComputeOp ops.
I renamed the current
ComputeOp
toScalarComputeOp
and created a base class and called itComputeOp
that bothScalarComputeOp
andTensorComputeOp
derive from. I also created a new virtual method (inComputeOp
) callednum_schedulable_dims()
. All names are the first sensible things that came to my mind. Please feel free to suggest improvements to naming, design, etc.