taichi-dev / taichi

Productive, portable, and performant GPU programming in Python.
https://taichi-lang.org
Apache License 2.0
25.48k stars 2.28k forks source link

Android AOT Vulkan #5650

Open helloworldstone opened 2 years ago

helloworldstone commented 2 years ago

hi, everyone!

  1. taichi AOT can generate .spv files when you set arch = ti.vulkan. I manually write a vulkan demo like this(https://gist.github.com/sheredom/523f02bbad2ae397d7ed255f3f3b5a7f) and use taichi's spv file instead. On MTK 9000, it can run but the output value is zero. On Snapdragon 888,vkCreateComputePipelines failed with error code -13(VK_ERROR_UNKNOWN). So what is the difference between taichi's spv file and the standard spv file which is generating from compute shader with glslc tools ? Can I use taichi's spv file with my own vulkan demo?

  2. On the other hand, if I have generated some spv files from computer shaders before, can I use taichi vulkan c++ pipeline api like this (https://github.com/taichi-dev/taichi-aot-demo/blob/master/implicit_fem/include/fem_app.h) to run my spv files. If so, Is there anything else I should be aware of? Do I have to rewrite taichi python codes according to my computer shaders to generate taichi's spv files ?

Thanks a lot!

ailzhang commented 2 years ago

Hey @helloworldstone ! Thanks a lot for trying it out!

  1. taichi's generated spv file is no different from standard spv file, but it does has assumptions about how to set argument and retrieve returned values. They are validate spv with glslc tools and you can use them with your own vulkan runtime as long as those assumptions are met. Using taichi's generated spv files this way will make your vulkan demo depend on some taichi implementation details, so although it works, it's isn't the recommended way to deploy taichi shaders ;P.
  2. For implicit_fem demo, it's actually run continuously in our CI ;). So I highly recommend following the steps here https://github.com/taichi-dev/taichi/blob/master/.github/workflows/testing.yml#L652-L678 to generate spv files and build the android apk. (note the android-build.sh and android-demo.sh are the keys). To use this please make sure you have install the latest taichi from our nightly channel pip install -i https://pypi.taichi.graphics/simple/ taichi-nightly , and let us know you have any followup questions. We're more than happy to help!
PENGUINLIONG commented 2 years ago

Please note that by default the backend targets Vulkan 1.3 so the compiled SPIR-Vs might have used features and extensions that are not available on mobile implementations. You could try forcing a Vulkan 1.0 fallback implementation with ti.init(arch=ti.vulkan, vk_api_version="1.0") and it should work on most mobile platforms.

helloworldstone commented 2 years ago

@ailzhang @PENGUINLIONG Thanks very mush for your reply! I will try it later.