Skip to content

Commit 5afdea6

Browse files
dstaay-fbmeta-codesync[bot]
authored andcommitted
Check mlx5dv - use mlx5 direct api (#1692)
Summary: Pull Request resolved: #1692 small change - use mlx5 specific apis to detect device. Reviewed By: allenwang28, casteryh Differential Revision: D85728514 fbshipit-source-id: 540ff28ce210701eb75ec0b005b45fd216789ade
1 parent a0aceab commit 5afdea6

File tree

1 file changed

+8
-29
lines changed

1 file changed

+8
-29
lines changed

monarch_rdma/src/ibverbs_primitives.rs

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -652,38 +652,17 @@ pub fn mlx5dv_supported() -> bool {
652652
fn mlx5dv_supported_impl() -> bool {
653653
// SAFETY: We are calling C functions from libibverbs and libmlx5.
654654
unsafe {
655+
let mut mlx5dv_supported = false;
655656
let mut num_devices = 0;
656657
let device_list = rdmaxcel_sys::ibv_get_device_list(&mut num_devices);
657-
658-
// Compute result in a block, ensuring cleanup happens afterward
659-
let result = {
660-
if device_list.is_null() || num_devices == 0 {
661-
false
662-
} else {
663-
// Try to open the first device and check mlx5dv support
664-
let device = *device_list;
665-
let mut mlx5dv_supported = false;
666-
667-
if !device.is_null() {
668-
let context = rdmaxcel_sys::ibv_open_device(device);
669-
if !context.is_null() {
670-
// Try to query device capabilities with mlx5dv
671-
let mut attrs_out = rdmaxcel_sys::mlx5dv_context::default();
672-
673-
// mlx5dv_query_device returns 0 on success
674-
if rdmaxcel_sys::mlx5dv_query_device(context, &mut attrs_out) == 0 {
675-
mlx5dv_supported = true;
676-
}
677-
678-
rdmaxcel_sys::ibv_close_device(context);
679-
}
680-
}
681-
mlx5dv_supported
658+
if !device_list.is_null() && num_devices > 0 {
659+
let device = *device_list;
660+
if !device.is_null() {
661+
mlx5dv_supported = rdmaxcel_sys::mlx5dv_is_supported(device);
682662
}
683-
};
684-
685-
rdmaxcel_sys::ibv_free_device_list(device_list);
686-
result
663+
rdmaxcel_sys::ibv_free_device_list(device_list);
664+
}
665+
mlx5dv_supported
687666
}
688667
}
689668

0 commit comments

Comments
 (0)