Skip to content

Commit 593d8a5

Browse files
committed
Add doca_ofed building block for the NVIDIA DOCA Software Framework
1 parent d267b0c commit 593d8a5

File tree

5 files changed

+460
-0
lines changed

5 files changed

+460
-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: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
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+
import hpccm.templates.rm
29+
import hpccm.templates.tar
30+
import hpccm.templates.wget
31+
32+
from hpccm.building_blocks.base import bb_base
33+
from hpccm.building_blocks.packages import packages
34+
from hpccm.common import cpu_arch, linux_distro
35+
from hpccm.primitives.comment import comment
36+
from hpccm.primitives.copy import copy
37+
from hpccm.primitives.label import label
38+
from hpccm.primitives.shell import shell
39+
40+
class doca_ofed(bb_base, hpccm.templates.annotate, hpccm.templates.rm,
41+
hpccm.templates.tar, hpccm.templates.wget):
42+
"""The `doca_ofed` building block downloads and installs the [NVIDIA
43+
DOCA Software Framework](https://developer.nvidia.com/networking/doca).
44+
45+
# Parameters
46+
47+
annotate: Boolean flag to specify whether to include annotations
48+
(labels). The default is False.
49+
50+
archlabel: The CPU architecture label assigned by Mellanox to the
51+
package repository. The default value is `x86_64` for x86_64
52+
processors and `arm64-sbsa` for aarch64 processors.
53+
54+
oslabel: The Linux distribution label assigned by Mellanox to the
55+
package repository. For Ubuntu, the default value is
56+
`ubuntuXX.04` where `XX` is derived from the base image. For
57+
RHEL-base Linux distributions, the default value is `rhelX.Y`
58+
where `X.Y` is `9.2` for RHEL 9.x and `8.6` for RHEL 8.x.
59+
60+
ospackages: List of OS packages to install prior to installing
61+
DOCA OFED. The default values are `ca-certificates`, `gnupg`, and
62+
`wget`.
63+
64+
packages: List of packages to install from Mellanox OFED. For
65+
Ubuntu, the default values are `ibverbs-providers`,
66+
`ibverbs-utils` `libibmad-dev`, `libibmad5`, `libibumad3`,
67+
`libibumad-dev`, `libibverbs-dev` `libibverbs1`, `librdmacm-dev`,
68+
and `librdmacm1`. For RHEL-based Linux distributions, the default
69+
values are `libibumad`, `libibverbs`, `libibverbs-utils`,
70+
`librdmacm`, `rdma-core`, and `rdma-core-devel`.
71+
72+
version: The version of DOCA OFED to download. The default value
73+
is `2.10.0`.
74+
75+
# Examples
76+
77+
```python
78+
doca_ofed(version='2.10.0')
79+
```
80+
81+
"""
82+
83+
def __init__(self, **kwargs):
84+
"""Initialize building block"""
85+
86+
super(doca_ofed, self).__init__(**kwargs)
87+
88+
self.__archlabel = kwargs.get('archlabel', '') # Filled in by __cpu_arch
89+
self.__key = 'https://linux.mellanox.com/public/repo/doca/GPG-KEY-Mellanox.pub'
90+
self.__oslabel = kwargs.get('oslabel', '') # Filled in by __distro
91+
self.__ospackages = kwargs.get('ospackages',
92+
['ca-certificates', 'gnupg', 'wget'])
93+
self.__packages = kwargs.get('packages', []) # Filled in by __distro
94+
self.__version = kwargs.get('version', '2.10.0')
95+
96+
# Add annotation
97+
self.add_annotation('version', self.__version)
98+
99+
# Set the CPU architecture specific parameters
100+
self.__cpu_arch()
101+
102+
# Set the Linux distribution specific parameters
103+
self.__distro()
104+
105+
# Fill in container instructions
106+
self.__instructions()
107+
108+
def __instructions(self):
109+
"""Fill in container instructions"""
110+
111+
self += comment('DOCA OFED version {}'.format(self.__version))
112+
113+
self += packages(ospackages=self.__ospackages)
114+
115+
self += packages(
116+
apt_keys=[self.__key],
117+
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'))],
118+
ospackages=self.__packages,
119+
yum_keys=[self.__key],
120+
yum_repositories=['https://linux.mellanox.com/public/repo/doca/{0}/{1}/{2}'.format(self.__version, self.__oslabel, self.__archlabel)])
121+
122+
self += label(metadata=self.annotate_step())
123+
124+
def __cpu_arch(self):
125+
"""Based on the CPU architecture, set values accordingly. A user
126+
specified value overrides any defaults."""
127+
128+
if not self.__archlabel:
129+
if hpccm.config.g_cpu_arch == cpu_arch.AARCH64:
130+
self.__archlabel = 'arm64-sbsa'
131+
elif hpccm.config.g_cpu_arch == cpu_arch.X86_64:
132+
self.__archlabel = 'x86_64'
133+
else: # pragma: no cover
134+
raise RuntimeError('Unknown CPU architecture')
135+
136+
def __distro(self):
137+
"""Based on the Linux distribution, set values accordingly. A user
138+
specified value overrides any defaults."""
139+
140+
if hpccm.config.g_linux_distro == linux_distro.UBUNTU:
141+
if not self.__oslabel:
142+
if hpccm.config.g_linux_version >= Version('24.0'):
143+
self.__oslabel = 'ubuntu24.04'
144+
elif hpccm.config.g_linux_version >= Version('22.0'):
145+
self.__oslabel = 'ubuntu22.04'
146+
else:
147+
self.__oslabel = 'ubuntu20.04'
148+
149+
if not self.__packages:
150+
self.__packages = ['libibverbs1', 'libibverbs-dev',
151+
'ibverbs-providers', 'ibverbs-utils',
152+
'libibmad5', 'libibmad-dev',
153+
'libibumad3', 'libibumad-dev',
154+
'librdmacm-dev', 'librdmacm1']
155+
156+
elif hpccm.config.g_linux_distro == linux_distro.CENTOS:
157+
if not self.__oslabel:
158+
if hpccm.config.g_linux_version >= Version('9.0'):
159+
self.__oslabel = 'rhel9.2'
160+
else:
161+
self.__oslabel = 'rhel8.6'
162+
163+
if not self.__packages:
164+
self.__packages = ['libibverbs', 'libibverbs-utils',
165+
'libibumad', 'librdmacm',
166+
'rdma-core', 'rdma-core-devel']
167+
168+
else: # pragma: no cover
169+
raise RuntimeError('Unknown Linux distribution')
170+
171+
def runtime(self, _from='0'):
172+
"""Generate the set of instructions to install the runtime specific
173+
components from a build in a previous stage.
174+
175+
# Examples
176+
177+
```python
178+
d = doca_ofed(...)
179+
Stage0 += d
180+
Stage1 += d.runtime()
181+
```
182+
"""
183+
184+
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)