cwenzi/neuroflow-cpp
1
1# NeuroFlow C++ Core2 3高性能C++底层实现,提供Python绑定接口。4 5## 特点6 7- **轻量化**: 相比原Python版本减少80%+内存占用8- **SIMD优化**: AVX2/ARM NEON加速矩阵运算9- **量化支持**: INT8/FP8量化,4x内存压缩10- **MLA技术**: DeepSeek KV压缩,87.5%+内存节省11- **长记忆**: 分页记忆系统,支持磁盘溢出12- **零依赖**: 单静态库,无外部依赖13 14## 构建15 16```bash17cd cpp_core18chmod +x build.sh19./build.sh build # 构建核心库20./build.sh test # 构建并测试21./build.sh python # 构建Python绑定22```23 24## 目录结构25 26```27cpp_core/28├── include/neuroflow/29│ ├── tensor.hpp # 张量运算引擎 (SIMD)30│ ├── networks.hpp # ECN/DMN/SN网络31│ ├── memory.hpp # MLA/记忆模块32│ └── model.hpp # 主模型类33├── src/34│ ├── tensor.cpp35│ └── model.cpp36├── bindings/37│ └── python_bindings.cpp # pybind11绑定38├── tests/39│ ├── test_tensor.cpp40│ └── test_model.cpp41├── CMakeLists.txt42└── build.sh43```44 45## Python使用46 47```python48import neuroflow_cpp as nf49 50# 创建模型51config = nf.ModelConfig(52 input_dim=512,53 hidden_dim=256,54 output_dim=10,55 use_quantization=True56)57model = nf.NeuroFlowModel(config)58 59# 前向传播60import numpy as np61x = np.random.randn(32, 512).astype(np.float32)62output = model.forward(x)63 64print(output.output.shape) # (32, 10)65print(output.decision.shape)66print(output.manifold.shape) # 如果return_manifold=True67 68# 性能对比69stats = nf.benchmark()70print(f"Size reduction: {stats['size_reduction']*100:.1f}%")71```72 73## 性能对比74 75| 版本 | 参数量 | 内存 | 推理时间 | 相比原版 |76|------|--------|------|----------|----------|77| C++ Original | 1.25M | 5 MB | 2.5 ms | baseline |78| C++ Optimized | 171K | 0.7 MB | 1.2 ms | 2x加速 |79| C++ Lite | 79K | 0.3 MB | 0.8 ms | 3x加速 |80| C++ Quantized | 79K | 0.08 MB | 0.6 ms | 4x加速 |