manoharan-lab / holopy

Hologram processing and light scattering in python
GNU General Public License v3.0
131 stars 50 forks source link

No parameter to run ADDA on GPU? #368

Closed golovart closed 3 years ago

golovart commented 4 years ago

Parameters in the init suggest only 1 or multiple cpus, and later in code, while forming 'cmd' only 2 options are considered:

if self.n_cpu == 1:
    cmd = ['adda']
if self.n_cpu > 1:
    cmd = ['mpiexec', '-n', str(self.n_cpu), 'adda_mpi']

If I understand correctly, the GPU run should start with adda_ocl

barkls commented 3 years ago

You're right - it looks like HoloPy was never set up to run adda on GPUs. It's great that you identified the change that needs to be made. If you can get this working, we would welcome a pull request to add this functionality!

golovart commented 3 years ago

I tried adding a parameter like self.use_gpu and self.gpu_id and therefore

if self.use_gpu == True:
    cmd = ['adda_ocl']
    if not (self.gpu_id is None): cmd.extend(['-gpu '+str(self.gpu_id)])
elif self.n_cpu == 1:
    cmd = ['adda']
elif self.n_cpu > 1:
    cmd = ['mpiexec', '-n', str(self.n_cpu), 'adda_mpi']

It indeed runs adda_ocl and nvidia-smi shows GPU usage. However, timing tests (with large refraction index) show no difference between GPU runs and 1 CPU runs, while for pure ADDA it is significant

barkls commented 3 years ago

Thanks for doing some digging on this. What ADDA calculations did you test through HoloPy? There's a fair bit of overhead to actually dispatch the scattering calculations to ADDA so the gpu (or parallel processing) advantage might only come through for longer calculations with a larger scatterer and/or many pixels to calculate.

barkls commented 3 years ago

Fixed by #370