taichi-dev / taichi

Productive, portable, and performant GPU programming in Python.
https://taichi-lang.org
Apache License 2.0
25.51k stars 2.28k forks source link

Bug caused by PR #3989 #4064

Closed BillXu2000 closed 2 years ago

BillXu2000 commented 2 years ago

Describe the bug It seems that #3989 cause the problem. See code and results below.

To Reproduce

import taichi as ti, sys, os, argparse, subprocess, re, numpy as np, time

ti.init(arch=ti.cuda)

vec3f = ti.types.vector(3, ti.f32)

mesh = ti.TetMesh()
mesh.verts.place({'x' : vec3f}, reorder=False)

mesh.verts.link(mesh.verts)
bunny = mesh.build(ti.Mesh.load_meta('./bunny_1k_bug.json'))

@ti.kernel
def vv_substep():
    ti.mesh_local(bunny.verts.x)
    for v0 in bunny.verts:
        total_f = ti.Vector([0.0, 0.0, 0.0])
        for i in range(v0.verts.size):
            total_f -= v0.x

vv_substep()

Log/Screenshots Before #3989:

{18:02}~/Desktop/meshtaichiext/evaluation:exp ✗ ➭ p spring_bug.py         
[Taichi] version 0.8.10, llvm 10.0.0, commit ae09c214, linux, python 3.8.10
[Taichi] Starting on arch=cuda

After #3989:

{18:00}~/Desktop/meshtaichiext/evaluation:exp ✗ ➭ p spring_bug.py                                                                                                                                                  
[Taichi] version 0.8.10, llvm 10.0.0, commit f855e480, linux, python 3.8.10                                                                                                                                        
[Taichi] Starting on arch=cuda                                                                                                                                                                                     
[E 01/19/22 18:00:44.576 2432407] [ir.h:as@226] Assertion failure: is<T>()                                                                                                                                         

***********************************                                                                                                                                                                                
* Taichi Compiler Stack Traceback *                                                                                                                                                                                
***********************************                                                                                                                                                                                
/home/bx2k/git/taichi/python/taichi/_lib/core/taichi_core.so: taichi::Logger::error(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool)                                  
/home/bx2k/git/taichi/python/taichi/_lib/core/taichi_core.so: taichi::lang::MeshBLSAnalyzer::record_access(taichi::lang::Stmt*, taichi::lang::AccessFlag)                                                          
/home/bx2k/git/taichi/python/taichi/_lib/core/taichi_core.so: taichi::lang::MeshBLSAnalyzer::visit(taichi::lang::GlobalLoadStmt*)                                                                                  
/home/bx2k/git/taichi/python/taichi/_lib/core/taichi_core.so: taichi::lang::BasicStmtVisitor::visit(taichi::lang::Block*)                                                                                          
/home/bx2k/git/taichi/python/taichi/_lib/core/taichi_core.so: taichi::lang::RangeForStmt::accept(taichi::lang::IRVisitor*)                                                                                         
/home/bx2k/git/taichi/python/taichi/_lib/core/taichi_core.so: taichi::lang::MeshBLSAnalyzer::run()                                                                                                                 
/home/bx2k/git/taichi/python/taichi/_lib/core/taichi_core.so: taichi::lang::irpass::analysis::initialize_mesh_local_attribute(taichi::lang::OffloadedStmt*, bool, taichi::lang::CompileConfig const&)              
/home/bx2k/git/taichi/python/taichi/_lib/core/taichi_core.so: taichi::lang::MakeMeshBlockLocal::MakeMeshBlockLocal(taichi::lang::OffloadedStmt*, taichi::lang::CompileConfig const&)                               
/home/bx2k/git/taichi/python/taichi/_lib/core/taichi_core.so: taichi::lang::MakeMeshBlockLocal::run(taichi::lang::OffloadedStmt*, taichi::lang::CompileConfig const&, std::__cxx11::basic_string<char, std::char_tr
aits<char>, std::allocator<char> > const&)                                                                                                                                                                         
/home/bx2k/git/taichi/python/taichi/_lib/core/taichi_core.so: taichi::lang::irpass::make_mesh_block_local(taichi::lang::IRNode*, taichi::lang::CompileConfig const&, taichi::lang::MakeMeshBlockLocal::Args const&)
/home/bx2k/git/taichi/python/taichi/_lib/core/taichi_core.so: taichi::lang::irpass::offload_to_executable(taichi::lang::IRNode*, taichi::lang::CompileConfig const&, taichi::lang::Kernel*, bool, bool, bool, bool,
 bool)                                                                                                                                                                                                             
/home/bx2k/git/taichi/python/taichi/_lib/core/taichi_core.so: taichi::lang::irpass::compile_to_executable(taichi::lang::IRNode*, taichi::lang::CompileConfig const&, taichi::lang::Kernel*, bool, bool, bool, bool,
 bool, bool, bool, bool)                                                                                                                                                                                           
/home/bx2k/git/taichi/python/taichi/_lib/core/taichi_core.so: taichi::lang::Kernel::lower(bool)                                                                                                                    
/home/bx2k/git/taichi/python/taichi/_lib/core/taichi_core.so: taichi::lang::LlvmProgramImpl::compile(taichi::lang::Kernel*, taichi::lang::OffloadedStmt*)
/home/bx2k/git/taichi/python/taichi/_lib/core/taichi_core.so: taichi::lang::Program::compile(taichi::lang::Kernel&, taichi::lang::OffloadedStmt*)
/home/bx2k/git/taichi/python/taichi/_lib/core/taichi_core.so: taichi::lang::Kernel::compile()
/home/bx2k/git/taichi/python/taichi/_lib/core/taichi_core.so: taichi::lang::Kernel::operator()(taichi::lang::Kernel::LaunchContextBuilder&)
/home/bx2k/git/taichi/python/taichi/_lib/core/taichi_core.so(+0x9921f7) [0x7f3094d2c1f7]
/home/bx2k/git/taichi/python/taichi/_lib/core/taichi_core.so(+0x958461) [0x7f3094cf2461]
python3(PyCFunction_Call+0x59) [0x5f5e79]
python3(_PyObject_MakeTpCall+0x296) [0x5f6a46]
python3() [0x50b447]
python3(PyObject_Call+0x62) [0x5f55f2]
python3() [0x59d2f4]
python3(_PyObject_MakeTpCall+0x296) [0x5f6a46]
python3(_PyEval_EvalFrameDefault+0x5932) [0x570612]
python3(_PyEval_EvalCodeWithName+0x26a) [0x5696da]
python3(_PyFunction_Vectorcall+0x393) [0x5f6403]
python3(PyObject_Call+0x62) [0x5f55f2]
python3(_PyEval_EvalFrameDefault+0x1f1b) [0x56cbfb]
python3(_PyEval_EvalCodeWithName+0x26a) [0x5696da]
python3(_PyFunction_Vectorcall+0x393) [0x5f6403]
python3() [0x59d07f]
python3(PyObject_Call+0x25e) [0x5f57ee]
python3(_PyEval_EvalFrameDefault+0x1f1b) [0x56cbfb]
python3(_PyEval_EvalCodeWithName+0x26a) [0x5696da]
python3(_PyFunction_Vectorcall+0x393) [0x5f6403]
python3(_PyEval_EvalFrameDefault+0x71e) [0x56b3fe]
python3(_PyEval_EvalCodeWithName+0x26a) [0x5696da]
python3(PyEval_EvalCode+0x27) [0x68db17]
python3() [0x67eeb1]
python3() [0x67ef2f]
python3() [0x67efd1]
python3(PyRun_SimpleFileExFlags+0x197) [0x67f377]
python3(Py_RunMain+0x212) [0x6b7902]
python3(Py_BytesMain+0x2d) [0x6b7c8d]
/lib/x86_64-linux-gnu/libc.so.6: __libc_start_main
python3(_start+0x2e) [0x5fb12e]

Internal error occurred. Check out this page for possible solutions:
https://docs.taichi.graphics/lang/articles/misc/install
Traceback (most recent call last):
  File "spring_bug.py", line 21, in <module>
    vv_substep()
  File "/home/bx2k/git/taichi/python/taichi/lang/kernel_impl.py", line 734, in wrapped
    return primal(*args, **kwargs)
  File "/home/bx2k/git/taichi/python/taichi/lang/kernel_impl.py", line 665, in __call__
    return self.compiled_functions[key](*args)
  File "/home/bx2k/git/taichi/python/taichi/lang/kernel_impl.py", line 617, in func__
    t_kernel(launch_ctx)
RuntimeError: [ir.h:as@226] Assertion failure: is<T>()
kracon7 commented 2 years ago

I had the same issue while running the example billiards.py I'm using Ubuntu 18.04 and python3.6

(taichi) jc@jc-Precision-7530:~/jiacheng/examples$ python billiards.py 
[Taichi] version 0.8.10, llvm 10.0.0, commit 016feb38, linux, python 3.6.9
[Taichi] Starting on arch=x64
[E 01/24/22 22:45:51.257 7889] [ir.h:as@226] Assertion failure: is<T>()

***********************************
* Taichi Compiler Stack Traceback *
***********************************
/home/jc/Envs/taichi/lib/python3.6/site-packages/taichi/_lib/core/taichi_core.so: taichi::Logger::error(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool)
/home/jc/Envs/taichi/lib/python3.6/site-packages/taichi/_lib/core/taichi_core.so: taichi::lang::AdStackAllocaStmt* taichi::lang::IRNode::as<taichi::lang::AdStackAllocaStmt>()
/home/jc/Envs/taichi/lib/python3.6/site-packages/taichi/_lib/core/taichi_core.so: taichi::lang::ControlFlowGraph::determine_ad_stack_size(int)
/home/jc/Envs/taichi/lib/python3.6/site-packages/taichi/_lib/core/taichi_core.so: taichi::lang::irpass::determine_ad_stack_size(taichi::lang::IRNode*, taichi::lang::CompileConfig const&)
/home/jc/Envs/taichi/lib/python3.6/site-packages/taichi/_lib/core/taichi_core.so: taichi::lang::irpass::offload_to_executable(taichi::lang::IRNode*, taichi::lang::CompileConfig const&, taichi::lang::Kernel*, bool, bool, bool, bool, bool)
/home/jc/Envs/taichi/lib/python3.6/site-packages/taichi/_lib/core/taichi_core.so: taichi::lang::irpass::compile_to_executable(taichi::lang::IRNode*, taichi::lang::CompileConfig const&, taichi::lang::Kernel*, bool, bool, bool, bool, bool, bool, bool, bool)
/home/jc/Envs/taichi/lib/python3.6/site-packages/taichi/_lib/core/taichi_core.so: taichi::lang::Kernel::lower(bool)
/home/jc/Envs/taichi/lib/python3.6/site-packages/taichi/_lib/core/taichi_core.so: taichi::lang::LlvmProgramImpl::compile(taichi::lang::Kernel*, taichi::lang::OffloadedStmt*)
/home/jc/Envs/taichi/lib/python3.6/site-packages/taichi/_lib/core/taichi_core.so: taichi::lang::Program::compile(taichi::lang::Kernel&, taichi::lang::OffloadedStmt*)
/home/jc/Envs/taichi/lib/python3.6/site-packages/taichi/_lib/core/taichi_core.so: taichi::lang::Kernel::compile()
/home/jc/Envs/taichi/lib/python3.6/site-packages/taichi/_lib/core/taichi_core.so: taichi::lang::Kernel::operator()(taichi::lang::Kernel::LaunchContextBuilder&)
/home/jc/Envs/taichi/lib/python3.6/site-packages/taichi/_lib/core/taichi_core.so(+0x3fa00a) [0x7f700e0c000a]
/home/jc/Envs/taichi/lib/python3.6/site-packages/taichi/_lib/core/taichi_core.so(+0x3b394e) [0x7f700e07994e]
python(_PyCFunction_FastCallDict+0x35c) [0x5675fc]
python() [0x5953c1]
python() [0x54b0a5]
python(_PyObject_FastCallKeywords+0x19c) [0x5aa2ac]
python() [0x50a7f3]
python(_PyEval_EvalFrameDefault+0x444) [0x50c274]
python() [0x507f94]
python() [0x5894db]
python(PyObject_Call+0x3e) [0x5a00ce]
python(_PyEval_EvalFrameDefault+0x17e7) [0x50d617]
python() [0x507f94]
python(_PyFunction_FastCallDict+0x2e2) [0x509272]
python() [0x595351]
python() [0x54af3f]
python(PyObject_Call+0x3e) [0x5a00ce]
python(_PyEval_EvalFrameDefault+0x17e7) [0x50d617]
python() [0x509989]
python() [0x50a6bd]
python(_PyEval_EvalFrameDefault+0x444) [0x50c274]
python(_PyFunction_FastCallDict+0xf5) [0x509085]
python() [0x595351]
python(_PyObject_FastCallDict+0x17c) [0x5a4cac]
python(PyObject_CallFunctionObjArgs+0xd8) [0x5a5378]
python(_PyEval_EvalFrameDefault+0x1af0) [0x50d920]
python() [0x509989]
python() [0x50a6bd]
python(_PyEval_EvalFrameDefault+0x444) [0x50c274]
python() [0x507f94]
python(PyEval_EvalCode+0x23) [0x50b0d3]
python() [0x634dc2]
python(PyRun_FileExFlags+0x97) [0x634e77]
python(PyRun_SimpleFileExFlags+0x17f) [0x63862f]
python(Py_Main+0x591) [0x6391d1]
python(main+0xe0) [0x4b0d30]
/lib/x86_64-linux-gnu/libc.so.6: __libc_start_main
python(_start+0x2a) [0x5b2a5a]

Internal error occurred. Check out this page for possible solutions:
https://docs.taichi.graphics/lang/articles/misc/install
Traceback (most recent call last):
  File "billiards.py", line 212, in <module>
    optimize()
  File "billiards.py", line 169, in optimize
    forward(visualize=True, output=output)
  File "/home/jc/Envs/taichi/lib/python3.6/site-packages/taichi/lang/tape.py", line 18, in __exit__
    self.grad()
  File "/home/jc/Envs/taichi/lib/python3.6/site-packages/taichi/lang/tape.py", line 27, in grad
    func.grad(*args)
  File "/home/jc/Envs/taichi/lib/python3.6/site-packages/taichi/lang/kernel_impl.py", line 665, in __call__
    return self.compiled_functions[key](*args)
  File "/home/jc/Envs/taichi/lib/python3.6/site-packages/taichi/lang/kernel_impl.py", line 617, in func__
    t_kernel(launch_ctx)
RuntimeError: [ir.h:as@226] Assertion failure: is<T>()
BillXu2000 commented 2 years ago

I had the same issue while running the example billiards.py I'm using Ubuntu 18.04 and python3.6

I think it is a different problem. The bug I reported is directly cause by #3989 , which is closely related to mesh-for features in Taichi.

BillXu2000 commented 2 years ago

It seems that as<MeshRelationAccessStmt>() in mesh_bls_analyzer.cpp will cause assertion failure when idx is not a MeshRelationAccessStmt. @g1n0st

BillXu2000 commented 2 years ago

fixed by #4529.