~ubuntu-branches/debian/sid/lammps/sid

« back to all changes in this revision

Viewing changes to doc/accelerate_gpu.txt

  • Committer: Package Import Robot
  • Author(s): Anton Gladky
  • Date: 2015-04-29 23:44:49 UTC
  • mfrom: (5.1.3 experimental)
  • Revision ID: package-import@ubuntu.com-20150429234449-mbhy9utku6hp6oq8
Tags: 0~20150313.gitfa668e1-1
Upload into unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"Previous Section"_Section_packages.html - "LAMMPS WWW Site"_lws -
 
2
"LAMMPS Documentation"_ld - "LAMMPS Commands"_lc :c
 
3
 
 
4
:link(lws,http://lammps.sandia.gov)
 
5
:link(ld,Manual.html)
 
6
:link(lc,Section_commands.html#comm)
 
7
 
 
8
:line
 
9
 
 
10
"Return to Section accelerate overview"_Section_accelerate.html
 
11
 
 
12
5.3.2 GPU package :h4
 
13
 
 
14
The GPU package was developed by Mike Brown at ORNL and his
 
15
collaborators, particularly Trung Nguyen (ORNL).  It provides GPU
 
16
versions of many pair styles, including the 3-body Stillinger-Weber
 
17
pair style, and for "kspace_style pppm"_kspace_style.html for
 
18
long-range Coulombics.  It has the following general features:
 
19
 
 
20
It is designed to exploit common GPU hardware configurations where one
 
21
or more GPUs are coupled to many cores of one or more multi-core CPUs,
 
22
e.g. within a node of a parallel machine. :ulb,l
 
23
 
 
24
Atom-based data (e.g. coordinates, forces) moves back-and-forth
 
25
between the CPU(s) and GPU every timestep. :l
 
26
 
 
27
Neighbor lists can be built on the CPU or on the GPU :l
 
28
 
 
29
The charge assignement and force interpolation portions of PPPM can be
 
30
run on the GPU.  The FFT portion, which requires MPI communication
 
31
between processors, runs on the CPU. :l
 
32
 
 
33
Asynchronous force computations can be performed simultaneously on the
 
34
CPU(s) and GPU. :l
 
35
 
 
36
It allows for GPU computations to be performed in single or double
 
37
precision, or in mixed-mode precision, where pairwise forces are
 
38
computed in single precision, but accumulated into double-precision
 
39
force vectors. :l
 
40
 
 
41
LAMMPS-specific code is in the GPU package.  It makes calls to a
 
42
generic GPU library in the lib/gpu directory.  This library provides
 
43
NVIDIA support as well as more general OpenCL support, so that the
 
44
same functionality can eventually be supported on a variety of GPU
 
45
hardware. :l,ule
 
46
 
 
47
Here is a quick overview of how to use the GPU package:
 
48
 
 
49
build the library in lib/gpu for your GPU hardware wity desired precision
 
50
include the GPU package and build LAMMPS
 
51
use the mpirun command to set the number of MPI tasks/node which determines the number of MPI tasks/GPU
 
52
specify the # of GPUs per node
 
53
use GPU styles in your input script :ul
 
54
 
 
55
The latter two steps can be done using the "-pk gpu" and "-sf gpu"
 
56
"command-line switches"_Section_start.html#start_7 respectively.  Or
 
57
the effect of the "-pk" or "-sf" switches can be duplicated by adding
 
58
the "package gpu"_package.html or "suffix gpu"_suffix.html commands
 
59
respectively to your input script.
 
60
 
 
61
[Required hardware/software:]
 
62
 
 
63
To use this package, you currently need to have an NVIDIA GPU and
 
64
install the NVIDIA Cuda software on your system:
 
65
 
 
66
Check if you have an NVIDIA GPU: cat /proc/driver/nvidia/gpus/0/information
 
67
Go to http://www.nvidia.com/object/cuda_get.html
 
68
Install a driver and toolkit appropriate for your system (SDK is not necessary)
 
69
Run lammps/lib/gpu/nvc_get_devices (after building the GPU library, see below) to list supported devices and properties :ul
 
70
 
 
71
[Building LAMMPS with the GPU package:]
 
72
 
 
73
This requires two steps (a,b): build the GPU library, then build
 
74
LAMMPS with the GPU package.
 
75
 
 
76
You can do both these steps in one line, using the src/Make.py script,
 
77
described in "Section 2.4"_Section_start.html#start_4 of the manual.
 
78
Type "Make.py -h" for help.  If run from the src directory, this
 
79
command will create src/lmp_gpu using src/MAKE/Makefile.mpi as the
 
80
starting Makefile.machine:
 
81
 
 
82
Make.py -p gpu -gpu mode=single arch=31 -o gpu lib-gpu file mpi :pre
 
83
 
 
84
Or you can follow these two (a,b) steps:
 
85
 
 
86
(a) Build the GPU library
 
87
 
 
88
The GPU library is in lammps/lib/gpu.  Select a Makefile.machine (in
 
89
lib/gpu) appropriate for your system.  You should pay special
 
90
attention to 3 settings in this makefile.
 
91
 
 
92
CUDA_HOME = needs to be where NVIDIA Cuda software is installed on your system
 
93
CUDA_ARCH = needs to be appropriate to your GPUs
 
94
CUDA_PREC = precision (double, mixed, single) you desire :ul
 
95
 
 
96
See lib/gpu/Makefile.linux.double for examples of the ARCH settings
 
97
for different GPU choices, e.g. Fermi vs Kepler.  It also lists the
 
98
possible precision settings:
 
99
 
 
100
CUDA_PREC = -D_SINGLE_SINGLE  # single precision for all calculations
 
101
CUDA_PREC = -D_DOUBLE_DOUBLE  # double precision for all calculations
 
102
CUDA_PREC = -D_SINGLE_DOUBLE  # accumulation of forces, etc, in double :pre
 
103
 
 
104
The last setting is the mixed mode referred to above.  Note that your
 
105
GPU must support double precision to use either the 2nd or 3rd of
 
106
these settings.
 
107
 
 
108
To build the library, type:
 
109
 
 
110
make -f Makefile.machine :pre
 
111
 
 
112
If successful, it will produce the files libgpu.a and Makefile.lammps.
 
113
 
 
114
The latter file has 3 settings that need to be appropriate for the
 
115
paths and settings for the CUDA system software on your machine.
 
116
Makefile.lammps is a copy of the file specified by the EXTRAMAKE
 
117
setting in Makefile.machine.  You can change EXTRAMAKE or create your
 
118
own Makefile.lammps.machine if needed.
 
119
 
 
120
Note that to change the precision of the GPU library, you need to
 
121
re-build the entire library.  Do a "clean" first, e.g. "make -f
 
122
Makefile.linux clean", followed by the make command above.
 
123
 
 
124
(b) Build LAMMPS with the GPU package
 
125
 
 
126
cd lammps/src
 
127
make yes-gpu
 
128
make machine :pre
 
129
 
 
130
No additional compile/link flags are needed in Makefile.machine.
 
131
 
 
132
Note that if you change the GPU library precision (discussed above)
 
133
and rebuild the GPU library, then you also need to re-install the GPU
 
134
package and re-build LAMMPS, so that all affected files are
 
135
re-compiled and linked to the new GPU library.
 
136
 
 
137
[Run with the GPU package from the command line:]
 
138
 
 
139
The mpirun or mpiexec command sets the total number of MPI tasks used
 
140
by LAMMPS (one or multiple per compute node) and the number of MPI
 
141
tasks used per node.  E.g. the mpirun command in MPICH does this via
 
142
its -np and -ppn switches.  Ditto for OpenMPI via -np and -npernode.
 
143
 
 
144
When using the GPU package, you cannot assign more than one GPU to a
 
145
single MPI task.  However multiple MPI tasks can share the same GPU,
 
146
and in many cases it will be more efficient to run this way.  Likewise
 
147
it may be more efficient to use less MPI tasks/node than the available
 
148
# of CPU cores.  Assignment of multiple MPI tasks to a GPU will happen
 
149
automatically if you create more MPI tasks/node than there are
 
150
GPUs/mode.  E.g. with 8 MPI tasks/node and 2 GPUs, each GPU will be
 
151
shared by 4 MPI tasks.
 
152
 
 
153
Use the "-sf gpu" "command-line switch"_Section_start.html#start_7,
 
154
which will automatically append "gpu" to styles that support it.  Use
 
155
the "-pk gpu Ng" "command-line switch"_Section_start.html#start_7 to
 
156
set Ng = # of GPUs/node to use.
 
157
 
 
158
lmp_machine -sf gpu -pk gpu 1 -in in.script                         # 1 MPI task uses 1 GPU
 
159
mpirun -np 12 lmp_machine -sf gpu -pk gpu 2 -in in.script           # 12 MPI tasks share 2 GPUs on a single 16-core (or whatever) node
 
160
mpirun -np 48 -ppn 12 lmp_machine -sf gpu -pk gpu 2 -in in.script   # ditto on 4 16-core nodes :pre
 
161
 
 
162
Note that if the "-sf gpu" switch is used, it also issues a default
 
163
"package gpu 1"_package.html command, which sets the number of
 
164
GPUs/node to 1.
 
165
 
 
166
Using the "-pk" switch explicitly allows for setting of the number of
 
167
GPUs/node to use and additional options.  Its syntax is the same as
 
168
same as the "package gpu" command.  See the "package"_package.html
 
169
command doc page for details, including the default values used for
 
170
all its options if it is not specified.
 
171
 
 
172
Note that the default for the "package gpu"_package.html command is to
 
173
set the Newton flag to "off" pairwise interactions.  It does not
 
174
affect the setting for bonded interactions (LAMMPS default is "on").
 
175
The "off" setting for pairwise interaction is currently required for
 
176
GPU package pair styles.
 
177
 
 
178
[Or run with the GPU package by editing an input script:]
 
179
 
 
180
The discussion above for the mpirun/mpiexec command, MPI tasks/node,
 
181
and use of multiple MPI tasks/GPU is the same.
 
182
 
 
183
Use the "suffix gpu"_suffix.html command, or you can explicitly add an
 
184
"gpu" suffix to individual styles in your input script, e.g.
 
185
 
 
186
pair_style lj/cut/gpu 2.5 :pre
 
187
 
 
188
You must also use the "package gpu"_package.html command to enable the
 
189
GPU package, unless the "-sf gpu" or "-pk gpu" "command-line
 
190
switches"_Section_start.html#start_7 were used.  It specifies the
 
191
number of GPUs/node to use, as well as other options.
 
192
 
 
193
[Speed-ups to expect:]
 
194
 
 
195
The performance of a GPU versus a multi-core CPU is a function of your
 
196
hardware, which pair style is used, the number of atoms/GPU, and the
 
197
precision used on the GPU (double, single, mixed).
 
198
 
 
199
See the "Benchmark page"_http://lammps.sandia.gov/bench.html of the
 
200
LAMMPS web site for performance of the GPU package on various
 
201
hardware, including the Titan HPC platform at ORNL.
 
202
 
 
203
You should also experiment with how many MPI tasks per GPU to use to
 
204
give the best performance for your problem and machine.  This is also
 
205
a function of the problem size and the pair style being using.
 
206
Likewise, you should experiment with the precision setting for the GPU
 
207
library to see if single or mixed precision will give accurate
 
208
results, since they will typically be faster.
 
209
 
 
210
[Guidelines for best performance:]
 
211
 
 
212
Using multiple MPI tasks per GPU will often give the best performance,
 
213
as allowed my most multi-core CPU/GPU configurations. :ulb,l
 
214
 
 
215
If the number of particles per MPI task is small (e.g. 100s of
 
216
particles), it can be more efficient to run with fewer MPI tasks per
 
217
GPU, even if you do not use all the cores on the compute node. :l
 
218
 
 
219
The "package gpu"_package.html command has several options for tuning
 
220
performance.  Neighbor lists can be built on the GPU or CPU.  Force
 
221
calculations can be dynamically balanced across the CPU cores and
 
222
GPUs.  GPU-specific settings can be made which can be optimized
 
223
for different hardware.  See the "packakge"_package.html command
 
224
doc page for details. :l
 
225
 
 
226
As described by the "package gpu"_package.html command, GPU
 
227
accelerated pair styles can perform computations asynchronously with
 
228
CPU computations. The "Pair" time reported by LAMMPS will be the
 
229
maximum of the time required to complete the CPU pair style
 
230
computations and the time required to complete the GPU pair style
 
231
computations. Any time spent for GPU-enabled pair styles for
 
232
computations that run simultaneously with "bond"_bond_style.html,
 
233
"angle"_angle_style.html, "dihedral"_dihedral_style.html,
 
234
"improper"_improper_style.html, and "long-range"_kspace_style.html
 
235
calculations will not be included in the "Pair" time. :l
 
236
 
 
237
When the {mode} setting for the package gpu command is force/neigh,
 
238
the time for neighbor list calculations on the GPU will be added into
 
239
the "Pair" time, not the "Neigh" time.  An additional breakdown of the
 
240
times required for various tasks on the GPU (data copy, neighbor
 
241
calculations, force computations, etc) are output only with the LAMMPS
 
242
screen output (not in the log file) at the end of each run.  These
 
243
timings represent total time spent on the GPU for each routine,
 
244
regardless of asynchronous CPU calculations. :l
 
245
 
 
246
The output section "GPU Time Info (average)" reports "Max Mem / Proc".
 
247
This is the maximum memory used at one time on the GPU for data
 
248
storage by a single MPI process. :l,ule
 
249
 
 
250
[Restrictions:]
 
251
 
 
252
None.