Skip to content

Commit 8f74c5d

Browse files
gpu_count refactor
1 parent 684b9b0 commit 8f74c5d

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

nipype/pipeline/plugins/multiproc.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from ...utils.profiler import get_system_total_memory_gb
2222
from ..engine import MapNode
2323
from .base import DistributedPluginBase
24+
from .tools import gpu_count
2425

2526
try:
2627
from textwrap import indent
@@ -132,7 +133,7 @@ def __init__(self, plugin_args=None):
132133
self.raise_insufficient = self.plugin_args.get("raise_insufficient", True)
133134

134135
# GPU found on system
135-
self.n_gpus_visible = MultiProcPlugin.gpu_count()
136+
self.n_gpus_visible = gpu_count()
136137
# proc per GPU set by user
137138
self.n_gpu_procs = self.plugin_args.get('n_gpu_procs', self.n_gpus_visible)
138139

@@ -423,12 +424,3 @@ def _sort_jobs(self, jobids, scheduler="tsort"):
423424
)
424425
return jobids
425426

426-
@staticmethod
427-
def gpu_count():
428-
n_gpus = 1
429-
try:
430-
import GPUtil
431-
432-
return len(GPUtil.getGPUs())
433-
except ImportError:
434-
return n_gpus

nipype/pipeline/plugins/tools.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,3 +178,12 @@ def create_pyscript(node, updatehash=False, store_exception=True):
178178
with open(pyscript, "w") as fp:
179179
fp.writelines(cmdstr)
180180
return pyscript
181+
182+
def gpu_count():
183+
n_gpus = 1
184+
try:
185+
import GPUtil
186+
except ImportError:
187+
return 1
188+
else:
189+
return len(GPUtil.getGPUs())

0 commit comments

Comments
 (0)