Describe the bug
simple tutorial code only works on x64 and cuda backend,
fails to work on dx12/dx11/opengl backend.
To Reproduce
change arch to different backend to try.
import taichi as ti
ti.init(debug=True, arch=ti.dx12)
max_num_particles = 256
dt = 1e-3
num_particles = ti.field(ti.i32, shape=())
spring_stiffness = ti.field(ti.f32, shape=())
paused = ti.field(ti.i32, shape=())
damping = ti.field(ti.f32, shape=())
particle_mass = 1
bottom_y = 0.05
x = ti.Vector.field(2, dtype=ti.f32, shape=max_num_particles)
v = ti.Vector.field(2, dtype=ti.f32, shape=max_num_particles)
A = ti.Matrix.field(2, 2, dtype=ti.f32, shape=(max_num_particles, max_num_particles))
b = ti.Vector.field(2, dtype=ti.f32, shape=max_num_particles)
# rest_length[i, j] = 0 means i and j are not connected
rest_length = ti.field(ti.f32, shape=(max_num_particles, max_num_particles))
connection_radius = 0.15
gravity = [0, -9.8]
@ti.kernel
def substep():
# Compute force and new velocity
n = num_particles[None]
for i in range(n):
v[i] *= ti.exp(-dt * damping[None]) # damping
total_force = ti.Vector(gravity) * particle_mass
for j in range(n):
if rest_length[i, j] != 0:
x_ij = x[i] - x[j]
total_force += -spring_stiffness[None] * (x_ij.norm() - rest_length[i, j]) * x_ij.normalized()
v[i] += dt * total_force / particle_mass
# Collide with ground
for i in range(n):
if x[i].y < bottom_y:
x[i].y = bottom_y
v[i].y = 0
# Compute new position
for i in range(num_particles[None]):
x[i] += v[i] * dt
@ti.kernel
def new_particle(pos_x: ti.f32, pos_y: ti.f32): # Taichi doesn't support using Matrices as kernel arguments yet
new_particle_id = num_particles[None]
x[new_particle_id] = [pos_x, pos_y]
v[new_particle_id] = [0, 0]
num_particles[None] += 1
# Connect with existing particles
for i in range(new_particle_id):
dist = (x[new_particle_id] - x[i]).norm()
if dist < connection_radius:
rest_length[i, new_particle_id] = 0.1
rest_length[new_particle_id, i] = 0.1
gui = ti.GUI('Mass Spring System', res=(512, 512), background_color=0xdddddd)
spring_stiffness[None] = 10000
damping[None] = 20
new_particle(0.3, 0.3)
new_particle(0.3, 0.4)
new_particle(0.4, 0.4)
while True:
for e in gui.get_events(ti.GUI.PRESS):
if e.key in [ti.GUI.ESCAPE, ti.GUI.EXIT]:
exit()
elif e.key == gui.SPACE:
paused[None] = not paused[None]
elif e.key == ti.GUI.LMB:
new_particle(e.pos[0], e.pos[1])
elif e.key == 'c':
num_particles[None] = 0
rest_length.fill(0)
elif e.key == 's':
if gui.is_pressed('Shift'):
spring_stiffness[None] /= 1.1
else:
spring_stiffness[None] *= 1.1
elif e.key == 'd':
if gui.is_pressed('Shift'):
damping[None] /= 1.1
else:
damping[None] *= 1.1
if not paused[None]:
for step in range(10):
substep()
X = x.to_numpy()
gui.circles(X[:num_particles[None]], color=0xffaa77, radius=5)
gui.line(begin=(0.0, bottom_y), end=(1.0, bottom_y), color=0x0, radius=1)
for i in range(num_particles[None]):
for j in range(i + 1, num_particles[None]):
if rest_length[i, j] != 0:
gui.line(begin=X[i], end=X[j], radius=2, color=0x445566)
gui.text(content=f'C: clear all; Space: pause', pos=(0, 0.95), color=0x0)
gui.text(content=f'S: Spring stiffness {spring_stiffness[None]:.1f}', pos=(0, 0.9), color=0x0)
gui.text(content=f'D: damping {damping[None]:.2f}', pos=(0, 0.85), color=0x0)
gui.show()
Log/Screenshots
Please post the full log of the program (instead of just a few lines around the error message, unless the log is > 1000 lines). This will help us diagnose what's happening. For example:
p .\mass_spring_explicit.py
[Taichi] version 1.6.0, llvm 15.0.1, commit f1c6fbbd, win, python 3.10.11
[Taichi] Starting on arch=dx12
[W 08/27/23 17:31:04.526 39080] [program.cpp:taichi::lang::Program::Program@162] Out-of-bound access checking is not supported on arch=dx12
[E 08/27/23 17:31:04.873 39080] [llvm_program.cpp:taichi::lang::LlvmProgramImpl::make_kernel_launcher@147] Not supported.
***********************************
* Taichi Compiler Stack Traceback *
***********************************
0x7ffdc05ce959: taichi::Time::get_cycles in taichi_python.cp310-win_amd64.pyd
0x7ffdc0f70249: taichi::Logger::error in taichi_python.cp310-win_amd64.pyd
0x7ffdc06eb2e5: taichi::lang::directx12::make_aot_module in taichi_python.cp310-win_amd64.pyd
0x7ffdc04bde4f: taichi::lang::Program::enqueue_compute_op_lambda in taichi_python.cp310-win_amd64.pyd
0x7ffdc04b1827: taichi::lang::Program::compile in taichi_python.cp310-win_amd64.pyd
0x7ffdc0492c73: taichi::lang::Kernel::compile in taichi_python.cp310-win_amd64.pyd
0x7ffdc04c1172: taichi::lang::Program::enqueue_compute_op_lambda in taichi_python.cp310-win_amd64.pyd
0x7ffdc043bdd2: taichi::lang::aot::Module::get_snode_tree in taichi_python.cp310-win_amd64.pyd
0x7ffdc0173a88: taichi::ui::vulkan::Canvas::operator= in taichi_python.cp310-win_amd64.pyd
0x7ffdc0173bb4: taichi::ui::vulkan::Canvas::operator= in taichi_python.cp310-win_amd64.pyd
0x7ffdbffa7fa1: taichi::Logger::operator= in taichi_python.cp310-win_amd64.pyd
0x7ffe35ee9eea: PyObject_IsTrue in python310.dll
0x7ffe35f2ffbb: PyObject_MakeTpCall in python310.dll
0x7ffe3606bf8f: Py_gitversion in python310.dll
0x7ffe35f46033: PyEval_EvalFrameDefault in python310.dll
0x7ffe35f449d7: PyFunction_Vectorcall in python310.dll
0x7ffe35f2bfb0: PyVectorcall_Call in python310.dll
0x7ffe35f2be87: PyObject_Call in python310.dll
0x7ffe35f4b5e7: PyEval_EvalFrameDefault in python310.dll
0x7ffe35f449d7: PyFunction_Vectorcall in python310.dll
0x7ffe35f2bfb0: PyVectorcall_Call in python310.dll
0x7ffe35f2be87: PyObject_Call in python310.dll
0x7ffe35f4b5e7: PyEval_EvalFrameDefault in python310.dll
0x7ffe35f449d7: PyFunction_Vectorcall in python310.dll
0x7ffe35ef2e90: PyObject_DelItem in python310.dll
0x7ffe35f487a2: PyEval_EvalFrameDefault in python310.dll
0x7ffe35efa1cd: PyType_CalculateMetaclass in python310.dll
0x7ffe35f5ad06: PyEval_EvalCode in python310.dll
0x7ffe35f5a9ca: PyArena_New in python310.dll
0x7ffe35f5a94a: PyArena_New in python310.dll
0x7ffe35fdf394: PyRun_SimpleFileObject in python310.dll
0x7ffe35fdf249: PyRun_SimpleFileObject in python310.dll
0x7ffe35fddd20: PyRun_AnyFileObject in python310.dll
0x7ffe35fdd9a3: Py_MakePendingCalls in python310.dll
0x7ffe35fdd85f: Py_MakePendingCalls in python310.dll
0x7ffe35f53a30: Py_RunMain in python310.dll
0x7ffe35f538c1: Py_RunMain in python310.dll
0x7ffe35f532d9: Py_Main in python310.dll
0x7ff7d97b1230: Unknown Function in python.exe
0x7ffec39e26ad: BaseThreadInitThunk in KERNEL32.DLL
0x7ffec506aa68: RtlUserThreadStart in ntdll.dll
Internal error occurred. Check out this page for possible solutions:
https://docs.taichi-lang.org/docs/install
Traceback (most recent call last):
File "mass_spring_explicit.py", line 71, in <module>
spring_stiffness[None] = 10000
File "C:\Users\xx\AppData\Local\Programs\Python\Python310\lib\site-packages\taichi\lang\util.py", line 321, in wrapped
return func(*args, **kwargs)
File "C:\Users\xx\AppData\Local\Programs\Python\Python310\lib\site-packages\taichi\lang\field.py", line 362, in __setitem__
self.host_accessors[0].setter(value, *self._pad_key(key))
File "C:\Users\xx\AppData\Local\Programs\Python\Python310\lib\site-packages\taichi\lang\field.py", line 409, in setter
write_func(key, value)
RuntimeError: [llvm_program.cpp:taichi::lang::LlvmProgramImpl::make_kernel_launcher@147] Not supported.
...
Describe the bug simple tutorial code only works on x64 and cuda backend, fails to work on dx12/dx11/opengl backend.
To Reproduce change arch to different backend to try.
Log/Screenshots Please post the full log of the program (instead of just a few lines around the error message, unless the log is > 1000 lines). This will help us diagnose what's happening. For example:
Additional comments