/** * @file utils.hpp * @brief 实用工具函数和宏定义。 */ #pragma once #include #include #include #include #include #include "../cuda_utils.hpp" // get_default_device() /** * @def SPRINT_VARS(prefix, ...) * @brief 将变量名和值格式化为 string,常用于 TORCH_CHECK 的报错信息。 * * @par 示例 * @code * int a = 10; * double b = 3.14; * SPRINT_VARS("ctx", a, b); // "ctx a, b: 10 3.14 " * @endcode */ #define SPRINT_VARS(prefix, ...) sprint_vars_impl(prefix, #__VA_ARGS__, __VA_ARGS__) template std::string sprint_vars_impl(const char *prefix, const char *names, const Args &...args) { std::stringstream ss; ss << prefix << " " << names << ": "; ((ss << args << " "), ...); return ss.str(); } inline int get_nextn_from_env() { const char *env = std::getenv("DEEPINFER_USE_NEXTN_DECODE"); // Keep the unset default consistent with deepinfer/environ.py and script entry points. return env != nullptr ? atoi(env) : 5; }