Skip to content

Commit 562e05f

Browse files
authored
[lang] Add SNode.snode_tree_id (#8697)
Issue: # ### Brief Summary Add SNode.snode_tree_id copilot:summary ### Walkthrough Add SNode.snode_tree_id This will be useful for diagnosing crash bugs in Debug. copilot:walkthrough
1 parent 89f15f5 commit 562e05f

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

python/taichi/lang/snode.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,10 @@ def _id(self):
215215
"""
216216
return self.ptr.id
217217

218+
@property
219+
def _snode_tree_id(self):
220+
return self.ptr.get_snode_tree_id()
221+
218222
@property
219223
def shape(self):
220224
"""Gets the number of elements from root in each axis of `self`.

taichi/python/export_lang.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,7 @@ void export_lang(py::module &m) {
500500
.def_readwrite("parent", &SNode::parent)
501501
.def_readonly("type", &SNode::type)
502502
.def_readonly("id", &SNode::id)
503+
.def("get_snode_tree_id", &SNode::get_snode_tree_id)
503504
.def_readonly("offset", &SNode::index_offsets)
504505
.def("dense",
505506
(SNode & (SNode::*)(const std::vector<Axis> &,

tests/python/test_snode.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import taichi as ti
2+
from tests import test_utils
3+
4+
5+
@ti.kernel
6+
def some_kernel(_: ti.template()): ...
7+
8+
9+
@test_utils.test(cpu_max_num_threads=1)
10+
def test_get_snode_tree_id():
11+
s = ti.field(int, shape=())
12+
some_kernel(s)
13+
assert s.snode._snode_tree_id == 0
14+
15+
s = ti.field(int, shape=())
16+
some_kernel(s)
17+
assert s.snode._snode_tree_id == 1
18+
19+
s = ti.field(int, shape=())
20+
some_kernel(s)
21+
assert s.snode._snode_tree_id == 2

0 commit comments

Comments
 (0)