monarch_rdma/
macros.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#[macro_export]
10macro_rules! cu_check {
11    ($result:expr) => {
12        let result = $result;
13        if result != rdmaxcel_sys::CUDA_SUCCESS {
14            let mut error_string: *const std::os::raw::c_char = std::ptr::null();
15            let err_result = rdmaxcel_sys::rdmaxcel_cuGetErrorString(result, &mut error_string);
16            if err_result != rdmaxcel_sys::CUDA_SUCCESS || error_string.is_null() {
17                panic!(
18                    "cuda failure {}:{} {:?} (cuGetErrorString failed with {:?})",
19                    file!(),
20                    line!(),
21                    result,
22                    err_result,
23                );
24            }
25            panic!(
26                "cuda failure {}:{} {:?} '{}'",
27                file!(),
28                line!(),
29                result,
30                std::ffi::CStr::from_ptr(error_string).to_string_lossy()
31            );
32        }
33    };
34}