-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RFC] Taichi on Javascript #3781
Comments
Regarding SPIR-V to WGSL, the biggest pain point is atomics. To understand the problem, please have a look at this discussion. TLDR:
I'd appreciate any help/suggestions on this, as this feels like a huge blocker. To make matters worse, it looks that the WebGPU committee has no plans to make atomics more flexible in the near future, as they have moved the discussion to |
WebGPU is not a stable API by any means and the atomic issue also originates from their persistence to use WGSL instead of a common standard. This does not sound like an addressable issue in any way, we might want to straight up limit atomic capabilities on WGSL all together. This is my personal opinion, but I feel like if the platform did not allow flexibility, we should not try to "fix" it by hacking our ways around it |
Would it be reasonable to make this work two-parted. The first part is the front-end, and we can use bindings such as https://github.com/maierfelix/nvk to allow at least node.js front-end to work with Vulkan. The second part would be the backend where we figure out WebGPU and WGSL |
I more or less agree. I hate the idea of hacking around it either. But this would essentially mean we would support no atomics at all, and that's not great. Virtually all of the physical simulation programs in taichi requires atomics. Not having atomics is a huge limitation.
That makes sense. Although I wouldn't invest too much time into a node-only version if it turns out to be a lot of work. My reasoning being that a node-only version doesn't add that much value to our existing Python version, while a version that runs in browsers can open up a lot of possibilities. |
https://amesingflank.github.io/taichi.js/ |
Hi, thanks for reporting. Could you please tell me your browser version? And could you paste the code that you put in the code editor? Are there any error messages in the Logs? |
|
@eatcosmos Thanks! I will try to fix this. |
@eatcosmos Also, could you try upgrading to chrome v98? |
v98 is ok, load image quickly |
What about webgl Oasis Engines, is three any relation between Taichi.js and Oasis or Three.js in technology? |
There isn't much in common at all. Taichi.js is a compiler codegen and JIT runtime system that compiles your JS code into GPU kernels. These examples are graphics and rendering engines, they are very different things. So, no relation in them at all. |
Test taichi.js three.js oasis.js, taichi.js cannot show demo in mobile chrome, |
@eatcosmos Taichi.js runs on WebGPU, which is not supported by mobile chrome yet. Of course I hope that in the future, mobile chrome/safari will support WebGPU and thus Taichi.js. But at this point there's no telling how long that would take. |
but mobile has no gpu, three.js could work, three.js use webgl , taichi.js not use webgl? |
@eatcosmos Three.js uses WebGL, which is a legacy API, and is well-supported by mobile browsers. Taichi.js uses a new API called WebGPU, which is aimed to replace WebGL, but has a long way to go from actually doing so. |
FYI you can track Chrome's support status of WebGPU in https://chromestatus.com/feature/6213121689518080. It doesn't mention mobile Chrome yet, but this is almost a guaranteed thing. |
what is the process of producing taichi.js? |
We use emscripten to compile taichi's C++ code base into javascript, paired with a WebGPU runtime written in Typescript. |
thank you for your explanation,maybe webgl is also a good choice for now to cover most devices |
The problem with WebGL is that it doesn't support compute shaders. It is a legacy API and we expect that in due time, WebGPU will receive fairly common support. |
is there any attempt going on to implement taichi js in react native too |
I'm writing this RFC to share my thoughts and plans to build a version of Taichi completely embedded in Javascript, with the hope of getting production-level applications to use Taichi, and thereby increasing the impact of Taichi as a programming language.
Currently, Taichi uses Python as the host language. Thanks to Python's simplicity, Taichi enables programmers with little GPU experiences to have fun and experiment with GPU computing. Javascript shares the simplicity of Python (to some extent), and additionally, it has the advantage of being used extensively in production-level, user-facing applications. For this reason, if we offer Taichi as a (deployable) Javascript package, it would provide professional web developers with a brand new way of building and serving compute-heavy or graphics-heavy web programs. This would certainly boost the popularity of Taichi.
To be more specifically, I'm planning to build a Javascript library that enables this:
Here,
taichi
would be a normal Javascript module, one that could be installed simply by runningnpm install taichi
. Most importantly, it must be a pure Javascript module, meaning that it must have no binary code dependencies attached to it. This is of course vital if we want web developers to be able to use it in their own products. We will of course implement interop routines with normal Javascript arrays, HTML canvases, and maybe even provide a GGUI.Use cases and Impacts
From the top of my head I can think of a lot of use cool cases for a Javascript version of Taichi
Graphics applications on the web.
No doubt there are lots and lots of graphics demands on web pages, and these are done most often via WebGL, which is flexible but cumbersome. As a language directly embedded in JS, this could be very appealing for beginner-level front-end engineers who don’t want to learn WebGL.
Compute heavy applications on the web
These are considerably rarer, but part of the reason for that is exactly because it’s difficult to develop high performance programs on the web -- and taichi just might change that.
Other fancy apps:
This is something I thought about a few years ago. We could build a site where people can submit compute tasks written in taichi, and other people could simple open up the website and contribute their (GPU) computing resources.
Technological Considerations and Challenges
Obviously, this will be a huge project with many challenges. Here’re the things that have crossed my mind:
In Javascript, you can obtain the source code of a function passed in as an argument. So this shouldn’t be a problem. In fact, there is a library called gpu.js[https://gpu.rocks/#/] which already uses this to translate Javascript to GPU code. That package is pretty cool, but Taichi is much, much more powerful of course.
Also, Javascript might support decorators in the future. If this ECMAScript proposal goes through, we might be able to have
No binary code dependencies?
Emscripten. I have already successfully compiled the entire Taichi project using emscripten. I haven't started trying to use the generated code, and there will probably be some troubles to overcome, but overall this is very feasible.
GPU Computing
This is a big "X" of this project. WebGL doesn’t have good support for compute. WebGPU does, but browsers don’t have good support for WebGPU. If we only use CPU, e.g. WASM, then the performance probably won’t be enough of a selling point.
Although, I remain hopeful that not too long in the future, WebGPU will become widely adopted. I mean, WebGL can’t just live forever right?
Roadmap
I believe the best way to do this is to use the Typescript Compiler API.
After the Javascript frontend, we will use a emscriptened Taichi to translate CHI IR to SPIR-V
There are a few publicly available tools that does this, namely naga and tint. But in fact none of them works well enough and there're some painful problems. I won't go into the details here, instead, I will post a comment below to discuss this.
Proof of Concept
I have hacked up a WebGPU Taichi runtime and used Taichi AOT and Tint to generate some WGSL kernels. If you have Chrome 94+, you can see it here
https://amesingflank.github.io/taichi.js/
---EDIT: 2022.Feb.13:
I built a taichi.js zoo with an interactive code editor and a few examples ported from Python:
https://amesingflank.github.io/taichi.js/
---EDIT: 2022.April.21
Moved website to https://taichi-js.com
The text was updated successfully, but these errors were encountered: