taichi icon indicating copy to clipboard operation
taichi copied to clipboard

Crash when running fractal.py example with vulkan

Open RPINerd opened this issue 8 months ago • 7 comments

Describe the bug

Running with vulkan crashes

To Reproduce

This is literally just the fractal.py example

import taichi as ti

ti.init(arch=ti.gpu)

n = 320
pixels = ti.field(dtype=float, 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: float):
    for i, j in pixels:  # Parallelized over all pixels
        c = ti.Vector([-0.8, ti.cos(t) * 0.2])
        z = ti.Vector([i / n - 1, 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("Julia Set", res=(n * 2, n))

for i in range(1000000):
    paint(i * 0.03)
    gui.set_image(pixels)
    gui.show()

Log/Screenshots

[Taichi] Starting on arch=vulkan
python: /home/dev/taichi/external/VulkanMemoryAllocator/include/vk_mem_alloc.h:16039: VkResult vmaCreateAllocator(const VmaAllocatorCreateInfo * _Nonnull, VmaAllocator * _Nonnull): Assertion `pCreateInfo->vulkanApiVersion == 0 || (((uint32_t)(pCreateInfo->vulkanApiVersion) >> 22U) == 1 && (((uint32_t)(pCreateInfo->vulkanApiVersion) >> 12U) & 0x3FFU) <= 3)' failed.
Aborted (core dumped)
...

Additional comments

Running the prime calculation example works fine, so taichi is installed and functioning in non-gui application

RPINerd avatar Apr 27 '25 22:04 RPINerd

It looks like the original assert is something like:

    VMA_ASSERT(pCreateInfo->vulkanApiVersion == 0 ||
        (VK_VERSION_MAJOR(pCreateInfo->vulkanApiVersion) == 1 && VK_VERSION_MINOR(pCreateInfo->vulkanApiVersion) <= 4));

This looks like your Vulkan is failing the version check. Looks like major version should be 1, and minor version <= 4. What Vulkan version do you have? Looks like you can use vulkaninfo to check the version, e.g. https://vulkan.lunarg.com/doc/view/latest/windows/vulkaninfo.html

(Note/disclaimer: I'm just a curious bystander)

Hmm, looks like all available versions of Vulkan are 1.0, 1.1, 1.2, 1.3 🤔 https://docs.vulkan.org/guide/latest/versions.html#:~:text=Vulkan%20works%20on%20a%20major,a%20Vulkan%20instance%20is%20supported.

hughperkins avatar Apr 28 '25 10:04 hughperkins

Well, the assert should pass with 1.4, since minorVersion <= 4 🤔 Maybe you can dump the values of VK_VERSION_MAJOR(pCreateInfo->vulkanApiVersion) and VK_VERSION_MINOR(pCreateInfo->vulkanApiVersion) to find out what is happening? i.e. add, befroe the assert:

std::cout << "vulkan major " << (VK_VERSION_MAJOR(pCreateInfo->vulkanApiVersion) ) << " minor " << (VK_VERSION_MINOR(pCreateInfo->vulkanApiVersion) ) << std::endl;

... and report the results here

hughperkins avatar Apr 28 '25 11:04 hughperkins

I am having the same issue. My system is on Vulkan 1.4, so this version check fails. currently attempting to comment out this assert or otherwise use the dev install

grindstm avatar Apr 28 '25 11:04 grindstm

@grindstm I wonder if you have slightly older version of the code? The assert in https://github.com/taichi-dev/taichi/issues/8677 has <= 3.

hughperkins avatar Apr 28 '25 11:04 hughperkins

Looks like this issue is dupe of https://github.com/taichi-dev/taichi/issues/8630

hughperkins avatar Apr 28 '25 11:04 hughperkins

I'm on Ubuntu 24.04, with NVidia driver 570.133 and Vulkan 1.4.303 on a Quadro T500 (a laptop NVidia GPU). I'm getting a similar assertion failure.

Is there any fix or work around yet?

wme7 avatar May 22 '25 13:05 wme7

I'm on Ubuntu 24.04, with NVidia driver 570.133 and Vulkan 1.4.303 on a Quadro T500 (a laptop NVidia GPU). I'm getting a similar assertion failure.

Is there any fix or work around yet?

Got busy with other things after submitting, but coming back to this today it looks like its an official support thing.. Taichi does not support vulkan 1.4 so the only option would be to attempt to downgrade. I highly discourage this though!

My workaround was just to use openGL/openCL instead, worked fine after that!

RPINerd avatar May 24 '25 15:05 RPINerd