#! /bin/tcsh -ef

#
# cuda_setup
#
# Setup CUDA for apps using the CUDA package included with Freesurfer
#
# Original Author: Nick Schmansky
# CVS Revision Info:
#    $Author: nicks $
#    $Date: 2011/03/22 22:59:38 $
#    $Revision: 1.1.2.2 $
#
# Copyright © 2011 The General Hospital Corporation (Boston, MA) "MGH"
#
# Terms and conditions for use, reproduction, distribution and contribution
# are found in the 'FreeSurfer Software License Agreement' contained
# in the file 'LICENSE' found in the FreeSurfer distribution, and here:
#
# https://surfer.nmr.mgh.harvard.edu/fswiki/FreeSurferSoftwareLicense
#
# Reporting: freesurfer@nmr.mgh.harvard.edu
#
#

### --  use NMR Center CUDA package -- ####

if ( $?FREESURFER_HOME && ! $?MY_CUDA_HOME ) then
  if ( -e $FREESURFER_HOME/lib/cuda ) then
    set FS_CUDA_HOME=$FREESURFER_HOME/lib/cuda
  else if ( -e /usr/pubsw/packages/CUDA/current ) then
    set FS_CUDA_HOME=/usr/pubsw/packages/CUDA/current
  endif
else if ( $?MY_CUDA_HOME ) then
  set FS_CUDA_HOME=$MY_CUDA_HOME
else if ( -e /usr/pubsw/packages/CUDA/current ) then
  set FS_CUDA_HOME=/usr/pubsw/packages/CUDA/current
endif

if ( $?FS_CUDA_HOME ) then

  if ( -e $FS_CUDA_HOME/bin ) then
    setenv PATH "$FS_CUDA_HOME/bin":"$PATH"
  endif

  if ( -e $FS_CUDA_HOME/lib ) then

    setenv CUDALIBPATH $FS_CUDA_HOME/lib
    if ( -e /usr/lib64 ) then
      # this is a 64b machine
      setenv CUDALIBPATH $FS_CUDA_HOME/lib64
    endif

    if(! $?LD_LIBRARY_PATH ) then
      setenv LD_LIBRARY_PATH $CUDALIBPATH
    else
      setenv LD_LIBRARY_PATH "$CUDALIBPATH":"$LD_LIBRARY_PATH"
    endif
    if(! $?DYLD_LIBRARY_PATH ) then
      setenv DYLD_LIBRARY_PATH $CUDALIBPATH
    else
      setenv DYLD_LIBRARY_PATH "$CUDALIBPATH":"$DYLD_LIBRARY_PATH"
    endif

  endif

  # default: assume platform has CUDA libs installed somewhere
endif
