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

Init_pos(): RuntimeError: [lang_util.cpp:to_primitive_type@395] Assertion failure: primitive #1940

Open
JerryYan97 opened this issue Oct 11, 2020 · 3 comments
Assignees
Labels
potential bug Something that looks like a bug but not yet confirmed

Comments

@JerryYan97
Copy link

Describe the bug
Previously, I can run these code, but it doesn't work and get stuck at the init_pos() function. It looks like it is caused by this statement:

ti.Vector([i/N*0.4, j/W*0.2])
# sample code here
import taichi as ti
import numpy as np
import pymesh

# Used to create an obj mesh for pymesh, which is exactly same as the one used in PDJ demo3.
# This mesh will be read into PN.

N = 20  # internal of one edge
W = 10
NF = 2 * N * W  # 2 * N ** 2   # number of faces
NV = (N+1)*(W+1)  # (N + 1) ** 2 # number of vertices
dx = 1 / N  # 0.05

pos = ti.Vector.field(2, float, NV)
f2v = ti.Vector.field(3, int, NF)  # ids of three vertices of each face
# dirichlet_num = N + 1
# dirichlet = ti.Vector.field(2, float, W + 1)
# [i for i in range(11)]


@ti.kernel
def init_pos():
    # i: col; j: row;
    for i, j in ti.ndrange(N + 1, W + 1):
        k = i*(W+1)+j
        pos[k] = ti.Vector([i/N*0.4, j/W*0.2]) + ti.Vector([0.2, 0.4]) # 0.2, 0.4 - 0.6,0.6  0.02*0.02


@ti.kernel
def init_mesh():  # generate two triangles
    for i, j in ti.ndrange(N, W):
        k = (i * W + j) * 2  # tirangle index   w 2 n 3
        a = i * (W + 1) + j  # 0 0 = 0
        b = a + 1  # 1
        c = a + W + 2  # 12
        d = a + W + 1  # 11
        f2v[k + 0] = [a, d, c]
        f2v[k + 1] = [a, c, b]


init_pos()
init_mesh()

np_pos = pos.to_numpy()
np_f2v = f2v.to_numpy()

print(np.shape(np_pos))
print(np.shape(np_f2v))

f = open("demo3_mesh.obj", "w")

# Write all pos
for [x, y] in np_pos:
    f.write("v " + str(x) + " " + str(y) + " 0\n")

# Write all faces
for [i, j, k] in np_f2v:
    f.write("f " + str(i + 1) + "/" + str(i + 1) + " " + str(j + 1) + "/" + str(j + 1) + " " + str(k + 1) + "/" + str(k + 1) + "\n")

f.close()
/usr/bin/python3.8 /home/jiaruiyan/self_study/Taichi_PJD_3D/mesh_create.py
[Taichi] mode=release
[Taichi] preparing sandbox at /tmp/taichi-1envx3t5
[Taichi] version 0.6.39, llvm 10.0.0, commit 12e02bec, linux, python 3.8.5
[Taichi] materializing...
[E 10/11/20 10:27:05.815] [lang_util.cpp:to_primitive_type@395] Assertion failure: primitive


***********************************
* Taichi Compiler Stack Traceback *
***********************************
/home/jiaruiyan/.local/lib/python3.8/site-packages/taichi/core/../lib/taichi_core.so: taichi::Logger::error(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool)
/home/jiaruiyan/.local/lib/python3.8/site-packages/taichi/core/../lib/taichi_core.so(+0x702f26) [0x7f66b8e03f26]
/home/jiaruiyan/.local/lib/python3.8/site-packages/taichi/core/../lib/taichi_core.so: taichi::lang::promoted_type(taichi::lang::DataType, taichi::lang::DataType)
/home/jiaruiyan/.local/lib/python3.8/site-packages/taichi/core/../lib/taichi_core.so: taichi::lang::TypeCheck::visit(taichi::lang::BinaryOpStmt*)
/home/jiaruiyan/.local/lib/python3.8/site-packages/taichi/core/../lib/taichi_core.so: taichi::lang::TypeCheck::visit(taichi::lang::Block*)
/home/jiaruiyan/.local/lib/python3.8/site-packages/taichi/core/../lib/taichi_core.so: taichi::lang::TypeCheck::visit(taichi::lang::Block*)
/home/jiaruiyan/.local/lib/python3.8/site-packages/taichi/core/../lib/taichi_core.so: taichi::lang::irpass::type_check(taichi::lang::IRNode*)
/home/jiaruiyan/.local/lib/python3.8/site-packages/taichi/core/../lib/taichi_core.so: taichi::lang::irpass::compile_to_offloads(taichi::lang::IRNode*, taichi::lang::CompileConfig const&, bool, bool, bool, bool)
/home/jiaruiyan/.local/lib/python3.8/site-packages/taichi/core/../lib/taichi_core.so: taichi::lang::irpass::compile_to_executable(taichi::lang::IRNode*, taichi::lang::CompileConfig const&, bool, bool, bool, bool, bool, bool, bool)
/home/jiaruiyan/.local/lib/python3.8/site-packages/taichi/core/../lib/taichi_core.so: taichi::lang::Kernel::lower(bool)
/home/jiaruiyan/.local/lib/python3.8/site-packages/taichi/core/../lib/taichi_core.so: taichi::lang::Program::compile(taichi::lang::Kernel&)
/home/jiaruiyan/.local/lib/python3.8/site-packages/taichi/core/../lib/taichi_core.so: taichi::lang::Kernel::compile()
/home/jiaruiyan/.local/lib/python3.8/site-packages/taichi/core/../lib/taichi_core.so: taichi::lang::Kernel::operator()(taichi::lang::Kernel::LaunchContextBuilder&)
/home/jiaruiyan/.local/lib/python3.8/site-packages/taichi/core/../lib/taichi_core.so(+0x4c6164) [0x7f66b8bc7164]
/home/jiaruiyan/.local/lib/python3.8/site-packages/taichi/core/../lib/taichi_core.so(+0x3d0d30) [0x7f66b8ad1d30]
/usr/bin/python3.8: PyCFunction_Call
/usr/bin/python3.8: _PyObject_MakeTpCall
/usr/bin/python3.8: ) [0x50a978]
/usr/bin/python3.8: PyObject_Call
/usr/bin/python3.8: ) [0x59d47c]
/usr/bin/python3.8: _PyObject_MakeTpCall
/usr/bin/python3.8: _PyEval_EvalFrameDefault
/usr/bin/python3.8: _PyEval_EvalCodeWithName
/usr/bin/python3.8: _PyFunction_Vectorcall
/usr/bin/python3.8: PyObject_Call
/usr/bin/python3.8: _PyEval_EvalFrameDefault
/usr/bin/python3.8: _PyEval_EvalCodeWithName
/usr/bin/python3.8: _PyFunction_Vectorcall
/usr/bin/python3.8: ) [0x59d17f]
/usr/bin/python3.8: PyObject_Call
/usr/bin/python3.8: _PyEval_EvalFrameDefault
/usr/bin/python3.8: _PyEval_EvalCodeWithName
/usr/bin/python3.8: _PyFunction_Vectorcall
/usr/bin/python3.8: _PyEval_EvalFrameDefault
/usr/bin/python3.8: _PyEval_EvalCodeWithName
/usr/bin/python3.8: PyEval_EvalCode
/usr/bin/python3.8: ) [0x67bc91]
/usr/bin/python3.8: ) [0x67bd0f]
/usr/bin/python3.8: PyRun_FileExFlags
/usr/bin/python3.8: PyRun_SimpleFileExFlags
/usr/bin/python3.8: Py_RunMain
/usr/bin/python3.8: Py_BytesMain
/lib/x86_64-linux-gnu/libc.so.6: __libc_start_main
/usr/bin/python3.8: _start

Internal Error occurred, check this page for possible solutions:
https://taichi.readthedocs.io/en/stable/install.html#troubleshooting
Traceback (most recent call last):
  File "/home/jiaruiyan/self_study/Taichi_PJD_3D/mesh_create.py", line 40, in <module>
    init_pos()
  File "/home/jiaruiyan/.local/lib/python3.8/site-packages/taichi/lang/kernel.py", line 574, in wrapped
    return primal(*args, **kwargs)
  File "/home/jiaruiyan/.local/lib/python3.8/site-packages/taichi/lang/kernel.py", line 502, in __call__
    return self.compiled_functions[key](*args)
  File "/home/jiaruiyan/.local/lib/python3.8/site-packages/taichi/lang/kernel.py", line 460, in func__
    t_kernel(launch_ctx)
RuntimeError: [lang_util.cpp:to_primitive_type@395] Assertion failure: primitive

Process finished with exit code 1

@JerryYan97 JerryYan97 added the potential bug Something that looks like a bug but not yet confirmed label Oct 11, 2020
@JerryYan97
Copy link
Author

It works when I change the init_pos() to this:

@ti.kernel
def init_pos():
    # i: col; j: row;
    for i, j in ti.ndrange(N + 1, W + 1):
        k = i*(W+1)+j
        pos[k] = ti.Vector([i * (1.0 / N * 0.4), j * (1.0 / W * 0.2)]) + ti.Vector([0.2, 0.4]) # 0.2, 0.4 - 0.6,0.6  0.02*0.02

It looks like variables in ti.kernel cannot divide other staffs.

@archibate
Copy link
Collaborator

archibate commented Oct 11, 2020

Thank for reporting! This is actually a known bug introduced by #1906.
Before that, we may add ti.init() to the first line of program to fix the problem.

Also btw, does ti.Vector([float(i)/float(N)*0.4, float(j)/float(W)*0.2]) depress the error? It seems the type promotion for division is broken.

@JerryYan97
Copy link
Author

Yes, it can depress the error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
potential bug Something that looks like a bug but not yet confirmed
Projects
None yet
Development

No branches or pull requests

3 participants