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

[async] Add allocator async state #1973

Merged
merged 3 commits into from
Oct 19, 2020
Merged

Conversation

k-ye
Copy link
Member

@k-ye k-ye commented Oct 18, 2020

taichi/taichi/lang_util.cpp

Lines 156 to 158 in ceea597

bool is_gc_able(SNodeType t) {
return (t == SNodeType::pointer || t == SNodeType::dynamic);
}

Before this PR, test_block_async() would actually fail. Here's the SFG. Note that all GC tasks are floating (as expected):

no-alloc

With this PR, SFG:

alloc

Highlighting the allocator state:

alloc-single

Related issue = #742

[Click here for the format server]


@codecov
Copy link

codecov bot commented Oct 18, 2020

Codecov Report

Merging #1973 into master will increase coverage by 0.96%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1973      +/-   ##
==========================================
+ Coverage   42.76%   43.72%   +0.96%     
==========================================
  Files          45       45              
  Lines        6431     6221     -210     
  Branches     1105     1105              
==========================================
- Hits         2750     2720      -30     
+ Misses       3507     3328     -179     
+ Partials      174      173       -1     
Impacted Files Coverage Δ
python/taichi/lang/ast_checker.py 70.58% <0.00%> (-1.64%) ⬇️
python/taichi/testing.py 75.00% <0.00%> (-0.72%) ⬇️
python/taichi/lang/linalg.py 89.33% <0.00%> (-0.67%) ⬇️
python/taichi/lang/__init__.py 40.45% <0.00%> (-0.33%) ⬇️
python/taichi/misc/util.py 20.54% <0.00%> (-0.21%) ⬇️
python/taichi/misc/task.py 0.00% <0.00%> (ø)
python/taichi/tools/patterns.py 0.00% <0.00%> (ø)
python/taichi/lang/kernel.py 71.39% <0.00%> (+0.13%) ⬆️
python/taichi/misc/gui.py 8.89% <0.00%> (+0.18%) ⬆️
python/taichi/main.py 22.95% <0.00%> (+0.35%) ⬆️
... and 8 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0298bca...03e7f3d. Read the comment docs.

Copy link
Contributor

@xumingkuan xumingkuan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM in general! I think we should also change some code in task fusion:

if (state.first.type != AsyncState::Type::value) {
// No need to check mask/list states as there must be value states.
continue;
}

IIUC allocator states should be treated like value states here: if A->B is an allocator edge on SNode s, only if both A and B are element-wise (or loop-unique on the same value in the future), can A and B be fused. For example, these two tasks cannot be fused:

@ti.kernel()
def foo():
  for i in x:
    ti.activate(y, i + 1)

@ti.kernel()
def bar():
  for i in x:
    ti.deactivate(y, i)

BTW, do these SNodeOpStmts change mask states?

@k-ye
Copy link
Member Author

k-ye commented Oct 19, 2020

LGTM in general! I think we should also change some code in task fusion:

if (state.first.type != AsyncState::Type::value) {
// No need to check mask/list states as there must be value states.
continue;
}

IIUC allocator states should be treated like value states here: if A->B is an allocator edge on SNode s, only if both A and B are element-wise (or loop-unique on the same value in the future), can A and B be fused. For example, these two tasks cannot be fused:

@ti.kernel()
def foo():
  for i in x:
    ti.activate(y, i + 1)

@ti.kernel()
def bar():
  for i in x:
    ti.deactivate(y, i)

Great catch! I've updated the code accordingly. However, note that I checked for mask state instead of allocator. IMHO, mask is directly related to sparsity, element_wise, etc. WDYT?

BTW, do these SNodeOpStmts change mask states?

Yes, thanks!

@k-ye k-ye requested a review from xumingkuan October 19, 2020 12:17
deactivate_y()
ti.sync()

# TODO: assert that activate_y and deactivate_y are not fused.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've confirmed this with the dumped dot graph. But task fusion is currently not recorded in the stats yet.

Copy link
Contributor

@xumingkuan xumingkuan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, thanks!

@k-ye k-ye merged commit 4a56852 into taichi-dev:master Oct 19, 2020
@k-ye k-ye deleted the sfg-allocator branch October 19, 2020 14:56
@yuanming-hu yuanming-hu mentioned this pull request Oct 21, 2020
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