-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[FFI] Provide Field Visit bridge so we can do gradual transition #18091
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
d7eb220 to
f6db7c8
Compare
Member
Author
|
Example // can he in header file
struct TestAttrs : public AttrsNodeReflAdapter<TestAttrs> {
int axis;
String name;
Array<PrimExpr> padding;
TypedEnvFunc<int(int)> func;
// replaces VisitAttrs
static void RegisterReflection() {
namespace refl = tvm::ffi::reflection;
refl::ObjectDef<TestAttrs>()
.def_ro("axis", &TestAttrs::axis, "axis field", refl::DefaultValue(10))
.def_ro("name", &TestAttrs::name, "name")
.def_ro("padding", &TestAttrs::padding, "padding of input",
refl::DefaultValue(Array<PrimExpr>({0, 0})))
.def_ro("func", &TestAttrs::func, "some random env function",
refl::DefaultValue(TypedEnvFunc<int(int)>(nullptr)));
}
static constexpr const char* _type_key = "attrs.TestAttrs";
TVM_FFI_DECLARE_FINAL_OBJECT_INFO(TestAttrs, BaseAttrsNode);
};
// in cc file
TVM_FFI_STATIC_INIT_BLOCK({
// can group multiple such registration
TestAttrs::RegisterReflection();
});
// still needed for now for the shash/equal mechanism
TVM_REGISTER_NODE_TYPE(TestAttrs); |
This PR provides functions that adapts old VisitAttrs reflection utilities to use new reflection mechanism when available. These adapter would allow us to gradually transition the object def from old VisitAttrs based mechanism to new mechanism. - For all objects - Replace VisitAttrs with static void RegisterReflection() that registers the fields - Call T::ReflectionDef() in TVM_STATIC_INIT_BLOCK in cc file - For subclass of AttrsNode<T>: subclass AttrsNodeReflAdapter<T> instead - Do the same steps as above and replace TVM_ATTRS - Provide explicit declaration of _type_key and TVM_FFI_DEFINE_FINAL_OBJECT_INFO We will send followup PRs to do the gradual transition. Once all transition is completed, we will remove AttrsVisitor and only go through the new mechanism.
MasterJH5574
approved these changes
Jun 25, 2025
ShiboXing
pushed a commit
to ShiboXing/tvm
that referenced
this pull request
Aug 10, 2025
…che#18091) This PR provides functions that adapts old VisitAttrs reflection utilities to use new reflection mechanism when available. These adapter would allow us to gradually transition the object def from old VisitAttrs based mechanism to new mechanism. - For all objects - Replace VisitAttrs with static void RegisterReflection() that registers the fields - Call T::ReflectionDef() in TVM_STATIC_INIT_BLOCK in cc file - For subclass of AttrsNode<T>: subclass AttrsNodeReflAdapter<T> instead - Do the same steps as above and replace TVM_ATTRS - Provide explicit declaration of _type_key and TVM_FFI_DEFINE_FINAL_OBJECT_INFO We will send followup PRs to do the gradual transition. Once all transition is completed, we will remove AttrsVisitor and only go through the new mechanism.
tqchen
added a commit
to tqchen/tvm
that referenced
this pull request
Sep 13, 2025
…che#18091) This PR provides functions that adapts old VisitAttrs reflection utilities to use new reflection mechanism when available. These adapter would allow us to gradually transition the object def from old VisitAttrs based mechanism to new mechanism. - For all objects - Replace VisitAttrs with static void RegisterReflection() that registers the fields - Call T::ReflectionDef() in TVM_STATIC_INIT_BLOCK in cc file - For subclass of AttrsNode<T>: subclass AttrsNodeReflAdapter<T> instead - Do the same steps as above and replace TVM_ATTRS - Provide explicit declaration of _type_key and TVM_FFI_DEFINE_FINAL_OBJECT_INFO We will send followup PRs to do the gradual transition. Once all transition is completed, we will remove AttrsVisitor and only go through the new mechanism.
tqchen
added a commit
to tqchen/tvm
that referenced
this pull request
Sep 13, 2025
…che#18091) This PR provides functions that adapts old VisitAttrs reflection utilities to use new reflection mechanism when available. These adapter would allow us to gradually transition the object def from old VisitAttrs based mechanism to new mechanism. - For all objects - Replace VisitAttrs with static void RegisterReflection() that registers the fields - Call T::ReflectionDef() in TVM_STATIC_INIT_BLOCK in cc file - For subclass of AttrsNode<T>: subclass AttrsNodeReflAdapter<T> instead - Do the same steps as above and replace TVM_ATTRS - Provide explicit declaration of _type_key and TVM_FFI_DEFINE_FINAL_OBJECT_INFO We will send followup PRs to do the gradual transition. Once all transition is completed, we will remove AttrsVisitor and only go through the new mechanism.
tqchen
added a commit
to tqchen/tvm
that referenced
this pull request
Sep 13, 2025
…che#18091) This PR provides functions that adapts old VisitAttrs reflection utilities to use new reflection mechanism when available. These adapter would allow us to gradually transition the object def from old VisitAttrs based mechanism to new mechanism. - For all objects - Replace VisitAttrs with static void RegisterReflection() that registers the fields - Call T::ReflectionDef() in TVM_STATIC_INIT_BLOCK in cc file - For subclass of AttrsNode<T>: subclass AttrsNodeReflAdapter<T> instead - Do the same steps as above and replace TVM_ATTRS - Provide explicit declaration of _type_key and TVM_FFI_DEFINE_FINAL_OBJECT_INFO We will send followup PRs to do the gradual transition. Once all transition is completed, we will remove AttrsVisitor and only go through the new mechanism.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR provides functions that adapts old VisitAttrs reflection utilities to use new reflection mechanism when available.
These adapter would allow us to gradually transition the object def from old VisitAttrs based mechanism to new mechanism.
We will send followup PRs to do the gradual transition. Once all transition is completed, we will remove AttrsVisitor and only go through the new mechanism.