feat: scaffold FCES-native C++ project with libtorch integration
- CMakeLists.txt with libtorch, GoogleTest, GoogleBenchmark, OpenMP, pybind11 - Header files: config, controller, population, fitness, evolution, spectral, oscillation, telemetry, optimizer - Source implementations: controller (full micro-MLP forward pass, mutation, crossover), fitness (Welford's algorithm), oscillation (DFT), spectral (SVD rank), optimizer (sign-SGD stub) - Tests: controller, population, fitness, optimizer (Google Test) - Benchmarks: evolve throughput, optimizer step (Google Benchmark) - Examples: simple optimization, PyTorch/libtorch integration - Python extension: pybind11 bindings with setup.py - README with architecture diagram and build instructions
This commit is contained in:
45
benchmarks/bench_evolve.cpp
Normal file
45
benchmarks/bench_evolve.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
#include <benchmark/benchmark.h>
|
||||
#include "fces/population.hpp"
|
||||
#include "fces/controller.hpp"
|
||||
|
||||
using namespace fces;
|
||||
|
||||
static void BM_ControllerDecideUpdate(benchmark::State& state) {
|
||||
FuzzyController ctrl;
|
||||
std::vector<std::vector<float>> stats(state.range(0), {0.1f, 0.2f, 0.3f, 0.4f, 0.5f});
|
||||
|
||||
for (auto _ : state) {
|
||||
auto actions = ctrl.decide_update(stats, 0.0f, 0.5f, 0.0f, 0.1f, 0.0f, 0.0f, 1.0f, 0.0f);
|
||||
benchmark::DoNotOptimize(actions);
|
||||
}
|
||||
}
|
||||
BENCHMARK(BM_ControllerDecideUpdate)->Arg(10)->Arg(50)->Arg(200);
|
||||
|
||||
static void BM_Evolve(benchmark::State& state) {
|
||||
Population pop(state.range(0));
|
||||
|
||||
for (auto _ : state) {
|
||||
pop.evolve(2.0f, -0.01f, 0.5f);
|
||||
}
|
||||
}
|
||||
BENCHMARK(BM_Evolve)->Arg(50)->Arg(100)->Arg(200);
|
||||
|
||||
static void BM_Mutation(benchmark::State& state) {
|
||||
FuzzyController ctrl;
|
||||
|
||||
for (auto _ : state) {
|
||||
auto child = ctrl.mutate(2.0f, 1.0f);
|
||||
benchmark::DoNotOptimize(child);
|
||||
}
|
||||
}
|
||||
BENCHMARK(BM_Mutation);
|
||||
|
||||
static void BM_Crossover(benchmark::State& state) {
|
||||
FuzzyController a, b;
|
||||
|
||||
for (auto _ : state) {
|
||||
auto child = a.crossover(b);
|
||||
benchmark::DoNotOptimize(child);
|
||||
}
|
||||
}
|
||||
BENCHMARK(BM_Crossover);
|
||||
25
benchmarks/bench_step.cpp
Normal file
25
benchmarks/bench_step.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#include <benchmark/benchmark.h>
|
||||
#include <torch/torch.h>
|
||||
#include "fces/optimizer.hpp"
|
||||
|
||||
using namespace fces;
|
||||
|
||||
static void BM_OptimizerStep(benchmark::State& state) {
|
||||
auto model = torch::nn::Linear(state.range(0), state.range(0) / 2);
|
||||
std::vector<torch::Tensor> params;
|
||||
for (auto& p : model->parameters()) params.push_back(p);
|
||||
|
||||
FCESOptimizer opt(params, FCESConfig{}.set_lr(1e-3f));
|
||||
|
||||
auto x = torch::randn({8, state.range(0)});
|
||||
|
||||
for (auto _ : state) {
|
||||
auto y = model->forward(x);
|
||||
auto loss = y.sum();
|
||||
loss.backward();
|
||||
opt.step();
|
||||
opt.zero_grad();
|
||||
benchmark::DoNotOptimize(loss);
|
||||
}
|
||||
}
|
||||
BENCHMARK(BM_OptimizerStep)->Arg(64)->Arg(256)->Arg(1024);
|
||||
Reference in New Issue
Block a user