Amd显卡使用ggui测试mesh显示中遇到的问题

我写了一个测试taichi的ggui的mesh显示功能的程序,可以正常运行,但是将程序在后台放置一分钟左右后,程序就会崩溃,使用的是RX580 8G显卡,vulkan后端。程序如下:

import taichi as ti
import numpy as np
import math

ti.init(arch=ti.vulkan)

indices = ti.field(int, 4*3)
vertices = ti.Vector.field(3, float, 4*3)
colours = ti.Vector.field(3, float, 4*3)

indices.from_numpy(np.array([0,1,2,3,4,5,6,7,8,9,10,11]))
vertices.from_numpy(np.array([
    [0,0,0],
    [0,1,0],
    [0,0,1],
    [1,0,0],
    [0,0,0],
    [0,1,0],
    [0,0,1],
    [1,0,0],
    [0,0,0],
    [0,1,0],
    [0,0,1],
    [1,0,0]
]))
colours.from_numpy(0.5*np.array([
    [1,0,0],
    [1,0,0],
    [1,0,0],
    [0,1,0],
    [0,1,0],
    [0,1,0],
    [0,0,1],
    [0,0,1],
    [0,0,1],
    [1,1,0],
    [1,1,0],
    [1,1,0]
]).astype(np.float32))



window = ti.ui.Window("test mesh plot", (800, 800), vsync=True)

canvas = window.get_canvas()
scene = ti.ui.Scene()
camera = ti.ui.make_camera()
theta=0
phi=0


while window.running:
    if window.is_pressed(ti.ui.LEFT, 'a'): theta -=0.03
    if window.is_pressed(ti.ui.RIGHT, 'd'): theta +=0.03
    if window.is_pressed(ti.ui.UP, 'w'): phi +=0.03
    if window.is_pressed(ti.ui.DOWN, 's'): phi -=0.03
    phi=min(math.pi/2,max(-math.pi/2,phi))
    camera.position(2*math.cos(theta)*math.cos(phi),2*math.sin(theta)*math.cos(phi),2*math.sin(phi)+0.5)
    camera.lookat(0,0,0.5)
    camera.up(0,0,1)
    scene.set_camera(camera)

    scene.point_light(pos=(0.5, 1, 2), color=(1, 1, 1))
    scene.ambient_light((1,1,1))
    scene.mesh(vertices,
            indices=indices,
            per_vertex_color=colours,
            two_sided=True)
    canvas.scene(scene)
    window.show()

崩溃效果如下:

1 个赞

Hi @frenchfries, 我如果直接用你的代码会报错:

RuntimeError: [kernel_utils.cpp:KernelContextAttributes@59] SPIRV kernel only supports less than 32-bit arguments, got i64

原因是 np.array如果没设置 dtype,就默认是 64 位,所以我修改了一下代码,显示设置了一下 dtype就可以正常运行了。

我使用的是N卡,所以一个原因可能就是A卡的问题。