Files
wehub-resource-sync ec436095dd
Book-CI / test (macos-latest) (push) Has been cancelled
Book-CI / test (ubuntu-latest) (push) Has been cancelled
Book-CI / test (windows-latest) (push) Has been cancelled
Release Fake Tag / publish (push) Has been cancelled
Deploy / deploy (macos-latest) (push) Has been cancelled
Deploy / deploy (ubuntu-latest) (push) Has been cancelled
Deploy / deploy (windows-latest) (push) Has been cancelled
Release to PyPI / Build & publish sglang-kt (push) Has been cancelled
Release to PyPI / Build kt-kernel (Python 3.11) (push) Has been cancelled
Release to PyPI / Build kt-kernel (Python 3.12) (push) Has been cancelled
Release to PyPI / Publish kt-kernel to PyPI (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:30:03 +08:00

60 lines
2.2 KiB
C++

#ifndef KML_DEBUG_HPP
#define KML_DEBUG_HPP
#include <arm_sve.h>
#include <cstdint>
#include <cstdlib>
#include <fstream>
#include <string>
inline std::string get_env_or_default(const char* var_name, const std::string& default_value) {
const char* value = std::getenv(var_name);
return (value != nullptr) ? std::string(value) : default_value;
}
inline void dump_bin(std::string file_name, float16_t* data, size_t count) {
file_name = get_env_or_default("KML_DEBUG_PATH", "debug") + "/" + file_name + ".f16";
std::ofstream f(file_name, std::ios::binary);
f.write(reinterpret_cast<const char*>(data), count * sizeof(*data));
f.close();
}
inline void dump_bin(std::string file_name, float* data, size_t count) {
file_name = get_env_or_default("KML_DEBUG_PATH", "debug") + "/" + file_name + ".f32";
std::ofstream f(file_name, std::ios::binary);
f.write(reinterpret_cast<const char*>(data), count * sizeof(*data));
f.close();
}
inline void dump_bin(std::string file_name, int64_t* data, size_t count) {
file_name = get_env_or_default("KML_DEBUG_PATH", "debug") + "/" + file_name + ".int64";
std::ofstream f(file_name, std::ios::binary);
f.write(reinterpret_cast<const char*>(data), count * sizeof(*data));
f.close();
}
inline void dump_bin(std::string file_name, int8_t* data, size_t count) {
file_name = get_env_or_default("KML_DEBUG_PATH", "debug") + "/" + file_name + ".int8";
std::ofstream f(file_name, std::ios::binary);
f.write(reinterpret_cast<const char*>(data), count * sizeof(*data));
f.close();
}
inline void dump_bin(std::string file_name, int32_t* data, size_t count) {
file_name = get_env_or_default("KML_DEBUG_PATH", "debug") + "/" + file_name + ".int32";
std::ofstream f(file_name, std::ios::binary);
f.write(reinterpret_cast<const char*>(data), count * sizeof(*data));
f.close();
}
inline void load_bin(std::string file_name, float* data, size_t count) {
file_name = get_env_or_default("KML_DEBUG_PATH", "debug") + "/" + file_name + ".f32";
std::ifstream f(file_name, std::ios::binary);
if (!f.is_open()) {
throw std::runtime_error("Failed to open file: " + file_name);
}
f.read(reinterpret_cast<char*>(data), count * sizeof(*data));
f.close();
}
#endif