55was written to work with FSL version 5.0.4. 
66""" 
77import  os 
8+ from  shutil  import  which 
89import  numpy  as  np 
910import  nibabel  as  nb 
1011import  warnings 
1112
1213from  ...utils .filemanip  import  split_filename , fname_presuffix 
14+ from  ...utils .gpu_count  import  gpu_count 
1315
1416from  ..base  import  traits , TraitedSpec , InputMultiPath , File , isdefined 
1517from  .base  import  FSLCommand , FSLCommandInputSpec , Info 
@@ -793,9 +795,12 @@ class EddyInputSpec(FSLCommandInputSpec):
793795        requires = ["estimate_move_by_susceptibility" ],
794796        min_ver = "6.0.1" ,
795797    )
796- 
797798    num_threads  =  traits .Int (
798-         1 , usedefault = True , nohash = True , desc = "Number of openmp threads to use" 
799+         argstr = "--nthr=%d" ,
800+         default_value = 1 ,
801+         usedefault = True ,
802+         nohash = True ,
803+         desc = "Number of openmp threads to use" 
799804    )
800805    is_shelled  =  traits .Bool (
801806        False ,
@@ -937,7 +942,7 @@ class Eddy(FSLCommand):
937942
938943    """ 
939944
940-     _cmd  =  "eddy_openmp" 
945+     _cmd  =  "eddy_openmp"   if   which ( "eddy_openmp" )  else   "eddy_cpu" 
941946    input_spec  =  EddyInputSpec 
942947    output_spec  =  EddyOutputSpec 
943948
@@ -963,17 +968,22 @@ def _num_threads_update(self):
963968            self .inputs .environ ["OMP_NUM_THREADS" ] =  str (self .inputs .num_threads )
964969
965970    def  _use_cuda (self ):
966-         self ._cmd  =  "eddy_cuda"  if  self .inputs .use_cuda  else  "eddy_openmp" 
971+         if  self .inputs .use_cuda  and  gpu_count ()> 0 :
972+             # eddy_cuda usually link to eddy_cudaX.X but some versions miss the symlink 
973+             # anyway in newer fsl versions eddy automatically use cuda on cuda-capable systems 
974+             self ._cmd  =  "eddy_cuda"  if  which ("eddy_cuda" ) else  "eddy" 
975+         else :
976+             # older fsl versions has cuda_openmp, newer versions has eddy_cpu 
977+             _cmd  =  "eddy_openmp"  if  which ("eddy_openmp" ) else  "eddy_cpu" 
967978
968979    def  _run_interface (self , runtime ):
969-         # If 'eddy_openmp'  is missing, use 'eddy' 
980+         # If selected command  is missing, use generic  'eddy' 
970981        FSLDIR  =  os .getenv ("FSLDIR" , "" )
971982        cmd  =  self ._cmd 
972983        if  all (
973984            (
974985                FSLDIR  !=  "" ,
975-                 cmd  ==  "eddy_openmp" ,
976-                 not  os .path .exists (os .path .join (FSLDIR , "bin" , cmd )),
986+                 not  os .path .exists (os .path .join (FSLDIR , "bin" , self ._cmd )),
977987            )
978988        ):
979989            self ._cmd  =  "eddy" 
0 commit comments