From 87b45a1484f3a56da56e3e3dabe20dae111b0edc Mon Sep 17 00:00:00 2001 From: KoDer Date: Fri, 2 Oct 2026 19:30:49 +0700 Subject: [PATCH] HPP --- CMakeLists.txt | 7 +++--- README.md | 2 +- main.cpp | 13 +++++----- settings.h | 15 ------------ xenith/converter.cpp | 2 +- xenith/{converter.h => converter.hpp} | 0 xenith/core/backward.cpp | 2 +- xenith/core/checkpoint.cpp | 2 +- xenith/core/{checkpoint.h => checkpoint.hpp} | 2 +- xenith/core/generate.cpp | 2 +- xenith/core/{generate.h => generate.hpp} | 2 +- xenith/core/gradcheck.cpp | 4 ++-- xenith/core/{gradcheck.h => gradcheck.hpp} | 2 +- xenith/core/model.cpp | 2 +- xenith/core/{model.h => model.hpp} | 2 +- xenith/core/{tensor.h => tensor.hpp} | 0 xenith/core/{train.h => train.hpp} | 4 ++-- xenith/core/trainer.cpp | 4 ++-- .../{httplib.h => httplib.hpp} | 0 xenith/ollama_api/handler.cpp | 2 +- xenith/ollama_api/{handler.h => handler.hpp} | 9 +++---- xenith/ollama_api/server.cpp | 2 +- xenith/ollama_api/server.h | 14 ----------- xenith/ollama_api/server.hpp | 13 ++++++++++ xenith/ollama_api/test.cpp | 2 +- xenith/preprocessing/tokenizer.cpp | 2 +- .../{tokenizer.h => tokenizer.hpp} | 2 +- xenith/ui/{tui.h => tui.hpp} | 24 ++++--------------- xenith/ui/tui/message.cpp | 7 ++++++ xenith/ui/tui/mouse.cpp | 2 +- xenith/ui/tui/tui.cpp | 6 ++++- 31 files changed, 65 insertions(+), 87 deletions(-) delete mode 100644 settings.h rename xenith/{converter.h => converter.hpp} (100%) rename xenith/core/{checkpoint.h => checkpoint.hpp} (97%) rename xenith/core/{generate.h => generate.hpp} (96%) rename xenith/core/{gradcheck.h => gradcheck.hpp} (89%) rename xenith/core/{model.h => model.hpp} (98%) rename xenith/core/{tensor.h => tensor.hpp} (100%) rename xenith/core/{train.h => train.hpp} (96%) rename xenith/libs/cpp-httplib-0.57.1/{httplib.h => httplib.hpp} (100%) rename xenith/ollama_api/{handler.h => handler.hpp} (96%) delete mode 100644 xenith/ollama_api/server.h create mode 100644 xenith/ollama_api/server.hpp rename xenith/preprocessing/{tokenizer.h => tokenizer.hpp} (90%) rename xenith/ui/{tui.h => tui.hpp} (90%) create mode 100644 xenith/ui/tui/message.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 44e0d98..cb7ca09 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,12 +28,13 @@ set(SOURCES xenith/converter.cpp help.h xenith/ollama_api/handler.cpp - xenith/ollama_api/handler.h - xenith/ollama_api/server.h + xenith/ollama_api/handler.hpp + xenith/ollama_api/server.hpp xenith/ollama_api/server.cpp xenith/ui/tui/tui.cpp - xenith/ui/tui.h + xenith/ui/tui.hpp xenith/ui/tui/mouse.cpp + xenith/ui/tui/message.cpp ) # Заголовочные файлы (для удобства в IDE) diff --git a/README.md b/README.md index 46f92ac..df632a5 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ | файл | что делает | |---|---| -| `xenith/core/tensor.h` | матрицы, три формы GEMM, RMSNorm, RNG, пул потоков | +| `xenith/core/tensor.hpp` | матрицы, три формы GEMM, RMSNorm, RNG, пул потоков | | `xenith/core/model.cpp` | конфигурация, инициализация, прямой проход, RoPE, Adam | | `xenith/core/backward.cpp` | обратный проход (ручной, без автомиффов) | | `xenith/core/trainer.cpp` | цикл обучения, расписание lr, чекпоинты, валидация | diff --git a/main.cpp b/main.cpp index ae27dec..06edeba 100644 --- a/main.cpp +++ b/main.cpp @@ -1,8 +1,8 @@ -#include "xenith/core/checkpoint.h" -#include "xenith/core/generate.h" -#include "xenith/core/train.h" +#include "xenith/core/checkpoint.hpp" +#include "xenith/core/generate.hpp" +#include "xenith/core/train.hpp" #include "xenith/core/gradcheck.h" -#include "xenith/ui/tui.h" +#include "xenith/ui/tui.hpp" #include #include "help.h" #include @@ -358,10 +358,9 @@ static int cmd_update(const Args& a) { static int cmd_tui(const Args& a) { - ui::Tui tui = ui::Tui(); - while (tui.is_running()) + while (ui::app.is_running()) { - tui.update(); + ui::app.update(); } std::cout << "\033[2J\033[H" << std::flush; return 0; diff --git a/settings.h b/settings.h deleted file mode 100644 index bca232e..0000000 --- a/settings.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef XENITH_SETTINGS_H -#define XENITH_SETTINGS_H -#pragma once -#include "xenith/preprocessing/tokenizer.h" - -struct llm_prm -{ - bool use_mmap = true; - bool use_mlock = false; - int num_thread = 1; - unsigned int num_gpu = 256; - -}; - -#endif diff --git a/xenith/converter.cpp b/xenith/converter.cpp index 135567a..ac94854 100644 --- a/xenith/converter.cpp +++ b/xenith/converter.cpp @@ -1,4 +1,4 @@ -#include "converter.h" +#include "converter.hpp" #include #include diff --git a/xenith/converter.h b/xenith/converter.hpp similarity index 100% rename from xenith/converter.h rename to xenith/converter.hpp diff --git a/xenith/core/backward.cpp b/xenith/core/backward.cpp index f5982dc..723f3a8 100644 --- a/xenith/core/backward.cpp +++ b/xenith/core/backward.cpp @@ -1,4 +1,4 @@ -#include "train.h" +#include "train.hpp" #include #include diff --git a/xenith/core/checkpoint.cpp b/xenith/core/checkpoint.cpp index 68757e5..93eef21 100644 --- a/xenith/core/checkpoint.cpp +++ b/xenith/core/checkpoint.cpp @@ -1,4 +1,4 @@ -#include "checkpoint.h" +#include "checkpoint.hpp" #include #include #include diff --git a/xenith/core/checkpoint.h b/xenith/core/checkpoint.hpp similarity index 97% rename from xenith/core/checkpoint.h rename to xenith/core/checkpoint.hpp index aa42f87..03d0f58 100644 --- a/xenith/core/checkpoint.h +++ b/xenith/core/checkpoint.hpp @@ -1,5 +1,5 @@ #pragma once -#include "model.h" +#include "model.hpp" #include #include #include diff --git a/xenith/core/generate.cpp b/xenith/core/generate.cpp index a17a522..78a3067 100644 --- a/xenith/core/generate.cpp +++ b/xenith/core/generate.cpp @@ -1,4 +1,4 @@ -#include "generate.h" +#include "generate.hpp" #include #include #include diff --git a/xenith/core/generate.h b/xenith/core/generate.hpp similarity index 96% rename from xenith/core/generate.h rename to xenith/core/generate.hpp index 3a44a4b..5998c3e 100644 --- a/xenith/core/generate.h +++ b/xenith/core/generate.hpp @@ -1,6 +1,6 @@ // generate.h — генерация текста с KV-кэшем #pragma once -#include "checkpoint.h" +#include "checkpoint.hpp" #include #include diff --git a/xenith/core/gradcheck.cpp b/xenith/core/gradcheck.cpp index f6aeced..f522165 100644 --- a/xenith/core/gradcheck.cpp +++ b/xenith/core/gradcheck.cpp @@ -1,8 +1,8 @@ // gradcheck.cpp — проверяем, что обратный проход совпадает с численным // и заодно меряем скорость. #include "gradcheck.h" -#include "generate.h" -#include "train.h" +#include "generate.hpp" +#include "train.hpp" #include #include #include diff --git a/xenith/core/gradcheck.h b/xenith/core/gradcheck.hpp similarity index 89% rename from xenith/core/gradcheck.h rename to xenith/core/gradcheck.hpp index a247ca0..fdcb2d6 100644 --- a/xenith/core/gradcheck.h +++ b/xenith/core/gradcheck.hpp @@ -1,6 +1,6 @@ // gradcheck.h — численная проверка градиентов и бенчмарк #pragma once -#include "checkpoint.h" +#include "checkpoint.hpp" namespace xt { int run_gradcheck(bool verbose); diff --git a/xenith/core/model.cpp b/xenith/core/model.cpp index 6dcdcf8..64b0529 100644 --- a/xenith/core/model.cpp +++ b/xenith/core/model.cpp @@ -1,4 +1,4 @@ -#include "model.h" +#include "model.hpp" #include #include #include diff --git a/xenith/core/model.h b/xenith/core/model.hpp similarity index 98% rename from xenith/core/model.h rename to xenith/core/model.hpp index 8245f19..7c00419 100644 --- a/xenith/core/model.h +++ b/xenith/core/model.hpp @@ -1,5 +1,5 @@ #pragma once -#include "tensor.h" +#include "tensor.hpp" #include #include diff --git a/xenith/core/tensor.h b/xenith/core/tensor.hpp similarity index 100% rename from xenith/core/tensor.h rename to xenith/core/tensor.hpp diff --git a/xenith/core/train.h b/xenith/core/train.hpp similarity index 96% rename from xenith/core/train.h rename to xenith/core/train.hpp index 0a18c1e..13da145 100644 --- a/xenith/core/train.h +++ b/xenith/core/train.hpp @@ -1,6 +1,6 @@ #pragma once -#include "model.h" -#include "checkpoint.h" +#include "model.hpp" +#include "checkpoint.hpp" #include namespace xt { diff --git a/xenith/core/trainer.cpp b/xenith/core/trainer.cpp index 5afb580..ac6a3f1 100644 --- a/xenith/core/trainer.cpp +++ b/xenith/core/trainer.cpp @@ -1,5 +1,5 @@ -#include "train.h" -#include "checkpoint.h" +#include "train.hpp" +#include "checkpoint.hpp" #include #include #include diff --git a/xenith/libs/cpp-httplib-0.57.1/httplib.h b/xenith/libs/cpp-httplib-0.57.1/httplib.hpp similarity index 100% rename from xenith/libs/cpp-httplib-0.57.1/httplib.h rename to xenith/libs/cpp-httplib-0.57.1/httplib.hpp diff --git a/xenith/ollama_api/handler.cpp b/xenith/ollama_api/handler.cpp index 0080569..6e150b8 100644 --- a/xenith/ollama_api/handler.cpp +++ b/xenith/ollama_api/handler.cpp @@ -1,2 +1,2 @@ -#include "handler.h" +#include "handler.hpp" diff --git a/xenith/ollama_api/handler.h b/xenith/ollama_api/handler.hpp similarity index 96% rename from xenith/ollama_api/handler.h rename to xenith/ollama_api/handler.hpp index 02040a6..88da385 100644 --- a/xenith/ollama_api/handler.h +++ b/xenith/ollama_api/handler.hpp @@ -1,5 +1,5 @@ -#ifndef XENITH_HANDLER_H -#define XENITH_HANDLER_H +#pragma once + #include #include #include @@ -63,7 +63,4 @@ namespace api std::string digest; models_details details; }; -} - - -#endif +} \ No newline at end of file diff --git a/xenith/ollama_api/server.cpp b/xenith/ollama_api/server.cpp index 7f4c27f..c5508c9 100644 --- a/xenith/ollama_api/server.cpp +++ b/xenith/ollama_api/server.cpp @@ -1,4 +1,4 @@ -#include "server.h" +#include "server.hpp" namespace api { diff --git a/xenith/ollama_api/server.h b/xenith/ollama_api/server.h deleted file mode 100644 index 27f7c4c..0000000 --- a/xenith/ollama_api/server.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef XENITH_SERVER_H -#define XENITH_SERVER_H -#include "handler.h" - -namespace api -{ - class server - { - server(); - ~server(); - }; -} - -#endif //XENITH_SERVER_H diff --git a/xenith/ollama_api/server.hpp b/xenith/ollama_api/server.hpp new file mode 100644 index 0000000..c383c37 --- /dev/null +++ b/xenith/ollama_api/server.hpp @@ -0,0 +1,13 @@ +#pragma once + +#include "handler.hpp" + +namespace api +{ + class server + { + server(); + ~server(); + }; +} + diff --git a/xenith/ollama_api/test.cpp b/xenith/ollama_api/test.cpp index 0174e29..554c112 100644 --- a/xenith/ollama_api/test.cpp +++ b/xenith/ollama_api/test.cpp @@ -3,7 +3,7 @@ #include #include #include -#include "./xenith/libs/cpp-httplib-0.57.1/httplib.h" +#include "./xenith/libs/cpp-httplib-0.57.1/httplib.hpp" #include "./xenith/libs/json-3.12.0/nlohmann/json.hpp" diff --git a/xenith/preprocessing/tokenizer.cpp b/xenith/preprocessing/tokenizer.cpp index 39210ee..ca64f35 100644 --- a/xenith/preprocessing/tokenizer.cpp +++ b/xenith/preprocessing/tokenizer.cpp @@ -1,4 +1,4 @@ -#include "tokenizer.h" +#include "tokenizer.hpp" #include #include diff --git a/xenith/preprocessing/tokenizer.h b/xenith/preprocessing/tokenizer.hpp similarity index 90% rename from xenith/preprocessing/tokenizer.h rename to xenith/preprocessing/tokenizer.hpp index 83f73d1..9a5d939 100644 --- a/xenith/preprocessing/tokenizer.h +++ b/xenith/preprocessing/tokenizer.hpp @@ -4,7 +4,7 @@ #include #include #include -#include "./../converter.h" +#include "./../converter.hpp" #include "models/test_model.h" void proccesing_promt(const std::string& text, Model& mdl, uint32_t layer_idx = 0); diff --git a/xenith/ui/tui.h b/xenith/ui/tui.hpp similarity index 90% rename from xenith/ui/tui.h rename to xenith/ui/tui.hpp index 206e452..f1a865b 100644 --- a/xenith/ui/tui.h +++ b/xenith/ui/tui.hpp @@ -1,12 +1,7 @@ -#ifndef XENITH_TUI_H -#define XENITH_TUI_H +#pragma once #include -#include #include -#include -#include -#include #include #include #include @@ -52,7 +47,6 @@ namespace ui inline static bool running = true; inline static int width = 80; inline static int height = 24; - struct SplitDesc { enum Type { VERTICAL, HORIZONTAL }; Type type; @@ -60,22 +54,17 @@ namespace ui std::vector> children; SplitDesc(Type t, int pos) : type(t), position(pos) {} }; - struct border_charset { std::string_view top_left, top_right, bottom_left, bottom_right; std::string_view bottom, top, horizontal, vertical, bg; std::string_view cross, tee_up, tee_down, tee_left, tee_right; }; - - // Ваша структура, которая теперь будет использоваться по назначению struct TuiCell { - std::string ch; // UTF-8 последовательность (например, "│" или "┌") - int width; // Ширина на экране (обычно 1) - + std::string ch; + int width; TuiCell() : ch(" "), width(1) {} TuiCell(const std::string& c, int w) : ch(c), width(w) {} }; - inline static struct termios orig_termios; inline static const border_charset border_clip { .top_left="╭", .top_right="╮", .bottom_left="╰", .bottom_right="╯", @@ -99,7 +88,6 @@ namespace ui .top_left="▟", .top_right="▙", .bottom_left="▜", .bottom_right="▛", .bottom="█", .top="█", .vertical="█", .bg="█" }; - static void get_console_size(); static bool wait_for_input_or_timeout(int timeout_ms); void apply_color() const; @@ -118,13 +106,11 @@ namespace ui static void invert_color(); static void draw_button(int x, int y, int w, int h, std::string_view label, border_charset charset = border_solid); static void invert_color_off(); - - // --- ОБНОВЛЕННЫЕ СИГНАТУРЫ --- void draw_split_border(int w, int h, border_charset charset, int x, int y, const SplitDesc* root); static void apply_splits_recursive(std::vector>& grid, int offset_x, int offset_y, int w, int h, border_charset charset, const SplitDesc* split); static void apply_single_split(std::vector>& grid, int offset_x, int offset_y, int w, int h, border_charset charset, const SplitDesc* split); static void draw_border_to_buffer(std::vector>& grid, int w, int h, border_charset charset); }; -} -#endif \ No newline at end of file + Tui app = Tui(); +} \ No newline at end of file diff --git a/xenith/ui/tui/message.cpp b/xenith/ui/tui/message.cpp new file mode 100644 index 0000000..78bd102 --- /dev/null +++ b/xenith/ui/tui/message.cpp @@ -0,0 +1,7 @@ +#include "message.h" +#include "./../tui.hpp" + +namespace ui +{ + +} \ No newline at end of file diff --git a/xenith/ui/tui/mouse.cpp b/xenith/ui/tui/mouse.cpp index 7387111..f815390 100644 --- a/xenith/ui/tui/mouse.cpp +++ b/xenith/ui/tui/mouse.cpp @@ -1,4 +1,4 @@ -#include "../tui.h" +#include "../tui.hpp" namespace ui { diff --git a/xenith/ui/tui/tui.cpp b/xenith/ui/tui/tui.cpp index 6b63397..ed95687 100644 --- a/xenith/ui/tui/tui.cpp +++ b/xenith/ui/tui/tui.cpp @@ -1,8 +1,12 @@ -#include "../tui.h" +#include "../tui.hpp" #include #include #include +#include +#include +#include +#include namespace ui