erwincoumans / tiny-differentiable-simulator

Tiny Differentiable Simulator is a header-only C++ and CUDA physics library for reinforcement learning and robotics with zero dependencies.
Apache License 2.0
1.23k stars 130 forks source link

running in web (js, wasm, webgl) #188

Open danbri opened 2 years ago

danbri commented 2 years ago

Is there any prospect of this ever being ported to run on the web platform? ie state represented on the GPU, code compiled to WASM.

erwincoumans commented 2 years ago

If the web has a C++17 compiler it is likely possible. Do you have any suggestions what to do with a web version? At the moment we use the library for training, which can run in a Colab, which is on the web but using Google servers as backend (so the code is not executed in local browser runtime).

I like those web examples, using the older emscripten: http://guillaumeblanc.github.io/ozz-animation/ By the way: that multicore CPU (AMD Ryzen 12 or higher cores) is competitive with CUDA.

danbri commented 2 years ago

Thanks, Erwin! I have been looking at JS continuous time neural net (ctrnn) controllers with a view to plugging them into some cartoon world environment (I was initially thinking box2d) and doing the evolutionary computing / alife thing. So the differentiation isn't directly of interest; rather just potentially speeding up simulations by keeping params and world all on GPU.

Whether there is value in doing all this in the web environment - I think time will tell. If the number of params is small maybe moving computation server-side isn't worth the hassle. But equally one could argue that GPU is overkill for "agents" that are closer to Braitenberg Machines than to gpt-3 in scale. You once reminded me that it takes 0 neurons to ride a bike in a straight line, and that seems a good ballpark figure to start adding nodes from.

More generally, there is interest around Tensorflow-JS for accessing vectors/matrices without pulling all the data off of the GPU. Either for visualizations or for eg (if a suitable GPU backed physics environment could be found) a toy world simulation to do more vectorized computation.

https://github.com/tensorflow/tfjs/issues/1607#issuecomment-987888157

After learning about this aspect of tfjs I figured it was worth at least poking around to see what gpu-backed physics options might be possible from JS. Hence this question!

danbri commented 2 years ago

Apparently c++17 is viable, per https://github.com/emscripten-core/emscripten/issues/5513