Skip to content

Conversation

@tqchen
Copy link
Member

@tqchen tqchen commented Jun 27, 2025

This PR transitions VisitAttrs to new reflection mechansim in the following components: tir, ir_builder, meta_schedule

@tqchen tqchen force-pushed the object-refl branch 3 times, most recently from 4e10a69 to 750c1f5 Compare June 27, 2025 18:28
@MasterJH5574 MasterJH5574 merged commit f0e62eb into apache:main Jun 27, 2025
13 checks passed
@LeiWang1999
Copy link
Contributor

Curious to learn why we need to refactor this part, and how we can reuse part of the parent class's reflect methods.

class SwizzledLayoutNode: LayoutNode {
...
}


# old code with AttrVisitor 
void LayoutNode::VisitAttrs(AttrVisitor *v) {
  v->Visit("input_size", &input_size_);
  v->Visit("forward_index", &forward_index_);
}

void SwizzledLayoutNode::VisitAttrs(tvm::AttrVisitor *v) {
  LayoutNode::VisitAttrs(v);
}

# new code
void LayoutNode::RegisterReflection() {
  namespace refl = tvm::ffi::reflection;
  refl::ObjectDef<LayoutNode>()
      .def_ro("input_size", &LayoutNode::input_size)
      .def_ro("forward_index", &LayoutNode::forward_index);
}

void SwizzledLayoutNode::RegisterReflection() {
  namespace refl = tvm::ffi::reflection;
   ?
}

@tqchen
Copy link
Member Author

tqchen commented Jul 16, 2025

The new reflection mechanism would make the field access from python faster (about 10x) because we diretly access the address.

In the new code , you just need to do

void SwizzledLayoutNode::RegisterReflection() {
  namespace refl = tvm::ffi::reflection;
   // still need for parent relation to hold, but thats it
  refl::ObjectDef<SwizzledLayoutNode>();

}```

ShiboXing pushed a commit to ShiboXing/tvm that referenced this pull request Aug 10, 2025
…r_builder/meta_schedule (apache#18096)

This PR transitions VisitAttrs to new reflection mechansim in the
following components: tir, ir_builder, meta_schedule
tqchen added a commit to tqchen/tvm that referenced this pull request Sep 13, 2025
…r_builder/meta_schedule (apache#18096)

This PR transitions VisitAttrs to new reflection mechansim in the
following components: tir, ir_builder, meta_schedule
tqchen added a commit to tqchen/tvm that referenced this pull request Sep 13, 2025
…r_builder/meta_schedule (apache#18096)

This PR transitions VisitAttrs to new reflection mechansim in the
following components: tir, ir_builder, meta_schedule
tqchen added a commit to tqchen/tvm that referenced this pull request Sep 13, 2025
…r_builder/meta_schedule (apache#18096)

This PR transitions VisitAttrs to new reflection mechansim in the
following components: tir, ir_builder, meta_schedule
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants