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-2022 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

17 #if defined HAVE_CONFIG_H
18 #include "config.h"
19 #endif
20 
21 #include "abi_common.h"
22 
23 
24 module m_gpu_detect
25 
26  use m_abicore
27 
28  use defs_basis
29  use m_xmpi
30 
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

SOURCE

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

SOURCE

168  subroutine get_topo(nproc,ngpu,topo)
169 
170   implicit none
171 
172 !Arguments ------------------------------------
173   integer,intent(in)  :: nproc,ngpu
174   integer,intent(out) :: topo
175 !Local ---------------------------
176   integer :: ierr,ndev,avail_gpu
177 ! *********************************************************************
178   topo = 0
179   if(nproc>1) topo = 1 !ncpu>1
180   if(ngpu==0) return   !no gpu
181 
182   if(ngpu==nproc)then
183     topo = 2             !1cpu,1gpu
184     if (nproc>1)topo = 3 !ncpu,ngpu
185     return
186   else
187     topo = 4               !ncpu>ngpu
188     if(nproc<ngpu)topo = 5 !ncpu<ngpu
189   endif
190 
191 end subroutine get_topo