eitcom / pyEIT

Python based toolkit for Electrical Impedance Tomography
Other
169 stars 96 forks source link

GPU accelerated support #66

Open ChabaneAmaury opened 1 year ago

ChabaneAmaury commented 1 year ago

@liubenyuan Since issue #22, I was wondering how to implement GPU support in the module. Could it be a thing to have a second module, completely separated? Like tensorflow and tensorflow-gpu? It may allow us to have gpu acceleration and have gpu specific optimizations in the program. This would need 2 separated pipelines, but it could be of a great help to a lot of people. And the limited memory allowed on a single GPU makes it a good start to take a look at huge models support, since we would need some kind of slicing/dataflow method we could as well implement in the classic module.

liubenyuan commented 1 year ago

Sure! How could we maintain that these two modules share a common base of functions and sync between them?

liubenyuan commented 1 year ago

Hi, I set up a EIT community organization, eitcom for short, to host all the EIT related things (software, mesh, and possibly OSS hardware). Would you like to be a member of this and create, push and manage a separate pyeit-gpu module?

ChabaneAmaury commented 1 year ago

Sure! How could we maintain that these two modules share a common base of functions and sync between them?

Not sure yet, since each update in the classic module needs to be manually rewritten and optimized for gpu, as stated in #22 .

I managed to make it work on gpu, but it is insanely slow (it constantly needs to send back and forth data between host memory and gpu memory, because I haven't optimized it yet).

I am actively looking into it, and when I will have something working (at least for fem and jac), then I will create and push on a new repo

ChabaneAmaury commented 1 year ago

Hi @liubenyuan , I have dpone some research on why it is so slow using the GPU, and I came across this article, which state that memory exchanges between the main host and the GPU is the main bottleneck of this settup. It is efficient only when it comes to calculate the same thing thousands of times. Unfortunately (or fortunately, depending on how you see it), it is not the case in this module, making the pyeit-gpu module inefficient. I can still continue to optimize the module, but the cpu method is still the best, and will be for a very long time. The only work-around I could suggest it to run the calculations on google-colab, but I am highly unexperienced with it so I won't assume anything right now.

liubenyuan commented 1 year ago

Thank you for your effort. And make pyeit-gpu as is and keep this repository. I will also try the gpu accelerated version of forward computing nevertheless. We could share the results :)

ChabaneAmaury commented 1 year ago

Thank you for your effort. And make pyeit-gpu as is and keep this repository. I will also try the gpu accelerated version of forward computing nevertheless. We could share the results :)

Alright, I will push what I have done so far, you will find the dev branch, it should be on it. You can try and launch the eit_static_jac.py example. If you have any issues regarding the installation, just come to me, I will do my best to guide you.

Update: Just as a reference, on my system, it takes around 5 min 33s to reconstruct the example with 16 electrodes (GPU: Nvidia RTX 2060 6GB), against 37s on the CPU (AMD Ryzen 3 3100 4-Core 3.9 GHz)

ChabaneAmaury commented 1 year ago

I have updated the README file on the dev branch so you have clearer informations on how to setup everything :)