Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX]eddy command and multithreading #3721

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions nipype/interfaces/fsl/epi.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
was written to work with FSL version 5.0.4.
"""
import os
from shutil import which
import numpy as np
import nibabel as nb
import warnings

from ...utils.filemanip import split_filename, fname_presuffix
from ...utils.gpu_count import gpu_count

from ..base import traits, TraitedSpec, InputMultiPath, File, isdefined
from .base import FSLCommand, FSLCommandInputSpec, Info
Expand Down Expand Up @@ -793,9 +795,12 @@
requires=["estimate_move_by_susceptibility"],
min_ver="6.0.1",
)

num_threads = traits.Int(
1, usedefault=True, nohash=True, desc="Number of openmp threads to use"
argstr="--nthr=%d",
default_value=1,
usedefault=True,
nohash=True,
desc="Number of openmp threads to use"
)
is_shelled = traits.Bool(
False,
Expand Down Expand Up @@ -937,7 +942,7 @@

"""

_cmd = "eddy_openmp"
_cmd = "eddy_openmp" if which("eddy_openmp") else "eddy_cpu"
input_spec = EddyInputSpec
output_spec = EddyOutputSpec

Expand All @@ -955,6 +960,8 @@
self._use_cuda()

def _num_threads_update(self):
if self.inputs.use_cuda and gpu_count()>0:
self.inputs.num_threads = 1

Check warning on line 964 in nipype/interfaces/fsl/epi.py

View check run for this annotation

Codecov / codecov/patch

nipype/interfaces/fsl/epi.py#L964

Added line #L964 was not covered by tests
self._num_threads = self.inputs.num_threads
if not isdefined(self.inputs.num_threads):
if "OMP_NUM_THREADS" in self.inputs.environ:
Expand All @@ -963,17 +970,23 @@
self.inputs.environ["OMP_NUM_THREADS"] = str(self.inputs.num_threads)

def _use_cuda(self):
self._cmd = "eddy_cuda" if self.inputs.use_cuda else "eddy_openmp"
if self.inputs.use_cuda and gpu_count()>0:
self.inputs.num_threads = 1

Check warning on line 974 in nipype/interfaces/fsl/epi.py

View check run for this annotation

Codecov / codecov/patch

nipype/interfaces/fsl/epi.py#L973-L974

Added lines #L973 - L974 were not covered by tests
# eddy_cuda usually link to eddy_cudaX.X but some versions miss the symlink
# anyway in newer fsl versions eddy automatically use cuda on cuda-capable systems
self._cmd = "eddy_cuda" if which("eddy_cuda") else "eddy"

Check warning on line 977 in nipype/interfaces/fsl/epi.py

View check run for this annotation

Codecov / codecov/patch

nipype/interfaces/fsl/epi.py#L977

Added line #L977 was not covered by tests
else:
# older fsl versions has cuda_openmp, newer versions has eddy_cpu
self._cmd = "eddy_openmp" if which("eddy_openmp") else "eddy_cpu"

Check warning on line 980 in nipype/interfaces/fsl/epi.py

View check run for this annotation

Codecov / codecov/patch

nipype/interfaces/fsl/epi.py#L980

Added line #L980 was not covered by tests

def _run_interface(self, runtime):
# If 'eddy_openmp' is missing, use 'eddy'
# If selected command is missing, use generic 'eddy'
FSLDIR = os.getenv("FSLDIR", "")
cmd = self._cmd
if all(
(
FSLDIR != "",
cmd == "eddy_openmp",
not os.path.exists(os.path.join(FSLDIR, "bin", cmd)),
not os.path.exists(os.path.join(FSLDIR, "bin", self._cmd)),
)
):
self._cmd = "eddy"
Expand Down
Loading