-
Notifications
You must be signed in to change notification settings - Fork 87
/
hpcx.py
339 lines (289 loc) · 14.5 KB
/
hpcx.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
# Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# pylint: disable=invalid-name, too-few-public-methods
# pylint: disable=too-many-instance-attributes
"""HPC-X building block"""
from __future__ import absolute_import
from __future__ import unicode_literals
from __future__ import print_function
from distutils.version import StrictVersion
import posixpath
import re
import hpccm.config
import hpccm.templates.envvars
import hpccm.templates.ldconfig
import hpccm.templates.rm
import hpccm.templates.tar
import hpccm.templates.wget
from hpccm.building_blocks.base import bb_base
from hpccm.building_blocks.packages import packages
from hpccm.common import linux_distro
from hpccm.primitives.comment import comment
from hpccm.primitives.environment import environment
from hpccm.primitives.shell import shell
from hpccm.toolchain import toolchain
class hpcx(bb_base, hpccm.templates.envvars, hpccm.templates.ldconfig,
hpccm.templates.rm, hpccm.templates.tar, hpccm.templates.wget):
"""The `hpcx` building block downloads and installs the [Mellanox
HPC-X](https://www.mellanox.com/page/products_dyn?product_family=189&mtag=hpc-x)
component.
# Parameters
environment: Boolean flag to specify whether the environment
should be modified to include HPC-X. This option is only
recognized if `hpcxinit` is False. The default is True.
hpcxinit: Mellanox HPC-X provides an environment script
(`hpcx-init.sh`) to setup the HPC-X environment. If this value is
`True`, the bashrc is modified to automatically source this
environment script. However, HPC-X is not automatically available
to subsequent container image build steps; the environment is
available when the container image is run. To set the HPC-X
environment in subsequent build steps you can explicitly call
`source /usr/local/hpcx/hpcx-init.sh && hpcx_init` in each build
step. If this value is set to `False`, then the environment is
set such that the environment is visible to both subsequent
container image build steps and when the container image is run.
However, the environment may differ slightly from that set by
`hpcx-init.sh`. The default value is `True`.
inbox: Boolean flag to specify whether to use Mellanox HPC-X built
for Inbox OFED. If the value is `True`, use Inbox OFED. If the
value is `False`, use Mellanox OFED. The default is `False`.
ldconfig: Boolean flag to specify whether the Mellanox HPC-X
library directories should be added dynamic linker cache. If
False, then `LD_LIBRARY_PATH` is modified to include the HPC-X
library directories. This value is ignored if `hpcxinit` is
`True`. The default value is False.
mlnx_ofed: The version of Mellanox OFED that should be matched.
This value is ignored if Inbox OFED is selected. The default
value is `4.7-1.0.0.1`.
multi_thread: Boolean flag to specify whether the multi-threaded
version of Mellanox HPC-X should be used. The default is `False`.
oslabel: The Linux distribution label assigned by Mellanox to the
tarball. For Ubuntu, the default value is `ubuntu16.04` for
Ubuntu 16.04 and `ubuntu18.04` for Ubuntu 18.04. For RHEL-based
Linux distributions, the default value is `redhat7.6` for version
7 and `redhat8.0` for version 8.
ospackages: List of OS packages to install prior to installing
Mellanox HPC-X. For Ubuntu, the default values are `bzip2`,
`openssh-client`, `tar`, and `wget`. For RHEL-based distributions
the default values are `bzip2`, `openssh-clients`, `tar`, and
`wget`.
prefix: The top level installation location. The default value is
`/usr/local/hpcx`.
version: The version of Mellanox HPC-X to install. The default
value is `2.6.0`.
# Examples
```python
hpcx(prefix='/usr/local/hpcx', version='2.6.0')
```
"""
def __init__(self, **kwargs):
"""Initialize building block"""
super(hpcx, self).__init__(**kwargs)
self.__arch = hpccm.config.get_cpu_architecture()
self.__baseurl = kwargs.get('baseurl',
'http://www.mellanox.com/downloads/hpc/hpc-x')
self.__bashrc = '' # Filled in by __distro()
self.__hpcxinit = kwargs.get('hpcxinit', True)
self.__inbox = kwargs.get('inbox', False)
self.__mlnx_ofed = kwargs.get('mlnx_ofed', '4.7-1.0.0.1')
self.__multi_thread = kwargs.get('multi_thread', False)
self.__oslabel = kwargs.get('oslabel', '') # Filled in by __distro()
self.__ospackages = kwargs.get('ospackages', []) # Filled in by _distro()
self.__packages = kwargs.get('packages', [])
self.__prefix = kwargs.get('prefix', '/usr/local/hpcx')
self.__version = kwargs.get('version', '2.6.0')
self.__commands = [] # Filled in by __setup()
self.__wd = '/var/tmp' # working directory
# Output toolchain
self.toolchain = toolchain(CC='mpicc', CXX='mpicxx', F77='mpif77',
F90='mpif90', FC='mpifort')
# Set the Linux distribution specific parameters
self.__distro()
# Construct the series of steps to execute
self.__setup()
# Fill in container instructions
self.__instructions()
def __instructions(self):
"""Fill in container instructions"""
self += comment('Mellanox HPC-X version {}'.format(self.__version))
self += packages(ospackages=self.__ospackages)
self += shell(commands=self.__commands)
self += environment(variables=self.environment_step())
def __distro(self):
"""Based on the Linux distribution, set values accordingly. A user
specified value overrides any defaults."""
if hpccm.config.g_linux_distro == linux_distro.UBUNTU:
if not self.__oslabel:
if hpccm.config.g_linux_version >= StrictVersion('18.0'):
self.__oslabel = 'ubuntu18.04'
else:
self.__oslabel = 'ubuntu16.04'
if not self.__ospackages:
self.__ospackages = ['bzip2', 'openssh-client', 'tar', 'wget']
self.__bashrc = '/etc/bash.bashrc'
elif hpccm.config.g_linux_distro == linux_distro.CENTOS:
if not self.__oslabel:
if hpccm.config.g_linux_version >= StrictVersion('8.0'):
self.__oslabel = 'redhat8.0'
else:
self.__oslabel = 'redhat7.6'
if not self.__ospackages:
self.__ospackages = ['bzip2', 'openssh-clients', 'tar', 'wget']
self.__bashrc = '/etc/bashrc'
else: # pragma: no cover
raise RuntimeError('Unknown Linux distribution')
def __setup(self):
"""Construct the series of shell commands, i.e., fill in
self.__commands"""
# The download URL has the format MAJOR.MINOR in the path and
# the tarball contains MAJOR.MINOR.REVISION, so pull apart the
# full version to get the individual components.
match = re.match(r'(?P<major>\d+)\.(?P<minor>\d+)\.(?P<revision>\d+)',
self.__version)
major_minor = '{0}.{1}'.format(match.groupdict()['major'],
match.groupdict()['minor'])
if self.__inbox:
# Use inbox OFED
self.__label = 'hpcx-v{0}-gcc-inbox-{1}-{2}'.format(
self.__version, self.__oslabel, self.__arch)
else:
# Use MLNX OFED
self.__label = 'hpcx-v{0}-gcc-MLNX_OFED_LINUX-{1}-{2}-{3}'.format(
self.__version, self.__mlnx_ofed, self.__oslabel, self.__arch)
tarball = self.__label + '.tbz'
url = '{0}/v{1}/{2}'.format(self.__baseurl, major_minor, tarball)
# Download source from web
self.__commands.append(self.download_step(url=url, directory=self.__wd))
# "Install"
self.__commands.append(self.untar_step(
tarball=posixpath.join(self.__wd, tarball), directory=self.__wd))
self.__commands.append('cp -a {0} {1}'.format(
posixpath.join(self.__wd, self.__label), self.__prefix))
# Set the environment
if self.__hpcxinit:
# Use hpcxinit script
if self.__multi_thread:
self.__commands.append('echo "source {0}" >> {1}'.format(
posixpath.join(self.__prefix, 'hpcx-mt-init-ompi.sh'),
self.__bashrc))
else:
self.__commands.append('echo "source {0}" >> {1}'.format(
posixpath.join(self.__prefix, 'hpcx-init-ompi.sh'),
self.__bashrc))
self.__commands.append('echo "hpcx_load" >> {0}'.format(
self.__bashrc))
else:
# Set environment manually
hpcx_dir = self.__prefix
if self.__multi_thread:
hpcx_ucx_dir = posixpath.join(hpcx_dir, 'ucx', 'mt')
else:
hpcx_ucx_dir = posixpath.join(hpcx_dir, 'ucx')
hpcx_sharp_dir = posixpath.join(hpcx_dir, 'sharp')
hpcx_nccl_rdma_sharp_plugin_dir = posixpath.join(
hpcx_dir, 'nccl_rdma_sharp_plugin')
hpcx_hcoll_dir = posixpath.join(hpcx_dir, 'hcoll')
hpcx_mpi_dir = posixpath.join(hpcx_dir, 'ompi')
hpcx_oshmem_dir = hpcx_mpi_dir
hpcx_mpi_tests_dir = posixpath.join(hpcx_mpi_dir, 'tests')
hpcx_osu_dir = posixpath.join(hpcx_mpi_tests_dir,
'osu-micro-benchmarks-5.3.2')
hpcx_osu_cuda_dir = posixpath.join(
hpcx_mpi_tests_dir, 'osu-micro-benchmarks-5.3.2-cuda')
hpcx_ipm_dir = posixpath.join(hpcx_mpi_tests_dir, 'ipm-2.0.6')
hpcx_ipm_lib = posixpath.join(hpcx_ipm_dir, 'lib', 'libipm.so')
hpcx_clusterkit_dir = posixpath.join(hpcx_dir, 'clusterkit')
self.environment_variables = {
'CPATH': ':'.join([
posixpath.join(hpcx_hcoll_dir, 'include'),
posixpath.join(hpcx_mpi_dir, 'include'),
posixpath.join(hpcx_sharp_dir, 'include'),
posixpath.join(hpcx_ucx_dir, 'include'),
'$CPATH']),
'HPCX_CLUSTERKIT_DIR': hpcx_clusterkit_dir,
'HPCX_DIR': hpcx_dir,
'HPCX_HCOLL_DIR': hpcx_hcoll_dir,
'HPCX_IPM_DIR': hpcx_ipm_dir,
'HPCX_IPM_LIB': hpcx_ipm_lib,
'HPCX_MPI_DIR': hpcx_mpi_dir,
'HPCX_MPI_TESTS_DIR': hpcx_mpi_tests_dir,
'HPCX_NCCL_RDMA_SHARP_PLUGIN_DIR': hpcx_nccl_rdma_sharp_plugin_dir,
'HPCX_OSHMEM_DIR': hpcx_oshmem_dir,
'HPCX_OSU_CUDA_DIR': hpcx_osu_cuda_dir,
'HPCX_OSU_DIR': hpcx_osu_dir,
'HPCX_SHARP_DIR': hpcx_sharp_dir,
'HPCX_UCX_DIR': hpcx_ucx_dir,
'LIBRARY_PATH': ':'.join([
posixpath.join(hpcx_hcoll_dir, 'lib'),
posixpath.join(hpcx_mpi_dir, 'lib'),
posixpath.join(hpcx_nccl_rdma_sharp_plugin_dir, 'lib'),
posixpath.join(hpcx_sharp_dir, 'lib'),
posixpath.join(hpcx_ucx_dir, 'lib'),
'$LIBRARY_PATH']),
'MPI_HOME': hpcx_mpi_dir,
'OMPI_HOME': hpcx_mpi_dir,
'OPAL_PREFIX': hpcx_mpi_dir,
'OSHMEM_HOME': hpcx_mpi_dir,
'PATH': ':'.join([
posixpath.join(hpcx_clusterkit_dir, 'bin'),
posixpath.join(hpcx_hcoll_dir, 'bin'),
posixpath.join(hpcx_mpi_dir, 'bin'),
posixpath.join(hpcx_ucx_dir, 'bin'),
'$PATH']),
'PKG_CONFIG_PATH': ':'.join([
posixpath.join(hpcx_hcoll_dir, 'lib', 'pkgconfig'),
posixpath.join(hpcx_mpi_dir, 'lib', 'pkgconfig'),
posixpath.join(hpcx_sharp_dir, 'lib', 'pkgconfig'),
posixpath.join(hpcx_ucx_dir, 'lib', 'pkgconfig'),
'$PKG_CONFIG_PATH']),
'SHMEM_HOME': hpcx_mpi_dir}
# Set library path
if self.ldconfig:
self.__commands.append(self.ldcache_step(
directory=posixpath.join(hpcx_hcoll_dir, 'lib')))
self.__commands.append(self.ldcache_step(
directory=posixpath.join(hpcx_mpi_dir, 'lib')))
self.__commands.append(self.ldcache_step(
directory=posixpath.join(hpcx_nccl_rdma_sharp_plugin_dir,
'lib')))
self.__commands.append(self.ldcache_step(
directory=posixpath.join(hpcx_sharp_dir, 'lib')))
self.__commands.append(self.ldcache_step(
directory=posixpath.join(hpcx_ucx_dir, 'lib')))
self.__commands.append(self.ldcache_step(
directory=posixpath.join(hpcx_ucx_dir, 'lib', 'ucx')))
else:
self.environment_variables['LD_LIBRARY_PATH'] = ':'.join([
posixpath.join(hpcx_hcoll_dir, 'lib'),
posixpath.join(hpcx_mpi_dir, 'lib'),
posixpath.join(hpcx_nccl_rdma_sharp_plugin_dir, 'lib'),
posixpath.join(hpcx_sharp_dir, 'lib'),
posixpath.join(hpcx_ucx_dir, 'lib'),
posixpath.join(hpcx_ucx_dir, 'lib', 'ucx'),
'$LD_LIBRARY_PATH'])
# Cleanup tarball and directory
self.__commands.append(self.cleanup_step(
items=[posixpath.join(self.__wd, tarball),
posixpath.join(self.__wd, self.__label)]))
def runtime(self, _from='0'):
"""Generate the set of instructions to install the runtime specific
components from a build in a previous stage.
# Examples
```python
h = hpcx(...)
Stage0 += h
Stage1 += h.runtime()
```
"""
return str(self)