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

[IR] Continue statement behavior is confusing in struct for #3272

Closed
BillXu2000 opened this issue Oct 26, 2021 · 2 comments · Fixed by #3282
Closed

[IR] Continue statement behavior is confusing in struct for #3272

BillXu2000 opened this issue Oct 26, 2021 · 2 comments · Fixed by #3282
Assignees
Labels
bug We've confirmed that this is an BUG ir IR related issues

Comments

@BillXu2000
Copy link
Collaborator

BillXu2000 commented Oct 26, 2021

Describe the bug
(update) Same issue as #3271.

Detected by @g1n0st .
Continue statement in struct for scope will skip the whole lowest activated dense block.
I am not sure whether it is a feature or a bug.

To Reproduce

import taichi as ti

ti.init(arch=ti.cuda, kernel_profiler = False)

n = 128
x = ti.field(ti.f32)
block = ti.root.pointer(ti.i, n // 16)
block.dense(ti.i, 16).place(x)

@ti.kernel 
def test():
    x[0] = 1
    x[1] = 2
    cnt = 0
    for i in x:
        if x[i] == 1: continue
        if x[i] == 2: cnt += 1
    print(cnt) # output 0

test()

Log/Screenshots

{11:11}~ ➭ p test.py  
[Taichi] version 0.8.3, llvm 10.0.0, commit 04cf87de, linux, python 3.8.5
[Taichi] Starting on arch=x64
0

Additional comments

bool ContinueStmt::as_return() const {

https://github.com/taichi-dev/taichi/blob/master/taichi/codegen/codegen_llvm.cpp#L802
A continue statement will emit a return statement in LLVM.

https://github.com/taichi-dev/taichi/blob/master/taichi/codegen/codegen_llvm.cpp#L1527
But every thread in struct for will loop over the whole lowest dense block.
I guess that a return statement in the kernel will force the thread to jump over the owest dense block loop, and resulting in this confusing skipping behavior.

@BillXu2000 BillXu2000 added the potential bug Something that looks like a bug but not yet confirmed label Oct 26, 2021
@k-ye
Copy link
Member

k-ye commented Oct 26, 2021

Closing #3271 because it's a duplicate

@k-ye
Copy link
Member

k-ye commented Oct 26, 2021

skip the whole lowest activated dense block

Nice catch! This is a bug

@k-ye k-ye added bug We've confirmed that this is an BUG ir IR related issues and removed potential bug Something that looks like a bug but not yet confirmed labels Oct 26, 2021
@BillXu2000 BillXu2000 self-assigned this Oct 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug We've confirmed that this is an BUG ir IR related issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants