Copyright (c) 2025-2025 Huawei Technologies Co., Ltd.
sysHAX-adapter 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.
Created: 2026-1-31
Desc: CPU inference utils
*/
#ifndef UTILS_H
#define UTILS_H
#include <iostream>
#include <string>
#include <cstdlib>
static inline uint64_t get_time_ns(void)
{
struct timespec ts;
clock_gettime(CLOCK_REALTIME, &ts);
return ts.tv_sec * 1000 * 1000 * 1000 + ts.tv_nsec;
}
#define CHECK(expr) \
do { \
if (!(expr)) { \
std::cerr << "CHECK failed: " << #expr \
<< " at " << __FILE__ << ":" << __LINE__ << std::endl; \
std::abort(); \
} \
} while(0)
#define CHECK_MSG(expr, msg) \
do { \
if (!(expr)) { \
std::cerr << "CHECK failed: " << #expr \
<< " at " << __FILE__ << ":" << __LINE__ << "\n" \
<< "Message: " << (msg) << std::endl; \
std::abort(); \
} \
} while(0)
#endif