Forum

Author Topic: How to turn on all gpus?  (Read 4145 times)

photoscan_user

  • Jr. Member
  • **
  • Posts: 98
    • View Profile
How to turn on all gpus?
« on: October 18, 2017, 01:18:00 PM »
How to turn on all gpus?

I can see parameter gpu_mask, but how to turn on all gpus, if I don't know number of gpus in the system beforehand?

For example, this enables 4 GPUs:
~/photoscan/photoscan.sh --gpu_mask 15 -platform offscreen -r my_script.py

photoscan_user

  • Jr. Member
  • **
  • Posts: 98
    • View Profile
Re: How to turn on all gpus?
« Reply #1 on: October 18, 2017, 02:01:54 PM »
Looks like by default  all GPUs are used, if gpu_mask is not specified and in GUI settings all GPUs checked.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14847
    • View Profile
Re: How to turn on all gpus?
« Reply #2 on: October 18, 2017, 02:50:29 PM »
Hello photoscan_user,

You can add the following code to your script instead of command-line argument:

Code: [Select]
PhotoScan.app.gpu_mask = 2**len(PhotoScan.app.enumGPUDevices()) - 1

if PhotoScan.app.gpu_mask:
PhotoScan.app.cpu_enable = False 
else:
PhotoScan.app.cpu_enable = True

PhotoScan.app.enumGPUDevices() returns the list of the available GPU devices.
« Last Edit: June 22, 2019, 01:45:13 PM by Alexey Pasumansky »
Best regards,
Alexey Pasumansky,
Agisoft LLC

OlegAlexander

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: How to turn on all gpus?
« Reply #3 on: June 22, 2019, 02:04:41 AM »
Hi Alexey,

Did you mean?

Code: [Select]
PhotoScan.app.gpu_mask = 2**len(PhotoScan.app.enumGPUDevices()) - 1

if PhotoScan.app.gpu_mask:
PhotoScan.app.cpu_enable = False 
else:
PhotoScan.app.cpu_enable = True

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14847
    • View Profile
Re: How to turn on all gpus?
« Reply #4 on: June 22, 2019, 01:44:58 PM »
Hello OlegAlexander,

Yes, seems so. I'll modify my reply.
Best regards,
Alexey Pasumansky,
Agisoft LLC

EE

  • Newbie
  • *
  • Posts: 26
    • View Profile
Re: How to turn on all gpus?
« Reply #5 on: January 18, 2022, 09:54:33 PM »
Is this snippet still relevant or are the defaults for both gou_mask and cpu_enable good by themselves for the most efficient setup?

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14847
    • View Profile
Re: How to turn on all gpus?
« Reply #6 on: January 18, 2022, 10:06:29 PM »
Hello EE,

Similar code (just substitute PhotoScan by Metashape) would work in the latest version. It enables all the available GPUs and disables the use of CPU, in case at least one GPU is enabled.

In most cases it is optimal configuration. You may only need to alter that, when working on the system with integrated graphics: you may want to enable CPU, if there's no discrete GPU available, or disable integrated graphics, if there's a powerful discrete GPU.
Best regards,
Alexey Pasumansky,
Agisoft LLC

EE

  • Newbie
  • *
  • Posts: 26
    • View Profile
Re: How to turn on all gpus?
« Reply #7 on: January 18, 2022, 10:09:28 PM »
Thank you for your quick response. If I were to not use this code snippet, all GPUs would still be used as gpu_mask is the max value, correct?

So then this code would only be needed when we need to disable a specific GPU like you said for the special cases.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14847
    • View Profile
Re: How to turn on all gpus?
« Reply #8 on: January 18, 2022, 10:12:59 PM »
Hello EE,

If this is the first time Metashape is started on the current configuration and GPU Preferences tab has never been opened, then Metashape will try to use all the available GPUs by default.

But in your case do you use Metashape in GUI mode, as network processing nodes or for headless Python scripts execution?
Best regards,
Alexey Pasumansky,
Agisoft LLC

EE

  • Newbie
  • *
  • Posts: 26
    • View Profile
Re: How to turn on all gpus?
« Reply #9 on: January 18, 2022, 10:20:47 PM »
I am indeed building a script for headless Python scripts execution so I was wondering if anything special needed to be set up.