Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Utilize GPU in Dart / Flutter other than graphics

Aye Aye good people,

I was wandering if I can 'use' ('calls', 'threads'?)

the GPU with Dart and Flutter.

The documentation states

The GPU thread executes graphics code from the Flutter Engine. This thread takes the layer tree and displays it by talking to the GPU (graphic processing unit). You cannot directly access the GPU thread or its data, but if this thread is slow, it’s a result of something you’ve done in the Dart code. Skia, the graphics library, runs on this thread, which is sometimes called the rasterizer thread.[...] More information on profiling the GPU thread can be found at flutter.dev. (which doesn't add much)

But what if I don't want to use it for graphics?

Let's say for example that I want to use Monte carlo method, for some calculation,

could I make a call or send a thread to the GPU?

thank you for your attention

like image 411
Francesco Iapicca Avatar asked Dec 18 '22 17:12

Francesco Iapicca


1 Answers

"GPU thread" was a confusing name, so we renamed it to "raster thread". This thread is actually running on a CPU core, and its function is to rasterize graphics to be sent to the GPU. Many people assumed the thread is running on the GPU itself, but that is not the case. Thus, the rename.

(We renamed it pretty recently. Your original question used the correct terminology at the time.)

You cannot compile Dart code to be run on the GPU (like CUDA), unfortunately, the way you can do that with C++, for example.

An option is to write your Monte Carlo routine in something like C++, then use Dart's FFI to call that routine from Dart code. This will run synchronously and as fast as you can make the C++ code go.

like image 147
filiph Avatar answered Jan 01 '23 16:01

filiph