I got an error when trying to run the sample code with gpu. This code can run normally on the CPU, but I still want to run successfully on GPU.
Here is the code.
# fractal.py
import taichi as ti
ti.init(arch=ti.gpu)
n = 320
pixels = ti.var(dt=ti.f32, shape=(n * 2, n))
@ti.func
def complex_sqr(z):
return ti.Vector([z[0] ** 2 - z[1] ** 2, z[1] * z[0] * 2])
@ti.kernel
def paint(t: ti.f32):
for i, j in pixels: # 对于所有像素,并行执行
c = ti.Vector([-0.8, ti.sin(t) * 0.2])
z = ti.Vector([float(i) / n - 1, float(j) / n - 0.5]) * 2
iterations = 0
while z.norm() < 20 and iterations < 50:
z = complex_sqr(z) + c
iterations += 1
pixels[i, j] = 1 - iterations * 0.02
gui = ti.GUI("Fractal", (n * 2, n))
for i in range(1000000):
paint(i * 0.03)
gui.set_image(pixels)
gui.show()
This is the command line output
[Taichi] mode=release [Taichi] version 0.6.8, supported archs: [cpu, cuda, opengl], commit 9f4fd27c, python 3.7.6 [W 06/09/20 19:10:10.887] [cuda_driver.h:call_with_warning@62] CUDA Error CUDA_ERROR_INVALID_DEVICE: invalid device ordinal while calling mem_advise (cuMemAdvise) [E 06/09/20 19:10:11.203] Received signal 7 (Bus error) *********************************** * Taichi Compiler Stack Traceback * *********************************** /home/argentea/anaconda3/lib/python3.7/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/argentea/anaconda3/lib/python3.7/site-packages/taichi/core/../lib/taichi_core.so: taichi::signal_handler(int) /lib/x86_64-linux-gnu/libc.so.6(+0x3ef20) [0x7fc954456f20] /home/argentea/anaconda3/lib/python3.7/site-packages/taichi/core/../lib/taichi_core.so: taichi::lang::MemoryPool::daemon() /home/argentea/anaconda3/bin/../lib/libstdc++.so.6(+0xc819d) [0x7fc9428da19d] /lib/x86_64-linux-gnu/libpthread.so.0(+0x76db) [0x7fc9548106db] /lib/x86_64-linux-gnu/libc.so.6: clone Internal Error occurred, check this page for possible solutions: https://taichi.readthedocs.io/en/stable/install.html#troubleshooting [E 06/09/20 19:10:11.204] Received signal 11 (Segmentation fault)