Skip to content
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

Document refine_coordinate #597

Closed
yuanming-hu opened this issue Mar 14, 2020 · 6 comments
Closed

Document refine_coordinate #597

yuanming-hu opened this issue Mar 14, 2020 · 6 comments
Assignees
Labels
feature request Suggest an idea on this project stale stale issues and PRs

Comments

@yuanming-hu
Copy link
Member

Per the request in #593

@yuanming-hu yuanming-hu added the feature request Suggest an idea on this project label Mar 14, 2020
@yuanming-hu yuanming-hu self-assigned this Mar 14, 2020
@k-ye
Copy link
Member

k-ye commented Mar 15, 2020

Actually, I think I figured out what has confused me. I hope my example could help explain the process:

x = ti.var(ti.i32)
ti.root.dense(ti.i, 4).bitmasked().dense(ti.i, 8).place(x)

@ti.kernel
def foo():
  for i in x:
    x[i] = 42

foo()

Here's the relevant fields for each SNode of its index 0:

snode size num_bits mask acc_offset start
S0 1 1 0x1 0 5
S1 4 2 0x3 0 3
S2 8 3 0x7 0 0

For a concrete example where the input linear index l=17, if I'm following the flow correctly:

auto addition = tlctx->get_constant(0);
if (snode->extractors[i].num_bits) {
auto mask = ((1 << snode->extractors[i].num_bits) - 1);
addition = builder.CreateAnd(
builder.CreateAShr(l, snode->extractors[i].acc_offset), mask);
addition = builder.CreateShl(
addition, tlctx->get_constant(snode->extractors[i].start));
}
auto in = call(&builder, "PhysicalCoordinates_get_val", inp_coords,
tlctx->get_constant(i));
auto added = builder.CreateOr(in, addition);
call(&builder, "PhysicalCoordinates_set_val", outp_coords,
tlctx->get_constant(i), added);

Then during element_listgen(), this should be its intermediate results

snode l addition in out
S0 0 ((l >> 0) & 0x1) << 5 = 0 0 0 or 0 = 0
S1 2 ((l >> 0) & 0x3) << 3 = 16 2 2 or 16 = 16
S2 1 ((l >> 0) & 0x7) << 0 = 1 16 16 or 1 = 17

What I went wrong before was that, in each parent -> child listgen, I used the same l = 17. As a result, the final output I got was 41 instead of 17...

@yuanming-hu
Copy link
Member Author

yuanming-hu commented Mar 15, 2020

I think your understanding now is mostly correct, excapt for a few numbers in the table, updated below:

snode size num_bits mask acc_offset start
S0_root 1 0 0x0 0 5
S1_dense 4 2 0x3 0 3
S2_dense 8 3 0x7 0 0
snode l addition in out
S0 0 ((l >> 5) & 0x0) << 5 = 0 0 0 or 0 = 0
S1 2 ((l >> 3) & 0x3) << 3 = 16 0 0 or 16 = 16
S2 1 ((l >> 0) & 0x7) << 0 = 1 16 16 or 1 = 17

@k-ye
Copy link
Member

k-ye commented Mar 15, 2020

btw, i believe they should all be ((l >> 0)... :)

@yuanming-hu
Copy link
Member Author

btw, i believe they should all be ((l >> 0)... :)

Oh sorry. I didn't realize what l is in the second table (2nd column) so I assumed we are working on 17 throughout this process....

@k-ye
Copy link
Member

k-ye commented Mar 15, 2020

Oh sorry. I didn't realize what l is in the second table (2nd column) so I assumed we are working on 17 throughout this process....

My bad, I meant to use 17 as the 17-th leaf element of x.

The l in the table is actually the third argument of the refine coordinates function:

auto l = args[2];

@github-actions
Copy link

Warning: The issue has been out-of-update for 50 days, marking stale.

@github-actions github-actions bot added the stale stale issues and PRs label May 21, 2020
@k-ye k-ye closed this as completed Jun 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Suggest an idea on this project stale stale issues and PRs
Projects
None yet
Development

No branches or pull requests

2 participants