Skip to main content

monarch_rdma/backend/ibverbs/
mlx_device.rs

1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 * All rights reserved.
4 *
5 * This source code is licensed under the BSD-style license found in the
6 * LICENSE file in the root directory of this source tree.
7 */
8
9//! Mellanox backend for [`IbvDevice`].
10
11use std::sync::Arc;
12
13use typeuri::Named;
14
15use super::device::IbvDeviceImpl;
16use super::mlx_domain::MlxDomain;
17use super::primitives::IbvConfig;
18use super::primitives::IbvContext;
19use crate::register_ibv_device_impl;
20
21/// PCI vendor ID for Mellanox Technologies.
22const MELLANOX_VENDOR_ID: u32 = 0x02c9;
23
24/// Mellanox backend.
25#[derive(Debug, Named)]
26pub struct MlxDevice;
27
28impl IbvDeviceImpl for MlxDevice {
29    type Domain = MlxDomain;
30
31    fn backend_name() -> &'static str {
32        "mellanox"
33    }
34
35    fn is_instance(ctx: Arc<IbvContext>) -> bool {
36        let mut attr = rdmaxcel_sys::ibv_device_attr::default();
37        // SAFETY: `ctx.as_ptr()` is a non-null context owned by
38        // the `Arc<IbvContext>` for the duration of this call;
39        // `&mut attr` is a writable, properly aligned
40        // `ibv_device_attr`.
41        let queried = unsafe { rdmaxcel_sys::ibv_query_device(ctx.as_ptr(), &mut attr) } == 0;
42        queried && attr.vendor_id == MELLANOX_VENDOR_ID
43    }
44
45    fn apply_config_defaults(_config: &mut IbvConfig) {}
46}
47
48register_ibv_device_impl!(MlxDevice);