TABLE OF CONTENTS


ABINIT/m_gpu_detect [ Modules ]

[ Top ] [ Modules ]

NAME

 m_gpu_detect

FUNCTION

 Detects the GPU associated to any cpu and associates a GPU, if
 possible, to any proc

COPYRIGHT

  Copyright (C) 2010-2018 ABINIT group (MMancini)
  This file is distributed under the terms of the
  GNU General Public License, see ~abinit/COPYING
  or http://www.gnu.org/copyleft/gpl.txt .

SOURCE

18 #if defined HAVE_CONFIG_H
19 #include "config.h"
20 #endif
21 
22 #include "abi_common.h"
23 
24 
25 module m_gpu_detect
26 
27  use m_abicore
28 
29  use defs_basis
30  use m_xmpi
31 #if defined HAVE_GPU_CUDA
32  use m_initcuda, only     : Get_ndevice
33 #endif
34 
35 
36  implicit none
37 
38  private
39 
40  public ::            &
41   find_set_gpu,       &  !Calc. the number of point,GPU,for any proc
42   get_topo               !Put the topology of machine in an integer
43 CONTAINS  !===========================================================

m_gpu_detect/find_set_gpu [ Functions ]

[ Top ] [ m_gpu_detect ] [ Functions ]

NAME

 find_set_gpu

FUNCTION

 Calculate the number of point,GPU,for any proc

INPUTS

  nproc= number of processor
  commcart= mpi communicator

OUTPUT

 ngpu=total number of gpu distributed on all node <=nproc
 gpu_map(0,nproc-1)=contains for any proc the associated device
 number. -1 if no gpu is associated

PARENTS

      m_rec

CHILDREN

SOURCE

 70  subroutine find_set_gpu(nproc,commcart,gpu_map,ngpu)
 71 
 72 
 73 !This section has been created automatically by the script Abilint (TD).
 74 !Do not modify the following lines by hand.
 75 #undef ABI_FUNC
 76 #define ABI_FUNC 'find_set_gpu'
 77 !End of the abilint section
 78 
 79   implicit none
 80 
 81 
 82 !Arguments ------------------------------------
 83   integer,intent(in) :: nproc,commcart
 84   integer,intent(out) :: ngpu
 85   integer,intent(out) :: gpu_map(0:nproc-1)
 86 !Local ---------------------------
 87   integer :: ierr,ndev,avail_gpu
 88   integer :: me,icpu,cpu_map_me
 89   character(20) :: name_ch
 90   character(20) :: nodes(0:nproc-1)
 91   character(500) :: msg
 92 ! *********************************************************************
 93 
 94   ngpu = 0
 95   gpu_map = -1
 96   ndev = 0
 97   me = 0
 98 
 99 #if defined HAVE_GPU_CUDA
100   me = xmpi_comm_rank(commcart)
101 
102   !--Get the number of compatible device on this CPU
103   call Get_ndevice(ndev)
104 
105   if(nproc == 1) then
106     if(ndev /= 0) gpu_map(0) = 0
107     ngpu = count(gpu_map>-1)
108     return
109   end if
110 
111   !--Get the name of the node
112   call xmpi_name(name_ch,ierr)
113 
114   !--Array containing the number of gpu seen by any cpu
115   call  xmpi_allgather(ndev,gpu_map,commcart,ierr)
116   !   write(std_out,*)' me,nedevice ',gpu_map
117 
118   !--Array containing the name of the cpu
119   call  xmpi_allgather(name_ch,nodes,commcart,ierr)
120 
121   !--Printing Nodes name
122   write(msg,'(3a)')&
123     & ' -Node names---------------',ch10,&
124     & '   me                name  '
125   call wrtout(std_out,msg,'COLL')
126   do icpu=0,nproc-1
127     write(msg,'(i5,a22)') icpu,trim(nodes(icpu))
128     call wrtout(std_out,msg,'COLL')
129   end do
130 
131   !--research of the cpu on the same node of this cpu
132   !   write(std_out,*)'ndev ',ndev
133   icpu = 0
134   avail_gpu = ndev
135   cpu_map_me = -1
136   do while(avail_gpu /= 0 .and. icpu <= me )
137     if( trim(nodes(icpu)) == trim(name_ch)) then
138       !--yes on the same node
139       if(me == icpu) cpu_map_me = ndev-avail_gpu
140       avail_gpu = avail_gpu -1
141     endif
142     icpu = icpu +1
143   end do
144 
145   !--All cpu know the cpu with associated gpu (and which gpu on the node)
146   !--Now gpu_map contains the number of the device which is associated
147   !  with any cpu (-1 if not)
148   call  xmpi_allgather(cpu_map_me,gpu_map,commcart,ierr)
149 
150   !--Count the total number of gpu
151   ngpu = count(gpu_map>-1)
152   !write(std_out,*)'total gpu',ngpu
153 
154 #endif
155 
156 end subroutine find_set_gpu

m_gpu_detect/get_topo [ Functions ]

[ Top ] [ m_gpu_detect ] [ Functions ]

NAME

 get_topo

FUNCTION

 Put the topology of machine in an integer

INPUTS

  nproc= number of processor
  ngpu = mpi communicator

OUTPUT

  topo= 0: 1 cpu;
        1: n cpu;
        2: 1 cpu 1 gpu;
        3: n cpu n gpu
        4: n cpu > m gpu;
        5: n cpu < m gpu

PARENTS

      m_rec

CHILDREN

SOURCE

185  subroutine get_topo(nproc,ngpu,topo)
186 
187 
188 !This section has been created automatically by the script Abilint (TD).
189 !Do not modify the following lines by hand.
190 #undef ABI_FUNC
191 #define ABI_FUNC 'get_topo'
192 !End of the abilint section
193 
194   implicit none
195 
196 !Arguments ------------------------------------
197   integer,intent(in)  :: nproc,ngpu
198   integer,intent(out) :: topo
199 !Local ---------------------------
200   integer :: ierr,ndev,avail_gpu
201 ! *********************************************************************
202   topo = 0
203   if(nproc>1) topo = 1 !ncpu>1
204   if(ngpu==0) return   !no gpu
205 
206   if(ngpu==nproc)then
207     topo = 2             !1cpu,1gpu
208     if (nproc>1)topo = 3 !ncpu,ngpu
209     return
210   else
211     topo = 4               !ncpu>ngpu
212     if(nproc<ngpu)topo = 5 !ncpu<ngpu
213   endif
214 
215 end subroutine get_topo