#ifndef CORE_H #define CORE_H #include "typedef.hpp" #include #include #include #include #include #include #include class NeuralNetwork { private: // Параметры нейросети int numLayers; std::vector sizes; std::vector>> weights; std::vector> biases; std::vector> outputs; // Объекты Vulkan bool useVulkan; // Сохраняем выбор пользователя vk::Instance instance; vk::PhysicalDevice physDev; vk::Device device; vk::Queue queue; vk::CommandPool cmdPool; uint32_t computeQueueFamilyIndex; // Индекс очереди для команд // Вспомогательные методы Vulkan uint32_t findMemoryType(uint32_t typeFilter, vk::MemoryPropertyFlags properties); std::vector readFile(const std::string& filename); // Математика CPU double sigmoid(double x) { return 1.0 / (1.0 + exp(-x)); } double sigmoidDeriv(double x) { return x * (1.0 - x); } struct TrainParams { uint32_t prevLayerSize; uint32_t nextLayerSize; uint32_t weightOffset; uint32_t biasOffset; uint32_t outOffset; uint32_t errOffset; float lr; }; vk::Buffer gpuW, gpuB, gpuO, gpuE; vk::DeviceMemory memW, memB, memO, memE; vk::DescriptorPool descriptorPool; vk::DescriptorSet descriptorSet; vk::DescriptorSetLayout dsLayout; vk::PipelineLayout pipeLayout; vk::Pipeline pipeline; vk::ShaderModule shaderModule; bool vulkanResourcesInitialized = false; void initVulkanResources(); // Метод для разовой инициализации void cleanupVulkanResources(); public: int cpu_count = 1; // Конструктор NeuralNetwork(LayerStructure_t layers[], int count, bool useVulkan = false); // Деструктор (ВАЖНО для очистки Vulkan) ~NeuralNetwork(); // Методы работы std::vector feedForward(const std::vector& input); double train(const std::vector& input, const std::vector& target, double lr); double trainVulkan(const std::vector& input, const std::vector& target, double lr); }; #endif