Skip to content

Commit 65e02c4

Browse files
authored
Add doca_ofed building block for the NVIDIA DOCA Software Framework (#507)
1 parent 3942e22 commit 65e02c4

File tree

5 files changed

+455
-0
lines changed

5 files changed

+455
-0
lines changed

docs/building_blocks.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,68 @@ Stage0 += c
635635
Stage1 += c.runtime()
636636
```
637637

638+
# doca_ofed
639+
```python
640+
doca_ofed(self, **kwargs)
641+
```
642+
The `doca_ofed` building block downloads and installs the [NVIDIA
643+
DOCA Software Framework](https://developer.nvidia.com/networking/doca).
644+
645+
__Parameters__
646+
647+
648+
- __annotate__: Boolean flag to specify whether to include annotations
649+
(labels). The default is False.
650+
651+
- __archlabel__: The CPU architecture label assigned by Mellanox to the
652+
package repository. The default value is `x86_64` for x86_64
653+
processors and `arm64-sbsa` for aarch64 processors.
654+
655+
- __oslabel__: The Linux distribution label assigned by Mellanox to the
656+
package repository. For Ubuntu, the default value is
657+
`ubuntuXX.04` where `XX` is derived from the base image. For
658+
RHEL-base Linux distributions, the default value is `rhelX.Y`
659+
where `X.Y` is `9.2` for RHEL 9.x and `8.6` for RHEL 8.x.
660+
661+
- __ospackages__: List of OS packages to install prior to installing
662+
DOCA OFED. The default values are `ca-certificates`, `gnupg`, and
663+
`wget`.
664+
665+
- __packages__: List of packages to install from Mellanox OFED. For
666+
Ubuntu, the default values are `ibverbs-providers`,
667+
`ibverbs-utils` `libibmad-dev`, `libibmad5`, `libibumad3`,
668+
`libibumad-dev`, `libibverbs-dev` `libibverbs1`, `librdmacm-dev`,
669+
and `librdmacm1`. For RHEL-based Linux distributions, the default
670+
values are `libibumad`, `libibverbs`, `libibverbs-utils`,
671+
`librdmacm`, `rdma-core`, and `rdma-core-devel`.
672+
673+
- __version__: The version of DOCA OFED to download. The default value
674+
is `2.10.0`.
675+
676+
__Examples__
677+
678+
679+
```python
680+
doca_ofed(version='2.10.0')
681+
```
682+
683+
684+
## runtime
685+
```python
686+
doca_ofed.runtime(self, _from=u'0')
687+
```
688+
Generate the set of instructions to install the runtime specific
689+
components from a build in a previous stage.
690+
691+
__Examples__
692+
693+
694+
```python
695+
d = doca_ofed(...)
696+
Stage0 += d
697+
Stage1 += d.runtime()
698+
```
699+
638700
# fftw
639701
```python
640702
fftw(self, **kwargs)

hpccm/building_blocks/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
'charm',
2424
'cmake',
2525
'conda',
26+
'doca_ofed',
2627
'fftw',
2728
'gdrcopy',
2829
'generic_autotools',
@@ -78,6 +79,7 @@
7879
from hpccm.building_blocks.charm import charm
7980
from hpccm.building_blocks.cmake import cmake
8081
from hpccm.building_blocks.conda import conda
82+
from hpccm.building_blocks.doca_ofed import doca_ofed
8183
from hpccm.building_blocks.fftw import fftw
8284
from hpccm.building_blocks.gdrcopy import gdrcopy
8385
from hpccm.building_blocks.generic_autotools import generic_autotools

hpccm/building_blocks/doca_ofed.py

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
# Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# pylint: disable=invalid-name, too-few-public-methods
16+
17+
"""DOCA OFED building block"""
18+
19+
from __future__ import absolute_import
20+
from __future__ import unicode_literals
21+
from __future__ import print_function
22+
23+
from packaging.version import Version
24+
import posixpath
25+
26+
import hpccm.config
27+
import hpccm.templates.annotate
28+
29+
from hpccm.building_blocks.base import bb_base
30+
from hpccm.building_blocks.packages import packages
31+
from hpccm.common import cpu_arch, linux_distro
32+
from hpccm.primitives.comment import comment
33+
from hpccm.primitives.label import label
34+
35+
class doca_ofed(bb_base, hpccm.templates.annotate, hpccm.templates.rm,
36+
hpccm.templates.tar, hpccm.templates.wget):
37+
"""The `doca_ofed` building block downloads and installs the [NVIDIA
38+
DOCA Software Framework](https://developer.nvidia.com/networking/doca).
39+
40+
# Parameters
41+
42+
annotate: Boolean flag to specify whether to include annotations
43+
(labels). The default is False.
44+
45+
archlabel: The CPU architecture label assigned by Mellanox to the
46+
package repository. The default value is `x86_64` for x86_64
47+
processors and `arm64-sbsa` for aarch64 processors.
48+
49+
oslabel: The Linux distribution label assigned by Mellanox to the
50+
package repository. For Ubuntu, the default value is
51+
`ubuntuXX.04` where `XX` is derived from the base image. For
52+
RHEL-base Linux distributions, the default value is `rhelX.Y`
53+
where `X.Y` is `9.2` for RHEL 9.x and `8.6` for RHEL 8.x.
54+
55+
ospackages: List of OS packages to install prior to installing
56+
DOCA OFED. The default values are `ca-certificates`, `gnupg`, and
57+
`wget`.
58+
59+
packages: List of packages to install from Mellanox OFED. For
60+
Ubuntu, the default values are `ibverbs-providers`,
61+
`ibverbs-utils` `libibmad-dev`, `libibmad5`, `libibumad3`,
62+
`libibumad-dev`, `libibverbs-dev` `libibverbs1`, `librdmacm-dev`,
63+
and `librdmacm1`. For RHEL-based Linux distributions, the default
64+
values are `libibumad`, `libibverbs`, `libibverbs-utils`,
65+
`librdmacm`, `rdma-core`, and `rdma-core-devel`.
66+
67+
version: The version of DOCA OFED to download. The default value
68+
is `2.10.0`.
69+
70+
# Examples
71+
72+
```python
73+
doca_ofed(version='2.10.0')
74+
```
75+
76+
"""
77+
78+
def __init__(self, **kwargs):
79+
"""Initialize building block"""
80+
81+
super(doca_ofed, self).__init__(**kwargs)
82+
83+
self.__archlabel = kwargs.get('archlabel', '') # Filled in by __cpu_arch
84+
self.__key = 'https://linux.mellanox.com/public/repo/doca/GPG-KEY-Mellanox.pub'
85+
self.__oslabel = kwargs.get('oslabel', '') # Filled in by __distro
86+
self.__ospackages = kwargs.get('ospackages',
87+
['ca-certificates', 'gnupg', 'wget'])
88+
self.__packages = kwargs.get('packages', []) # Filled in by __distro
89+
self.__version = kwargs.get('version', '2.10.0')
90+
91+
# Add annotation
92+
self.add_annotation('version', self.__version)
93+
94+
# Set the CPU architecture specific parameters
95+
self.__cpu_arch()
96+
97+
# Set the Linux distribution specific parameters
98+
self.__distro()
99+
100+
# Fill in container instructions
101+
self.__instructions()
102+
103+
def __instructions(self):
104+
"""Fill in container instructions"""
105+
106+
self += comment('DOCA OFED version {}'.format(self.__version))
107+
108+
self += packages(ospackages=self.__ospackages)
109+
110+
self += packages(
111+
apt_keys=[self.__key],
112+
apt_repositories=['deb [signed-by=/usr/share/keyrings/{3}] https://linux.mellanox.com/public/repo/doca/{0}/{1}/{2}/ ./'.format(self.__version, self.__oslabel, self.__archlabel, posixpath.basename(self.__key).replace('.pub', '.gpg'))],
113+
ospackages=self.__packages,
114+
yum_keys=[self.__key],
115+
yum_repositories=['https://linux.mellanox.com/public/repo/doca/{0}/{1}/{2}'.format(self.__version, self.__oslabel, self.__archlabel)])
116+
117+
self += label(metadata=self.annotate_step())
118+
119+
def __cpu_arch(self):
120+
"""Based on the CPU architecture, set values accordingly. A user
121+
specified value overrides any defaults."""
122+
123+
if not self.__archlabel:
124+
if hpccm.config.g_cpu_arch == cpu_arch.AARCH64:
125+
self.__archlabel = 'arm64-sbsa'
126+
elif hpccm.config.g_cpu_arch == cpu_arch.X86_64:
127+
self.__archlabel = 'x86_64'
128+
else: # pragma: no cover
129+
raise RuntimeError('Unknown CPU architecture')
130+
131+
def __distro(self):
132+
"""Based on the Linux distribution, set values accordingly. A user
133+
specified value overrides any defaults."""
134+
135+
if hpccm.config.g_linux_distro == linux_distro.UBUNTU:
136+
if not self.__oslabel:
137+
if hpccm.config.g_linux_version >= Version('24.0'):
138+
self.__oslabel = 'ubuntu24.04'
139+
elif hpccm.config.g_linux_version >= Version('22.0'):
140+
self.__oslabel = 'ubuntu22.04'
141+
else:
142+
self.__oslabel = 'ubuntu20.04'
143+
144+
if not self.__packages:
145+
self.__packages = ['libibverbs1', 'libibverbs-dev',
146+
'ibverbs-providers', 'ibverbs-utils',
147+
'libibmad5', 'libibmad-dev',
148+
'libibumad3', 'libibumad-dev',
149+
'librdmacm-dev', 'librdmacm1']
150+
151+
elif hpccm.config.g_linux_distro == linux_distro.CENTOS:
152+
if not self.__oslabel:
153+
if hpccm.config.g_linux_version >= Version('9.0'):
154+
self.__oslabel = 'rhel9.2'
155+
else:
156+
self.__oslabel = 'rhel8.6'
157+
158+
if not self.__packages:
159+
self.__packages = ['libibverbs', 'libibverbs-utils',
160+
'libibumad', 'librdmacm',
161+
'rdma-core', 'rdma-core-devel']
162+
163+
else: # pragma: no cover
164+
raise RuntimeError('Unknown Linux distribution')
165+
166+
def runtime(self, _from='0'):
167+
"""Generate the set of instructions to install the runtime specific
168+
components from a build in a previous stage.
169+
170+
# Examples
171+
172+
```python
173+
d = doca_ofed(...)
174+
Stage0 += d
175+
Stage1 += d.runtime()
176+
```
177+
"""
178+
179+
return str(self)

pydocmd.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ generate:
1313
- hpccm.building_blocks.charm+
1414
- hpccm.building_blocks.cmake+
1515
- hpccm.building_blocks.conda+
16+
- hpccm.building_blocks.doca_ofed+
1617
- hpccm.building_blocks.fftw+
1718
- hpccm.building_blocks.gdrcopy+
1819
- hpccm.building_blocks.generic_autotools+

0 commit comments

Comments
 (0)