forked from taichi-dev/taichi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[llvm] Establish a correspondence between SNodes and DevicePtr (taich…
…i-dev#3120) * correspondence * fix mac build? * fix max build, take 2 * resolve convo * fix * Update taichi/ui/common/field_info.cpp Co-authored-by: Ye Kuang <[email protected]> * format * get_ptr(uint64_t offset = 0) * fix requirements? * fix requirements, second try * ok wth is up with this setuptools-rust thingy Co-authored-by: Ye Kuang <[email protected]>
- Loading branch information
1 parent
bac269e
commit 434607f
Showing
11 changed files
with
139 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include "taichi/ui/common/field_info.h" | ||
#include "taichi/program/program.h" | ||
|
||
namespace taichi { | ||
|
||
namespace ui { | ||
|
||
using namespace taichi::lang; | ||
|
||
DevicePtr get_device_ptr(taichi::lang::Program *program, SNode *snode) { | ||
/* | ||
GGUI makes the assumption that the input fields are created directly from | ||
ti.field() or ti.Vector field with `shape` specified. In other words, we | ||
assume that the fields are created via ti.root.dense.place() That is, the | ||
parent of the snode is a dense, and the parent of that node is a root. Note | ||
that, GGUI's python-side code creates a staging buffer to construct the VBO, | ||
which obeys this assumption. Thus, the only situation where this assumption | ||
may be violated is for set_image(), because the image isn't part of the VBO. | ||
Using this assumption, we will compute the offset of this field relative to | ||
the begin of the root buffer. | ||
*/ | ||
|
||
SNode *dense_parent = snode->parent; | ||
SNode *root = dense_parent->parent; | ||
|
||
int tree_id = root->get_snode_tree_id(); | ||
DevicePtr root_ptr = program->get_snode_tree_device_ptr(tree_id); | ||
|
||
size_t offset = 0; | ||
|
||
int child_id = root->child_id(dense_parent); | ||
|
||
TI_ASSERT_INFO(root == program->get_snode_root(tree_id), | ||
"SNode roots don't match"); | ||
|
||
for (int i = 0; i < child_id; ++i) { | ||
SNode *child = root->ch[i].get(); | ||
offset += child->cell_size_bytes * child->num_cells_per_container; | ||
} | ||
|
||
return root_ptr.get_ptr(offset); | ||
} | ||
|
||
} // namespace ui | ||
|
||
} // namespace taichi |
This file contains 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