/* -------------------------------------------------------------------------
 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * This file is part of the MindStudio project.
 *
 * MindStudio is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *
 *    http://license.coscl.org.cn/MulanPSL2
 *
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 * -------------------------------------------------------------------------
*/

#ifndef UTIL_MSPTI_H_
#define UTIL_MSPTI_H_

#include <cstdio>

#define CHECK_RET(cond, return_expr) \
    do {                               \
        if (!(cond)) {                   \
            return_expr;                   \
        }                                \
    } while (0)

#define LOG_PRINT(message, ...)     \
    do {                              \
        printf(message, ##__VA_ARGS__); \
    } while (0)

#define ACL_CALL(acl_func_call)   \
    do {                                       \
        auto ret = acl_func_call;              \
        if (ret != ACL_SUCCESS) { \
            LOG_PRINT("%s call failed, error code: %d\n", #acl_func_call, ret); \
            return ret; \
        }                         \
    } while (0)

#define HCCL_CHECK(func) \
    do { \
        auto ret = func; \
        if (ret != HCCL_SUCCESS) \
        { \
            LOG_PRINT("hccl interface return err %s:%d, ret code: %d \n", __FILE__, __LINE__, ret); \
            return ret; \
        } \
    } while (0)
    

#define ALIGN_SIZE (8)
#define ALIGN_BUFFER(buffer, align)                                                 \
    (((uintptr_t) (buffer) & ((align)-1)) ? ((buffer) + (align) - ((uintptr_t) (buffer) & ((align)-1))) : (buffer))

#endif // UTIL_MSPTI_H_